From f19cf6686eaa327f56a645a2c3290baa2e513782 Mon Sep 17 00:00:00 2001 From: Korbinian Date: Wed, 8 May 2024 15:22:10 +0200 Subject: [PATCH 1/2] feat(bridge-ui): update token dropdown (#16979) --- .../src/components/Alert/FlatAlert.svelte | 2 +- .../AddressInput/AddressInput.svelte | 2 +- .../components/DialogTabs/DialogTab.svelte | 40 ++++ .../components/DialogTabs/DialogTabs.svelte | 24 +++ .../src/components/DialogTabs/index.ts | 2 + .../bridge-ui/src/components/Icon/Icon.svelte | 2 +- .../src/components/InputBox/InputBox.svelte | 2 +- .../TokenDropdown/AddCustomERC20.svelte | 27 +-- .../TokenDropdown/DialogView.svelte | 172 ++++++++++----- .../TokenDropdown/DropdownView.svelte | 199 ++++++++++++------ .../TokenDropdown/TokenDropdown.svelte | 43 +++- .../src/components/TokenDropdown/types.ts | 9 + packages/bridge-ui/src/i18n/en.json | 5 +- .../src/libs/fee/recommendProcessingFee.ts | 12 -- packages/bridge-ui/src/styles/components.css | 5 +- 15 files changed, 388 insertions(+), 158 deletions(-) create mode 100644 packages/bridge-ui/src/components/DialogTabs/DialogTab.svelte create mode 100644 packages/bridge-ui/src/components/DialogTabs/DialogTabs.svelte create mode 100644 packages/bridge-ui/src/components/DialogTabs/index.ts create mode 100644 packages/bridge-ui/src/components/TokenDropdown/types.ts diff --git a/packages/bridge-ui/src/components/Alert/FlatAlert.svelte b/packages/bridge-ui/src/components/Alert/FlatAlert.svelte index 6fc7fd4d029..a82472fe189 100644 --- a/packages/bridge-ui/src/components/Alert/FlatAlert.svelte +++ b/packages/bridge-ui/src/components/Alert/FlatAlert.svelte @@ -30,7 +30,7 @@ info: { textClass: 'text-secondary-content', iconType: 'info-circle', - iconFillClass: 'fill-info-content', + iconFillClass: 'fill-secondary-content', }, }; diff --git a/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/AddressInput/AddressInput.svelte b/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/AddressInput/AddressInput.svelte index 92fd502b3c7..f7a8d25ce4b 100644 --- a/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/AddressInput/AddressInput.svelte +++ b/packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/AddressInput/AddressInput.svelte @@ -99,7 +99,7 @@ {#if !quiet} -
+
{#if state === State.INVALID && ethereumAddress} {:else if state === State.TOO_SHORT && ethereumAddress} diff --git a/packages/bridge-ui/src/components/DialogTabs/DialogTab.svelte b/packages/bridge-ui/src/components/DialogTabs/DialogTab.svelte new file mode 100644 index 00000000000..9c1ab0557fe --- /dev/null +++ b/packages/bridge-ui/src/components/DialogTabs/DialogTab.svelte @@ -0,0 +1,40 @@ + + + + + diff --git a/packages/bridge-ui/src/components/DialogTabs/DialogTabs.svelte b/packages/bridge-ui/src/components/DialogTabs/DialogTabs.svelte new file mode 100644 index 00000000000..919434c01d3 --- /dev/null +++ b/packages/bridge-ui/src/components/DialogTabs/DialogTabs.svelte @@ -0,0 +1,24 @@ + + +
+ {#each tabs as tab} + setActiveTab(tab.id)}> + {tab.title} + + {/each} +
diff --git a/packages/bridge-ui/src/components/DialogTabs/index.ts b/packages/bridge-ui/src/components/DialogTabs/index.ts new file mode 100644 index 00000000000..1db8f2a45c8 --- /dev/null +++ b/packages/bridge-ui/src/components/DialogTabs/index.ts @@ -0,0 +1,2 @@ +export { default as DialogTab } from './DialogTab.svelte'; +export { default as DialogTabs } from './DialogTabs.svelte'; diff --git a/packages/bridge-ui/src/components/Icon/Icon.svelte b/packages/bridge-ui/src/components/Icon/Icon.svelte index 95e37b2de99..87b3de139e2 100644 --- a/packages/bridge-ui/src/components/Icon/Icon.svelte +++ b/packages/bridge-ui/src/components/Icon/Icon.svelte @@ -202,7 +202,7 @@ class={fillClass} fill-rule="evenodd" clip-rule="evenodd" - d="M20,6H16V5a3,3,0,0,0-3-3H11A3,3,0,0,0,8,5V6H4A1,1,0,0,0,4,8H5V19a3,3,0,0,0,3,3h8a3,3,0,0,0,3-3V8h1a1,1,0,0,0,0-2ZM10,5a1,1,0,0,1,1-1h2a1,1,0,0,1,1,1V6H10Zm7,14a1,1,0,0,1-1,1H8a1,1,0,0,1-1-1V8H17Z" /> + d="M6.12461 0.699951C5.06146 0.699951 4.19961 1.5618 4.19961 2.62495V2.93484C3.64291 2.98875 3.09083 3.05858 2.54381 3.14386C2.25733 3.18852 2.06129 3.45697 2.10595 3.74346C2.15061 4.02995 2.41907 4.22599 2.70556 4.18132L2.80909 4.16538L3.39814 11.5285C3.47817 12.5289 4.31339 13.2999 5.31701 13.2999H8.68206C9.68568 13.2999 10.5209 12.5289 10.6009 11.5285L11.19 4.16534L11.2938 4.18132C11.5803 4.22599 11.8488 4.02995 11.8934 3.74346C11.9381 3.45697 11.742 3.18852 11.4556 3.14386C10.9085 3.05857 10.3564 2.98874 9.79961 2.93482V2.62495C9.79961 1.5618 8.93776 0.699951 7.87461 0.699951H6.12461ZM6.99968 2.79995C7.58723 2.79995 8.17071 2.81761 8.74961 2.85244V2.62495C8.74961 2.1417 8.35786 1.74995 7.87461 1.74995H6.12461C5.64136 1.74995 5.24961 2.1417 5.24961 2.62495V2.85245C5.82856 2.81762 6.41208 2.79995 6.99968 2.79995ZM5.94903 5.40625C5.93868 5.14758 5.72059 4.94626 5.46192 4.95661C5.20324 4.96696 5.00193 5.18505 5.01228 5.44372L5.22229 10.6937C5.23263 10.9524 5.45072 11.1537 5.7094 11.1434C5.96807 11.133 6.16938 10.9149 6.15904 10.6563L5.94903 5.40625ZM8.98704 5.44372C8.99738 5.18505 8.79607 4.96696 8.5374 4.95661C8.27872 4.94627 8.06063 5.14758 8.05029 5.40625L7.84029 10.6563C7.82994 10.9149 8.03125 11.133 8.28993 11.1434C8.5486 11.1537 8.76669 10.9524 8.77704 10.6937L8.98704 5.44372Z" /> {:else if type === 'adjustments'} { - log('remove token', token); - const address = $account.address; - tokenService.removeToken(token, address as Address); - customTokens = tokenService.getTokens(address as Address); dispatch('tokenRemoved', { token }); }; @@ -155,8 +151,6 @@ ? formatUnits(customTokenWithDetails.balance, customTokenWithDetails.decimals) : 0; - $: customTokens = tokenService.getTokens($account?.address as Address); - $: disabled = state !== AddressInputState.VALID || tokenAddress === '' || tokenAddress.length !== 42; const closeModalIfClickedOutside = (e: MouseEvent) => { @@ -186,7 +180,7 @@ on:addressvalidation={onAddressValidation} bind:state onDialog /> -
+
{#if customTokenWithDetails} {$t('common.name')}: {customTokenWithDetails.symbol} {$t('common.balance')}: {formattedBalance} @@ -194,16 +188,12 @@ {:else if loadingTokenDetails} - {:else} -
+ {:else if state === AddressInputState.DEFAULT} + {/if}
- - - {$t('token_dropdown.custom_token.button')} - - +
{#if customTokens.length > 0}

{$t('token_dropdown.imported_tokens')}

@@ -217,10 +207,15 @@
-
{/each}
+ {:else} + {$t('token_dropdown.no_imported_token')} {/if} +
+ + {$t('token_dropdown.custom_token.button')} +
diff --git a/packages/bridge-ui/src/components/TokenDropdown/DialogView.svelte b/packages/bridge-ui/src/components/TokenDropdown/DialogView.svelte index cf199d2b111..cb355971ce1 100644 --- a/packages/bridge-ui/src/components/TokenDropdown/DialogView.svelte +++ b/packages/bridge-ui/src/components/TokenDropdown/DialogView.svelte @@ -1,34 +1,49 @@ -
    - {#each tokens as t (t.symbol)} -
  • selectToken(t)} - on:keydown={getTokenKeydownHandler(t)}> -
    - - {#if symbolToIconMap[t.symbol] && !t.imported} - - - - {:else} - - - - {/if} - {t.symbol} -
    -
  • - {/each} - {#if !onlyMintable} - {#each customTokens as ct, index (index)} -
  • selectToken(ct)} - on:keydown={getTokenKeydownHandler(ct)}> -
    - - - - {truncateString(ct.symbol, 10)} -
    -
  • - {/each} -
    -
  • - -
  • - {/if} -
- + {$t('token_dropdown.add_custom')} + + + + {/if} + {/if} + +
diff --git a/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte b/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte index 07ddc5a7869..5b40f1e2b81 100644 --- a/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte +++ b/packages/bridge-ui/src/components/TokenDropdown/TokenDropdown.svelte @@ -1,4 +1,5 @@