Skip to content

Commit

Permalink
fix: broadcast ledger swap
Browse files Browse the repository at this point in the history
  • Loading branch information
fbwoolf committed Dec 8, 2023
1 parent 6539075 commit 886309b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/app/features/ledger/utils/stacks-ledger-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
17 changes: 12 additions & 5 deletions src/app/pages/swap/alex-swap-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {}
}

Expand Down

0 comments on commit 886309b

Please sign in to comment.