Skip to content

Commit

Permalink
feat: on wallet error and cleanup (#1103)
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker authored Jan 17, 2025
1 parent 2bd46c0 commit ee0f8ea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@
"snapshot_restore_error": "Unexpected error(s) while restoring the snapshot.",
"snapshot_delete_error": "Unexpected error(s) while deleting the snapshot.",
"snapshot_list_error": "Unexpected error(s) while listing the snapshot.",
"wallet_error": "Error while loading your wallet.",
"wallet_uncertified_transactions_removed": "Several uncertified transactions were identified and subsequently removed from the displayed lists.",
"wallet_no_account": "The wallet did not provide any account.",
"wallet_load_balance": "The balance of the account cannot be loaded.",
"wallet_receive_error": "Unexpected error while receiving tokens.",
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/lib/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@
"snapshot_restore_error": "恢复快照出现未知错误.",
"snapshot_delete_error": "删除快照出现未知错误.",
"snapshot_list_error": "列表快照出现未知错误.",
"wallet_error": "Error while loading your wallet.",
"wallet_uncertified_transactions_removed": "Several uncertified transactions were identified and subsequently removed from the displayed lists.",
"wallet_no_account": "签名方未提供账号.",
"wallet_load_balance": "账户余额不能被加载.",
"wallet_receive_error": "接受代币是出现异常错误.",
Expand Down
23 changes: 23 additions & 0 deletions src/frontend/src/lib/services/wallet.loader.services.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { balanceCertifiedStore } from '$lib/stores/balance.store';
import { exchangePricesCanisterDataStore } from '$lib/stores/exchange.store';
import { i18n } from '$lib/stores/i18n.store';
import { toasts } from '$lib/stores/toasts.store';
import { transactionsCertifiedStore } from '$lib/stores/transactions.store';
import type {
PostMessageDataResponseExchange,
PostMessageDataResponseWallet
} from '$lib/types/post-message';
import { isNullish, jsonReviver } from '@dfinity/utils';
import { get } from 'svelte/store';

export const onSyncWallet = (data: PostMessageDataResponseWallet) => {
if (isNullish(data.wallet)) {
Expand All @@ -19,6 +22,26 @@ export const onSyncWallet = (data: PostMessageDataResponseWallet) => {
transactionsCertifiedStore.prepend(newTransactions);
};

export const onWalletError = ({ error: err }: { error: unknown }) => {
transactionsCertifiedStore.reset();

// We get transactions and balance for the same end point therefore if getting certified transactions fails, it also means the balance is incorrect.
balanceCertifiedStore.reset();

toasts.error({
text: get(i18n).errors.wallet_error,
detail: err
});
};

export const onWalletCleanUp = ({ transactionIds }: { transactionIds: string[] }) => {
transactionsCertifiedStore.cleanUp(transactionIds);

toasts.error({
text: get(i18n).errors.wallet_uncertified_transactions_removed
});
};

export const onSyncExchange = (data: PostMessageDataResponseExchange) => {
if (isNullish(data.exchange)) {
return;
Expand Down
17 changes: 16 additions & 1 deletion src/frontend/src/lib/services/worker.wallet.services.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { onSyncExchange, onSyncWallet } from '$lib/services/wallet.loader.services';
import {
onSyncExchange,
onSyncWallet,
onWalletCleanUp,
onWalletError
} from '$lib/services/wallet.loader.services';
import type { MissionControlId } from '$lib/types/mission-control';
import type {
PostMessage,
Expand Down Expand Up @@ -33,6 +38,16 @@ export const initWalletWorker = async (): Promise<WalletWorker> => {
case 'syncWallet':
onSyncWallet(data.data as PostMessageDataResponseWallet);
return;
case 'syncWalletError':
onWalletError({
error: (data.data as PostMessageDataResponseError).error
});
return;
case 'syncWalletCleanUp':
onWalletCleanUp({
transactionIds: (data.data as PostMessageDataResponseWalletCleanUp).transactionIds
});
return;
case 'syncExchange':
onSyncExchange(data.data as PostMessageDataResponseExchange);
return;
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/lib/types/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ interface I18nErrors {
snapshot_restore_error: string;
snapshot_delete_error: string;
snapshot_list_error: string;
wallet_error: string;
wallet_uncertified_transactions_removed: string;
wallet_no_account: string;
wallet_load_balance: string;
wallet_receive_error: string;
Expand Down

0 comments on commit ee0f8ea

Please sign in to comment.