From 24ed8971abb616225c6ee341de2cb0aa14664c24 Mon Sep 17 00:00:00 2001 From: Max Strasinsky Date: Wed, 11 Sep 2024 23:28:15 +0200 Subject: [PATCH 01/24] New type UserTokenFailed --- .../TokensTable/TokenActionsCell.svelte | 3 ++- .../TokensTable/TokenBalanceCell.svelte | 16 ++++++++++---- .../tokens/TokensTable/TokenTitleCell.svelte | 8 +++++-- frontend/src/lib/types/tokens-page.ts | 8 ++++++- frontend/src/lib/utils/user-token.utils.ts | 22 ++++++++++++++++--- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte b/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte index 4f19fc9e284..4d3b48d53cc 100644 --- a/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte +++ b/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte @@ -1,6 +1,7 @@ -{#if rowData.balance === "loading"} +{#if isUserTokenLoading(rowData)} -{:else} +{:else if isUserTokenData(rowData)} {/if} diff --git a/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte b/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte index acbe27f2577..fd2c0b179c3 100644 --- a/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte +++ b/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte @@ -1,5 +1,9 @@
- -
-
{rowData.title}
- {#if nonNullish(rowData.subtitle)} - {rowData.subtitle} - {/if} -
+ {#if isUserTokenFailed(rowData)} + +
+ +
+
+ + {:else} + +
+
{rowData.title}
+ {#if nonNullish(rowData.subtitle)} + {rowData.subtitle} + {/if} +
+ {/if} {#if importedToken} {$i18n.import_token.imported_token} {/if} + {#if isUserTokenFailed(rowData)} +
+ {/if}
From 5de0283f518db87c3159b34f6f43362bcef1d0d3 Mon Sep 17 00:00:00 2001 From: Max Strasinsky Date: Wed, 11 Sep 2024 23:54:35 +0200 Subject: [PATCH 04/24] Add compareFailedTokensLast for table sorting --- frontend/src/lib/utils/tokens-table.utils.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frontend/src/lib/utils/tokens-table.utils.ts b/frontend/src/lib/utils/tokens-table.utils.ts index 45e4e2c8f75..7c6c8ea4bed 100644 --- a/frontend/src/lib/utils/tokens-table.utils.ts +++ b/frontend/src/lib/utils/tokens-table.utils.ts @@ -7,6 +7,7 @@ import { mergeComparators, } from "$lib/utils/responsive-table.utils"; import { TokenAmountV2 } from "@dfinity/utils"; +import { isUserTokenFailed } from "./user-token.utils"; const getTokenBalanceOrZero = (token: UserToken) => token.balance instanceof TokenAmountV2 ? token.balance.toUlps() : 0n; @@ -15,6 +16,10 @@ export const compareTokensIcpFirst = createDescendingComparator( (token: UserToken) => token.universeId.toText() === OWN_CANISTER_ID_TEXT ); +export const compareFailedTokensLast = createAscendingComparator( + (token: UserToken) => isUserTokenFailed(token) +); + export const compareTokensWithBalanceOrImportedFirst = ({ importedTokenIds, }: { @@ -49,6 +54,7 @@ export const compareTokensForTokensTable = ({ }) => mergeComparators([ compareTokensIcpFirst, + compareFailedTokensLast, compareTokensWithBalanceOrImportedFirst({ importedTokenIds }), compareTokensByImportance, compareTokensAlphabetically, From 811fab5ee33578a6427c5016f9a60b79d3bdf641 Mon Sep 17 00:00:00 2001 From: Max Strasinsky Date: Thu, 12 Sep 2024 17:25:50 +0200 Subject: [PATCH 05/24] Use question-mark.svg for failed to load token --- frontend/src/lib/assets/question-mark.svg | 5 ++--- .../tokens/TokensTable/TokenTitleCell.svelte | 10 ++-------- frontend/src/lib/utils/tokens-table.utils.ts | 2 +- frontend/src/lib/utils/user-token.utils.ts | 3 ++- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/frontend/src/lib/assets/question-mark.svg b/frontend/src/lib/assets/question-mark.svg index ce048bc98c7..3b6c2a8acb2 100644 --- a/frontend/src/lib/assets/question-mark.svg +++ b/frontend/src/lib/assets/question-mark.svg @@ -1,4 +1,3 @@ - - - ? + + diff --git a/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte b/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte index fb97d443239..26f0290f285 100644 --- a/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte +++ b/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte @@ -8,7 +8,7 @@ import { isImportedToken } from "$lib/utils/imported-tokens.utils"; import Logo from "$lib/components/ui/Logo.svelte"; import { nonNullish } from "@dfinity/utils"; - import { IconError, IconWarning, Tag } from "@dfinity/gix-components"; + import { IconError, Tag } from "@dfinity/gix-components"; import { i18n } from "$lib/stores/i18n"; import LogoWrapper from "$lib/components/ui/LogoWrapper.svelte"; import Hash from "$lib/components/ui/Hash.svelte"; @@ -24,22 +24,16 @@
+ {#if isUserTokenFailed(rowData)} - -
- -
-
{:else} -
{rowData.title}
{#if nonNullish(rowData.subtitle)} diff --git a/frontend/src/lib/utils/tokens-table.utils.ts b/frontend/src/lib/utils/tokens-table.utils.ts index 7c6c8ea4bed..88ecfa0b343 100644 --- a/frontend/src/lib/utils/tokens-table.utils.ts +++ b/frontend/src/lib/utils/tokens-table.utils.ts @@ -54,8 +54,8 @@ export const compareTokensForTokensTable = ({ }) => mergeComparators([ compareTokensIcpFirst, - compareFailedTokensLast, compareTokensWithBalanceOrImportedFirst({ importedTokenIds }), + compareFailedTokensLast, compareTokensByImportance, compareTokensAlphabetically, ]); diff --git a/frontend/src/lib/utils/user-token.utils.ts b/frontend/src/lib/utils/user-token.utils.ts index df0df9cf985..0932667e348 100644 --- a/frontend/src/lib/utils/user-token.utils.ts +++ b/frontend/src/lib/utils/user-token.utils.ts @@ -2,6 +2,7 @@ import type { UserTokenData, UserTokenFailed, UserTokenLoading, +import UNKNOWN_LOGO from "$lib/assets/question-mark.svg"; } from "$lib/types/tokens-page"; import { Principal } from "@dfinity/principal"; @@ -29,7 +30,7 @@ export const toUserTokenFailed = ( universeId: Principal.fromText(ledgerCanisterIdText), // Title will be used for sorting. title: ledgerCanisterIdText, - logo: "", + logo: UNKNOWN_LOGO, balance: "failed", domKey: ledgerCanisterIdText, actions: [], From 99e258ff513ccd967abebc18b6af983d27f48a09 Mon Sep 17 00:00:00 2001 From: Max Strasinsky Date: Thu, 12 Sep 2024 17:26:30 +0200 Subject: [PATCH 06/24] style: change (i) icon colour --- .../src/lib/components/tokens/TokensTable/TokenTitleCell.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte b/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte index 26f0290f285..f11d5ead91b 100644 --- a/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte +++ b/frontend/src/lib/components/tokens/TokensTable/TokenTitleCell.svelte @@ -69,7 +69,7 @@ } .failed-token-icon { - color: var(--alert); + color: var(--orange); line-height: 0; } From e8362fa3b0c72ed095fd6cc9a4737d75e8fec890 Mon Sep 17 00:00:00 2001 From: Max Strasinsky Date: Thu, 12 Sep 2024 17:27:23 +0200 Subject: [PATCH 07/24] Add actions for failed imported token --- .../TokensTable/TokenActionsCell.svelte | 16 +++++++++--- .../actions/GoToDashboardButton.svelte | 12 +++++++++ .../TokensTable/actions/RemoveButton.svelte | 26 +++++++++++++++++++ frontend/src/lib/types/tokens-page.ts | 4 ++- frontend/src/lib/utils/user-token.utils.ts | 11 ++++---- 5 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 frontend/src/lib/components/tokens/TokensTable/actions/GoToDashboardButton.svelte create mode 100644 frontend/src/lib/components/tokens/TokensTable/actions/RemoveButton.svelte diff --git a/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte b/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte index 4d3b48d53cc..2c1c61029f4 100644 --- a/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte +++ b/frontend/src/lib/components/tokens/TokensTable/TokenActionsCell.svelte @@ -5,9 +5,14 @@ type UserTokenData, type UserTokenLoading, } from "$lib/types/tokens-page"; - import { isUserTokenData } from "$lib/utils/user-token.utils"; + import { + isUserTokenData, + isUserTokenFailed, + } from "$lib/utils/user-token.utils"; + import GoToDashboardButton from "./actions/GoToDashboardButton.svelte"; import GoToDetailIcon from "./actions/GoToDetailIcon.svelte"; import ReceiveButton from "./actions/ReceiveButton.svelte"; + import RemoveButton from "./actions/RemoveButton.svelte"; import SendButton from "./actions/SendButton.svelte"; import { nonNullish } from "@dfinity/utils"; import type { SvelteComponent, ComponentType } from "svelte"; @@ -21,10 +26,15 @@ [UserTokenAction.GoToDetail]: GoToDetailIcon, [UserTokenAction.Receive]: ReceiveButton, [UserTokenAction.Send]: SendButton, + [UserTokenAction.GoToDashboard]: GoToDashboardButton, + [UserTokenAction.Remove]: RemoveButton, }; - let userToken: UserTokenData | undefined; - $: userToken = isUserTokenData(rowData) ? rowData : undefined; + let userToken: UserTokenData | UserTokenFailed | undefined; + $: userToken = + isUserTokenData(rowData) || isUserTokenFailed(rowData) + ? rowData + : undefined; {#if nonNullish(userToken)} diff --git a/frontend/src/lib/components/tokens/TokensTable/actions/GoToDashboardButton.svelte b/frontend/src/lib/components/tokens/TokensTable/actions/GoToDashboardButton.svelte new file mode 100644 index 00000000000..63b60df9f60 --- /dev/null +++ b/frontend/src/lib/components/tokens/TokensTable/actions/GoToDashboardButton.svelte @@ -0,0 +1,12 @@ + + + diff --git a/frontend/src/lib/components/tokens/TokensTable/actions/RemoveButton.svelte b/frontend/src/lib/components/tokens/TokensTable/actions/RemoveButton.svelte new file mode 100644 index 00000000000..f619dd31ddc --- /dev/null +++ b/frontend/src/lib/components/tokens/TokensTable/actions/RemoveButton.svelte @@ -0,0 +1,26 @@ + + + + + diff --git a/frontend/src/lib/types/tokens-page.ts b/frontend/src/lib/types/tokens-page.ts index ba4ffd67e03..5c7e3f99db5 100644 --- a/frontend/src/lib/types/tokens-page.ts +++ b/frontend/src/lib/types/tokens-page.ts @@ -16,6 +16,8 @@ export enum UserTokenAction { Send = "send", GoToDetail = "goToDetail", Receive = "receive", + GoToDashboard = "goToDashboard", + Remove = "remove", } export type UserTokenBase = { @@ -42,7 +44,7 @@ export type UserTokenLoading = UserTokenBase & { export type UserTokenFailed = UserTokenBase & { balance: "failed"; - actions: []; + actions: UserTokenAction[]; domKey: string; }; diff --git a/frontend/src/lib/utils/user-token.utils.ts b/frontend/src/lib/utils/user-token.utils.ts index 0932667e348..f351b0bab0e 100644 --- a/frontend/src/lib/utils/user-token.utils.ts +++ b/frontend/src/lib/utils/user-token.utils.ts @@ -1,8 +1,9 @@ -import type { - UserTokenData, - UserTokenFailed, - UserTokenLoading, import UNKNOWN_LOGO from "$lib/assets/question-mark.svg"; +import { + UserTokenAction, + type UserTokenData, + type UserTokenFailed, + type UserTokenLoading, } from "$lib/types/tokens-page"; import { Principal } from "@dfinity/principal"; @@ -33,5 +34,5 @@ export const toUserTokenFailed = ( logo: UNKNOWN_LOGO, balance: "failed", domKey: ledgerCanisterIdText, - actions: [], + actions: [UserTokenAction.GoToDashboard, UserTokenAction.Remove], }); From 665eb37a5dcbd1972ae2f6039281947b50e1e6bf Mon Sep 17 00:00:00 2001 From: Max Strasinsky Date: Thu, 12 Sep 2024 17:27:36 +0200 Subject: [PATCH 08/24] Display unknown balance --- .../lib/components/tokens/TokensTable/TokenBalanceCell.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/src/lib/components/tokens/TokensTable/TokenBalanceCell.svelte b/frontend/src/lib/components/tokens/TokensTable/TokenBalanceCell.svelte index 69d0230d9cf..b2df99ba43a 100644 --- a/frontend/src/lib/components/tokens/TokensTable/TokenBalanceCell.svelte +++ b/frontend/src/lib/components/tokens/TokensTable/TokenBalanceCell.svelte @@ -20,6 +20,8 @@ > {:else if isUserTokenData(rowData)} +{:else} + -/- {/if}