Skip to content

Commit

Permalink
Merge pull request #58 from near/sign-small-fix
Browse files Browse the repository at this point in the history
Redirect to failure_url if borsh invalid
  • Loading branch information
esaminu authored Sep 26, 2023
2 parents 5dba028 + 8785a4b commit 0734519
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions src/components/Sign/Sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,35 @@ function Sign() {
}

const transactionHashes = searchParams.get('transactions');
const deserializedTransactions = deserializeTransactionsFromString(transactionHashes);
const allActions = deserializedTransactions.flatMap((t) => t.actions);
setTransactionDetails({
signerId: deserializedTransactions[0].signerId,
receiverId: deserializedTransactions[0].receiverId,
totalAmount: allActions
.map((a) => a?.transfer?.deposit || a?.functionCall?.deposit || 0)
.filter((a) => a !== 0)
.reduce(
(totalAmount: BN, amount) => totalAmount.add(new BN(amount)),
new BN(0)
)
.toString(),
fees: {
transactionFees: '',
gasLimit: calculateGasLimit(allActions),
gasPrice: '',
},
transactions: deserializedTransactions,
actions: allActions,
});
try {
const deserializedTransactions = deserializeTransactionsFromString(transactionHashes);
const allActions = deserializedTransactions.flatMap((t) => t.actions);
setTransactionDetails({
signerId: deserializedTransactions[0].signerId,
receiverId: deserializedTransactions[0].receiverId,
totalAmount: allActions
.map((a) => a?.transfer?.deposit || a?.functionCall?.deposit || 0)
.filter((a) => a !== 0)
.reduce(
(totalAmount: BN, amount) => totalAmount.add(new BN(amount)),
new BN(0)
)
.toString(),
fees: {
transactionFees: '',
gasLimit: calculateGasLimit(allActions),
gasPrice: '',
},
transactions: deserializedTransactions,
actions: allActions,
});
} catch (err) {
const parsedUrl = new URL(searchParams.get('failure_url'));
parsedUrl.searchParams.set('code', err.code);
parsedUrl.searchParams.set('reason', err.message);
window.location.replace(parsedUrl.href);
return;
}

fetchGeckoPrices('near')
.then((res) => {
Expand Down

0 comments on commit 0734519

Please sign in to comment.