Skip to content

Commit

Permalink
Fix signless disable transaction cancel error catching
Browse files Browse the repository at this point in the history
  • Loading branch information
vraja-nayaka authored May 20, 2024
1 parent 33dd4c9 commit ade2b13
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,25 @@ function useBatchSignAndSend(type?: 'all' | 'force') {
});
};

const batchSign = async (txs: SubmittableExtrinsic<'promise', ISubmittableResult>[], pair?: KeyringPair) => {
const batchSign = async (
txs: SubmittableExtrinsic<'promise', ISubmittableResult>[],
{ pair, ...options }: Options = {},
) => {
if (!account) throw new Error('No account address');

const { address, meta } = account;
const batch = getBatch();

return pair
const signAsync = pair
? batch(txs).signAsync(pair)
: web3FromSource(meta.source).then(({ signer }) => batch(txs).signAsync(address, { signer }));

return signAsync.catch(({ message }: Error) => {
const { onError = () => {}, onFinally = () => {} } = options;

onError(message);
onFinally();
});
};

const batchSend = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ function useCreateSession(programId: HexString, metadata: ProgramMetadata | unde

// We need to sign transactions before sending declineExtrinsic;
// Otherwise, if the signing is canceled, the voucher will be invalid.
const signedTxs = await batchSign(txs);
const signedTxs = await batchSign(txs, options);

if (!signedTxs) {
throw new Error('Transaction sign canceled');
}

if (!isExpired) {
const declineExtrinsic = api.voucher.call(voucher.id, { DeclineVoucher: null });
await sendTransaction(declineExtrinsic, pair, ['VoucherDeclined']);
await sendTransaction(declineExtrinsic, pair, ['VoucherDeclined'], options);
}

batchSend(signedTxs, { ...options, onError });
Expand Down

0 comments on commit ade2b13

Please sign in to comment.