Skip to content

Commit

Permalink
fix(SendAndReceive): remove dry-run from xcm (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsimao authored Aug 25, 2023
1 parent 1084182 commit babdcb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/hooks/transaction/hooks/use-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ function useTransaction<T extends Transaction>(
onReady: () => onSigning(params)
};

return submitTransaction(window.bridge.api, params.accountAddress, feeWrappedExtrinsic, expectedStatus, events);
const shouldDryRun = params.type !== Transaction.XCM_TRANSFER;

return submitTransaction(
window.bridge.api,
params.accountAddress,
feeWrappedExtrinsic,
expectedStatus,
events,
shouldDryRun
);
},
[feeData?.amount, onSigning, pools]
);
Expand Down
17 changes: 13 additions & 4 deletions src/hooks/transaction/submission/submit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const handleTransaction = async (
account: AddressOrPair,
extrinsicData: ExtrinsicData,
expectedStatus?: ExtrinsicStatus['type'],
callbacks?: TransactionEvents
callbacks?: TransactionEvents,
shouldDryRun?: boolean
) => {
let isComplete = false;

Expand All @@ -28,7 +29,7 @@ const handleTransaction = async (
// Extrinsic is signed at first and then we use the same signed extrinsic
// for dry-running and submission.
.signAsync(account, { nonce: -1 })
.then(dryRun)
.then((signedExtrinsic) => (shouldDryRun ? dryRun(signedExtrinsic) : signedExtrinsic))
.then((signedExtrinsic) => signedExtrinsic.send(callback))
.then((unsub) => (unsubscribe = unsub))
.catch((error) => reject(error));
Expand Down Expand Up @@ -59,16 +60,24 @@ const handleTransaction = async (
* @param {ExtrinsicData} extrinsicData transaction extrinsic data
* @param {ExtrinsicStatus.type} expectedStatus status where the transaction is counted as fulfilled
* @param {TransactionEvents} callbacks a set of events emitted accross the lifecycle of the transaction (i.e Bro)
* @param {boolean} shouldDryRun wether dry run should be executed
* @return {Promise<ISubmittableResult>} transaction data that also can contain meta data in case of error
*/
const submitTransaction = async (
api: ApiPromise,
account: AddressOrPair,
extrinsicData: ExtrinsicData,
expectedStatus?: ExtrinsicStatus['type'],
callbacks?: TransactionEvents
callbacks?: TransactionEvents,
shouldDryRun?: boolean
): Promise<TransactionResult> => {
const { result, unsubscribe } = await handleTransaction(account, extrinsicData, expectedStatus, callbacks);
const { result, unsubscribe } = await handleTransaction(
account,
extrinsicData,
expectedStatus,
callbacks,
shouldDryRun
);

unsubscribe();

Expand Down

2 comments on commit babdcb8

@vercel
Copy link

@vercel vercel bot commented on babdcb8 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on babdcb8 Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.