From a9267de6538b50551050c20d0144e75c39d683fd Mon Sep 17 00:00:00 2001 From: Art Date: Wed, 3 May 2023 21:35:05 +0200 Subject: [PATCH] feat(trading): asset balances inside asset selector (deposit, withdraw form) (#3590) --- libs/assets/src/lib/asset-option.tsx | 45 ++++++++++-- libs/assets/src/lib/index.ts | 3 +- libs/assets/src/lib/use-balances-store.ts | 69 +++++++++++++++++++ libs/deposits/src/lib/asset-balance.tsx | 42 +++++++++++ libs/deposits/src/lib/deposit-form.tsx | 13 +++- libs/deposits/src/lib/index.ts | 5 +- libs/deposits/src/lib/use-submit-faucet.ts | 4 +- libs/utils/src/lib/is-asset-erc20.ts | 2 +- libs/withdraws/src/lib/asset-balance.tsx | 30 ++++++++ .../src/lib/withdraw-form-container.spec.tsx | 6 ++ libs/withdraws/src/lib/withdraw-form.spec.tsx | 5 ++ libs/withdraws/src/lib/withdraw-form.tsx | 7 +- .../src/lib/withdraw-manager.spec.tsx | 5 ++ 13 files changed, 223 insertions(+), 13 deletions(-) create mode 100644 libs/assets/src/lib/use-balances-store.ts create mode 100644 libs/deposits/src/lib/asset-balance.tsx create mode 100644 libs/withdraws/src/lib/asset-balance.tsx diff --git a/libs/assets/src/lib/asset-option.tsx b/libs/assets/src/lib/asset-option.tsx index 0df06a490..2d67c79a8 100644 --- a/libs/assets/src/lib/asset-option.tsx +++ b/libs/assets/src/lib/asset-option.tsx @@ -1,13 +1,50 @@ import { Option } from '@vegaprotocol/ui-toolkit'; import type { AssetFieldsFragment } from './__generated__/Asset'; +import classNames from 'classnames'; +import { t } from '@vegaprotocol/i18n'; +import type { ReactNode } from 'react'; -export const AssetOption = ({ asset }: { asset: AssetFieldsFragment }) => { +type AssetOptionProps = { + asset: AssetFieldsFragment; + balance?: ReactNode; +}; + +export const Balance = ({ + balance, + symbol, +}: { + balance?: string; + symbol: string; +}) => + balance ? ( +
+ {balance} {symbol} +
+ ) : ( +
{t('Fetching balanceā€¦')}
+ ); + +export const AssetOption = ({ asset, balance }: AssetOptionProps) => { return (