Skip to content

Commit

Permalink
fix: show insufficient funds/rejection errors properly
Browse files Browse the repository at this point in the history
  • Loading branch information
kelsos committed Nov 28, 2024
1 parent b01df02 commit 9184b62
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
7 changes: 6 additions & 1 deletion components/checkout/pay/CryptoPaymentForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ stopWatcher = watchEffect(() => {
redirect();
});
function dismissNotification() {
set(state, 'idle');
set(error, '');
}
watch(canvas, async (canvas) => {
if (!canvas)
return;
Expand Down Expand Up @@ -252,7 +257,7 @@ watch(canvas, async (canvas) => {
:timeout="10000"
closeable
:visible="failure"
@dismiss="state = 'idle'"
@dismiss="dismissNotification()"
>
<template #title>
{{ status?.title }}
Expand Down
18 changes: 6 additions & 12 deletions composables/crypto-payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export function useWeb3Payment(data: Ref<CryptoPayment>, state: Ref<StepType | I

appKit.subscribeAccount((account) => {
set(state, 'idle');
set(errorMessage, '');
set(connected, account.isConnected);

if (account.isConnected) {
Expand Down Expand Up @@ -199,15 +200,14 @@ export function useWeb3Payment(data: Ref<CryptoPayment>, state: Ref<StepType | I
signer: await browserProvider.getSigner(),
});
}
catch (error_: any) {
logger.error(error_);
catch (error: any) {
logger.error(error);
set(state, 'idle');

if ('reason' in error_ && error_.reason)
set(errorMessage, error_.reason);

if ('shortMessage' in error)
set(errorMessage, error.shortMessage);
else
set(errorMessage, error_.message);
set(errorMessage, error.message);
}
};

Expand All @@ -225,12 +225,6 @@ export function useWeb3Payment(data: Ref<CryptoPayment>, state: Ref<StepType | I
appKit.switchNetwork(network);
}

watch(state, (state) => {
if (state === 'idle') {
set(errorMessage, '');
}
});

onUnmounted(async () => {
await appKit.disconnect();
});
Expand Down

0 comments on commit 9184b62

Please sign in to comment.