From 6f6ee6d3833cf8524c67eae7c8edd47f9c63e715 Mon Sep 17 00:00:00 2001 From: xiaodino Date: Mon, 21 Aug 2023 08:20:24 -0700 Subject: [PATCH] fix(bridge-ui-v2): refresh ETH balance at the top right (#14539) --- .../src/components/Bridge/Amount.svelte | 23 +++++++++++-------- .../ConnectButton/ConnectButton.svelte | 14 +++++++---- .../src/components/Icon/BLL.svelte | 5 ++-- .../src/components/Icon/ERC20.svelte | 5 ++-- .../src/components/Icon/HORSE.svelte | 5 ++-- .../TokenDropdown/TokenDropdown.svelte | 4 ++-- .../src/libs/util/renderBalance.ts | 10 ++++++++ packages/bridge-ui-v2/src/stores/balance.ts | 4 ++++ 8 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 packages/bridge-ui-v2/src/libs/util/renderBalance.ts create mode 100644 packages/bridge-ui-v2/src/stores/balance.ts diff --git a/packages/bridge-ui-v2/src/components/Bridge/Amount.svelte b/packages/bridge-ui-v2/src/components/Bridge/Amount.svelte index 852970f401a..3f12dd87e9c 100644 --- a/packages/bridge-ui-v2/src/components/Bridge/Amount.svelte +++ b/packages/bridge-ui-v2/src/components/Bridge/Amount.svelte @@ -1,5 +1,4 @@ diff --git a/packages/bridge-ui-v2/src/components/Icon/ERC20.svelte b/packages/bridge-ui-v2/src/components/Icon/ERC20.svelte index 752e06e83ad..959e7f0ab17 100644 --- a/packages/bridge-ui-v2/src/components/Icon/ERC20.svelte +++ b/packages/bridge-ui-v2/src/components/Icon/ERC20.svelte @@ -1,6 +1,7 @@ - export let width = 32; - export let height = 32; + export let size = 32; + export let width = size; + export let height = size; diff --git a/packages/bridge-ui-v2/src/components/TokenDropdown/TokenDropdown.svelte b/packages/bridge-ui-v2/src/components/TokenDropdown/TokenDropdown.svelte index aa80a765cc4..e8892c8fbe8 100644 --- a/packages/bridge-ui-v2/src/components/TokenDropdown/TokenDropdown.svelte +++ b/packages/bridge-ui-v2/src/components/TokenDropdown/TokenDropdown.svelte @@ -110,11 +110,11 @@
{#if symbolToIconMap[value.symbol]} - + {:else} - + {/if} {value.symbol} diff --git a/packages/bridge-ui-v2/src/libs/util/renderBalance.ts b/packages/bridge-ui-v2/src/libs/util/renderBalance.ts new file mode 100644 index 00000000000..deae0261f7a --- /dev/null +++ b/packages/bridge-ui-v2/src/libs/util/renderBalance.ts @@ -0,0 +1,10 @@ +import type { FetchBalanceResult } from '@wagmi/core'; + +import { truncateString } from '$libs/util/truncateString'; + +export function renderBalance(balance: Maybe) { + if (!balance) return '0.00'; + + const maxlength = Number(balance.formatted) < 0.000001 ? balance.decimals : 6; + return `${truncateString(balance.formatted, maxlength, '')} ${balance.symbol}`; +} diff --git a/packages/bridge-ui-v2/src/stores/balance.ts b/packages/bridge-ui-v2/src/stores/balance.ts new file mode 100644 index 00000000000..7aac3f64bec --- /dev/null +++ b/packages/bridge-ui-v2/src/stores/balance.ts @@ -0,0 +1,4 @@ +import type { FetchBalanceResult } from '@wagmi/core'; +import { writable } from 'svelte/store'; + +export const ethBalance = writable>(null);