-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add v6 tx signing for swaps
- Loading branch information
Showing
18 changed files
with
381 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,9 +176,11 @@ | |
"@stacks/connect": "7.4.0", | ||
"@stacks/encryption": "7.0.2", | ||
"@stacks/network": "7.0.2", | ||
"@stacks/network-v6": "npm:@stacks/[email protected]", | ||
"@stacks/profile": "7.0.2", | ||
"@stacks/rpc-client": "1.0.3", | ||
"@stacks/transactions": "7.0.2", | ||
"@stacks/transactions-v6": "npm:@stacks/[email protected]", | ||
"@stacks/wallet-sdk": "7.0.2", | ||
"@stitches/react": "1.2.8", | ||
"@storybook/addon-styling-webpack": "1.0.1", | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { StacksTransaction, broadcastTransaction } from '@stacks/transactions-v6'; | ||
|
||
import { delay, isError } from '@leather.io/utils'; | ||
|
||
import { logger } from '@shared/logger'; | ||
import { analytics } from '@shared/utils/analytics'; | ||
|
||
import { useRefreshAllAccountData } from '@app/common/hooks/account/use-refresh-all-account-data'; | ||
import { useLoading } from '@app/common/hooks/use-loading'; | ||
import { safelyFormatHexTxid } from '@app/common/utils/safe-handle-txid'; | ||
import { useToast } from '@app/features/toasts/use-toast'; | ||
import { useCurrentStacksNetworkStateV6 } from '@app/store/networks/networks.hooks'; | ||
|
||
const timeForApiToUpdate = 250; | ||
|
||
interface UseSubmitTransactionArgs { | ||
loadingKey: string; | ||
} | ||
interface UseSubmitTransactionCallbackV6Args { | ||
replaceByFee?: boolean; | ||
onSuccess(txId: string): void; | ||
onError(error: Error | string): void; | ||
} | ||
export function useSubmitTransactionCallbackV6({ loadingKey }: UseSubmitTransactionArgs) { | ||
const toast = useToast(); | ||
const refreshAccountData = useRefreshAllAccountData(); | ||
|
||
const { setIsLoading, setIsIdle } = useLoading(loadingKey); | ||
const stacksNetwork = useCurrentStacksNetworkStateV6(); | ||
|
||
return useCallback( | ||
({ onSuccess, onError }: UseSubmitTransactionCallbackV6Args) => | ||
async (transaction: StacksTransaction) => { | ||
setIsLoading(); | ||
try { | ||
const response = await broadcastTransaction(transaction, stacksNetwork); | ||
if (response.error) { | ||
logger.error('Transaction broadcast', response); | ||
if (response.reason) toast.error('Broadcast error'); | ||
onError(response.error); | ||
setIsIdle(); | ||
} else { | ||
logger.info('Transaction broadcast', response); | ||
|
||
await delay(500); | ||
|
||
void analytics.track('broadcast_transaction', { | ||
symbol: 'stx', | ||
}); | ||
onSuccess(safelyFormatHexTxid(response.txid)); | ||
setIsIdle(); | ||
await refreshAccountData(timeForApiToUpdate); | ||
} | ||
} catch (error) { | ||
logger.error('Transaction callback', { error }); | ||
onError(isError(error) ? error : { name: '', message: '' }); | ||
setIsIdle(); | ||
} | ||
}, | ||
[setIsLoading, stacksNetwork, toast, setIsIdle, refreshAccountData] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/app/features/ledger/flows/stacks-tx-signing/stacks-tx-signing-event-listeners.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.