Skip to content

Commit

Permalink
fix(ui): improve error message for transaction was cancelled event
Browse files Browse the repository at this point in the history
  • Loading branch information
thekiba committed May 20, 2024
1 parent be181cc commit 91a4d43
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/ui/src/ton-connect-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ export class TonConnectUI {

return result;
} catch (e) {
this.tracker.trackTransactionSigningFailed(this.wallet, tx, e.message);

widgetController.setAction({
name: 'transaction-canceled',
showNotification: notifications.includes('error'),
Expand Down Expand Up @@ -656,6 +654,7 @@ export class TonConnectUI {
const { transaction, signal } = options;

if (signal.aborted) {
this.tracker.trackTransactionSigningFailed(this.wallet, transaction, 'Transaction was cancelled');
return reject(new TonConnectUIError('Transaction was not sent'));
}

Expand All @@ -668,19 +667,24 @@ export class TonConnectUI {
const onErrorsHandler = (reason: TonConnectError): void => {
reject(reason);
};

const onCanceledHandler = (): void => {
this.tracker.trackTransactionSigningFailed(this.wallet, transaction, 'Transaction was cancelled');
reject(new TonConnectUIError('Transaction was not sent'));
};

signal.addEventListener('abort', onCanceledHandler, { once: true });

this.connector
.sendTransaction(transaction, { onRequestSent: onRequestSent, signal: signal })
.then(result => onTransactionHandler(result))
.catch(reason => onErrorsHandler(reason));

signal.addEventListener(
'abort',
(): void => {
reject(new TonConnectUIError('Transaction was not sent'));
},
{ once: true }
);
.then(result => {
signal.removeEventListener('abort', onCanceledHandler);
return onTransactionHandler(result)
})
.catch(reason => {
signal.removeEventListener('abort', onCanceledHandler);
return onErrorsHandler(reason)
});
});
}

Expand Down

0 comments on commit 91a4d43

Please sign in to comment.