From 1afdf4899d34557d070f385c7f24fb4321e09244 Mon Sep 17 00:00:00 2001 From: Elmar <102954831+elmar-vega@users.noreply.github.com> Date: Mon, 25 Jul 2022 09:07:01 +0100 Subject: [PATCH] Feat/533 update balance styles (#820) * feat(console-lit): change balance styles * feat(console-lit): add tests for deal ticket balance * fix(console-lit): fix typo with wrong library name --- .../deal-ticket/deal-ticket-balance.spec.tsx | 65 +++++++++++++++++++ .../deal-ticket/deal-ticket-balance.tsx | 34 +++++----- .../deal-ticket/deal-ticket-container.tsx | 1 + 3 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.spec.tsx diff --git a/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.spec.tsx b/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.spec.tsx new file mode 100644 index 000000000..c16461b20 --- /dev/null +++ b/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.spec.tsx @@ -0,0 +1,65 @@ +import React from 'react'; +import { render } from '@testing-library/react'; +import type { + PartyBalanceQuery_party_accounts, + PartyBalanceQuery_party_accounts_asset, +} from './__generated__/PartyBalanceQuery'; +import { DealTicketBalance } from './deal-ticket-balance'; + +const tDAI: PartyBalanceQuery_party_accounts_asset = { + __typename: 'Asset', + id: '1', + symbol: 'tDAI', + name: 'TDAI', + decimals: 2, +}; + +const accounts: PartyBalanceQuery_party_accounts[] = [ + { + __typename: 'Account', + balance: '1000000', + asset: tDAI, + }, +]; + +describe('DealTicketBalance', function () { + it('should render the balance', () => { + const { getByText, getByRole } = render( + + ); + + expect(getByRole('complementary')).toHaveAccessibleName('tDAI Balance'); + expect(getByText('10,000.00')).toBeInTheDocument(); + expect(getByText('tDAI')).toBeInTheDocument(); + }); + + it('should prompt to connect wallet', () => { + const { getByText } = render( + + ); + + expect( + getByText('Please connect your Vega wallet to see your balance') + ).toBeInTheDocument(); + }); + + it('should display zero balance', () => { + const { getByText } = render( + + ); + + expect(getByText('No tDAI left to trade')).toBeInTheDocument(); + }); +}); diff --git a/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.tsx b/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.tsx index e0bd91ef8..4d411c0de 100644 --- a/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.tsx +++ b/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-balance.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import classNames from 'classnames'; import type { DealTicketQuery_market_tradableInstrument_instrument_product_settlementAsset } from '@vegaprotocol/deal-ticket'; import type { PartyBalanceQuery_party_accounts } from './__generated__/PartyBalanceQuery'; import { useSettlementAccount } from '../../hooks/use-settlement-account'; @@ -8,12 +9,14 @@ interface DealTicketBalanceProps { settlementAsset: DealTicketQuery_market_tradableInstrument_instrument_product_settlementAsset; accounts: PartyBalanceQuery_party_accounts[]; isWalletConnected: boolean; + className?: string; } export const DealTicketBalance = ({ settlementAsset, accounts, isWalletConnected, + className = '', }: DealTicketBalanceProps) => { const settlementAssetId = settlementAsset?.id; const settlementAssetSymbol = settlementAsset?.symbol; @@ -26,30 +29,29 @@ export const DealTicketBalance = ({ settlementAccount.asset.decimals ); - const balance = settlementAccount ? ( -

- {t( - `${formatedNumber} ${settlementAccount.asset.symbol} available to trade` - )} + const balance = ( +

+ {settlementAccount + ? t(`${formatedNumber}`) + : `No ${settlementAssetSymbol} left to trade`}

- ) : ( -

{t(`You have no ${settlementAssetSymbol} available to trade`)}

); const connectWallet = ( -

- {t( - "Please connect your Vega wallet to see your balance for this market's settlement asset" - )} -

+

{t('Please connect your Vega wallet to see your balance')}

); + const ariaLabel = t(`${settlementAssetSymbol} Balance`); + return ( -
-
- {t('Balance')} +
+ ); }; diff --git a/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-container.tsx b/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-container.tsx index f66794906..57c974f16 100644 --- a/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-container.tsx +++ b/apps/simple-trading-app/src/app/components/deal-ticket/deal-ticket-container.tsx @@ -52,6 +52,7 @@ export const DealTicketContainer = () => { 'Loading...' ) : (