From 886309b318dda5fa1c19f30b5a2772408e21acb6 Mon Sep 17 00:00:00 2001 From: Fara Woolf Date: Fri, 1 Dec 2023 09:48:17 -0600 Subject: [PATCH] fix: broadcast ledger swap --- .../ledger/utils/stacks-ledger-utils.ts | 6 +++--- src/app/pages/swap/alex-swap-container.tsx | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/app/features/ledger/utils/stacks-ledger-utils.ts b/src/app/features/ledger/utils/stacks-ledger-utils.ts index b4b50cef1be..ca6ea389db9 100644 --- a/src/app/features/ledger/utils/stacks-ledger-utils.ts +++ b/src/app/features/ledger/utils/stacks-ledger-utils.ts @@ -70,11 +70,11 @@ export function signLedgerStacksStructuredMessage(app: StacksApp) { } export function signStacksTransactionWithSignature(transaction: string, signatureVRS: Buffer) { - const deserialzedTx = deserializeTransaction(transaction); + const deserializedTx = deserializeTransaction(transaction); const spendingCondition = createMessageSignature(signatureVRS.toString('hex')); - (deserialzedTx.auth.spendingCondition as SingleSigSpendingCondition).signature = + (deserializedTx.auth.spendingCondition as SingleSigSpendingCondition).signature = spendingCondition; - return deserialzedTx; + return deserializedTx; } export function useActionCancellableByUser() { diff --git a/src/app/pages/swap/alex-swap-container.tsx b/src/app/pages/swap/alex-swap-container.tsx index aa1595e7c81..9d2abaddc0a 100644 --- a/src/app/pages/swap/alex-swap-container.tsx +++ b/src/app/pages/swap/alex-swap-container.tsx @@ -16,6 +16,7 @@ import { RouteUrls } from '@shared/route-urls'; import { isDefined, isUndefined } from '@shared/utils'; import { LoadingKeys, useLoading } from '@app/common/hooks/use-loading'; +import { useWalletType } from '@app/common/use-wallet-type'; import { NonceSetter } from '@app/components/nonce-setter'; import { defaultFeesMinValues } from '@app/query/stacks/fees/fees.hooks'; import { useStacksPendingTransactions } from '@app/query/stacks/mempool/mempool.hooks'; @@ -43,8 +44,12 @@ function AlexSwapContainer() { const generateUnsignedTx = useGenerateStacksContractCallUnsignedTx(); const signTx = useSignStacksTransaction(); const { transactions: pendingTransactions } = useStacksPendingTransactions(); + const { whenWallet } = useWalletType(); - const isSponsoredByAlex = !pendingTransactions.length; + const isSponsoredByAlex = whenWallet({ + ledger: false, + software: !pendingTransactions.length, + }); const { alexSDK, @@ -172,10 +177,12 @@ function AlexSwapContainer() { return logger.error('Attempted to generate raw tx, but signed tx is undefined'); const txRaw = bytesToHex(signedTx.serialize()); - if (isSponsoredByAlex) { - return await broadcastAlexSwap(txRaw); - } - return await broadcastStacksSwap(unsignedTx); + return whenWallet({ + ledger: await broadcastStacksSwap(signedTx), + software: isSponsoredByAlex + ? await broadcastAlexSwap(txRaw) + : await broadcastStacksSwap(signedTx), + }); } catch (error) {} }