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
This commit is contained in:
parent
6b79c1df6e
commit
1afdf4899d
@ -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(
|
||||||
|
<DealTicketBalance
|
||||||
|
settlementAsset={tDAI}
|
||||||
|
accounts={accounts}
|
||||||
|
isWalletConnected
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
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(
|
||||||
|
<DealTicketBalance
|
||||||
|
settlementAsset={tDAI}
|
||||||
|
accounts={accounts}
|
||||||
|
isWalletConnected={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
getByText('Please connect your Vega wallet to see your balance')
|
||||||
|
).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display zero balance', () => {
|
||||||
|
const { getByText } = render(
|
||||||
|
<DealTicketBalance
|
||||||
|
settlementAsset={tDAI}
|
||||||
|
accounts={[]}
|
||||||
|
isWalletConnected={true}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(getByText('No tDAI left to trade')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
@ -1,4 +1,5 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import classNames from 'classnames';
|
||||||
import type { DealTicketQuery_market_tradableInstrument_instrument_product_settlementAsset } from '@vegaprotocol/deal-ticket';
|
import type { DealTicketQuery_market_tradableInstrument_instrument_product_settlementAsset } from '@vegaprotocol/deal-ticket';
|
||||||
import type { PartyBalanceQuery_party_accounts } from './__generated__/PartyBalanceQuery';
|
import type { PartyBalanceQuery_party_accounts } from './__generated__/PartyBalanceQuery';
|
||||||
import { useSettlementAccount } from '../../hooks/use-settlement-account';
|
import { useSettlementAccount } from '../../hooks/use-settlement-account';
|
||||||
@ -8,12 +9,14 @@ interface DealTicketBalanceProps {
|
|||||||
settlementAsset: DealTicketQuery_market_tradableInstrument_instrument_product_settlementAsset;
|
settlementAsset: DealTicketQuery_market_tradableInstrument_instrument_product_settlementAsset;
|
||||||
accounts: PartyBalanceQuery_party_accounts[];
|
accounts: PartyBalanceQuery_party_accounts[];
|
||||||
isWalletConnected: boolean;
|
isWalletConnected: boolean;
|
||||||
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DealTicketBalance = ({
|
export const DealTicketBalance = ({
|
||||||
settlementAsset,
|
settlementAsset,
|
||||||
accounts,
|
accounts,
|
||||||
isWalletConnected,
|
isWalletConnected,
|
||||||
|
className = '',
|
||||||
}: DealTicketBalanceProps) => {
|
}: DealTicketBalanceProps) => {
|
||||||
const settlementAssetId = settlementAsset?.id;
|
const settlementAssetId = settlementAsset?.id;
|
||||||
const settlementAssetSymbol = settlementAsset?.symbol;
|
const settlementAssetSymbol = settlementAsset?.symbol;
|
||||||
@ -26,30 +29,29 @@ export const DealTicketBalance = ({
|
|||||||
settlementAccount.asset.decimals
|
settlementAccount.asset.decimals
|
||||||
);
|
);
|
||||||
|
|
||||||
const balance = settlementAccount ? (
|
const balance = (
|
||||||
<p>
|
<p className="text-blue text-lg font-semibold">
|
||||||
{t(
|
{settlementAccount
|
||||||
`${formatedNumber} ${settlementAccount.asset.symbol} available to trade`
|
? t(`${formatedNumber}`)
|
||||||
)}
|
: `No ${settlementAssetSymbol} left to trade`}
|
||||||
</p>
|
</p>
|
||||||
) : (
|
|
||||||
<p>{t(`You have no ${settlementAssetSymbol} available to trade`)}</p>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const connectWallet = (
|
const connectWallet = (
|
||||||
<p>
|
<p>{t('Please connect your Vega wallet to see your balance')}</p>
|
||||||
{t(
|
|
||||||
"Please connect your Vega wallet to see your balance for this market's settlement asset"
|
|
||||||
)}
|
|
||||||
</p>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const ariaLabel = t(`${settlementAssetSymbol} Balance`);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="text-right">
|
<aside
|
||||||
<div className="border border-current p-16 inline-block">
|
aria-label={ariaLabel}
|
||||||
<small className="text-text">{t('Balance')}</small>
|
className={classNames('text-right', className)}
|
||||||
|
>
|
||||||
|
<div className="inline-block">
|
||||||
|
<span className="text-blue">{settlementAssetSymbol}</span>
|
||||||
{isWalletConnected ? balance : connectWallet}
|
{isWalletConnected ? balance : connectWallet}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</aside>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -52,6 +52,7 @@ export const DealTicketContainer = () => {
|
|||||||
'Loading...'
|
'Loading...'
|
||||||
) : (
|
) : (
|
||||||
<DealTicketBalance
|
<DealTicketBalance
|
||||||
|
className="mb-16"
|
||||||
settlementAsset={
|
settlementAsset={
|
||||||
data.market.tradableInstrument.instrument.product
|
data.market.tradableInstrument.instrument.product
|
||||||
?.settlementAsset
|
?.settlementAsset
|
||||||
|
Loading…
Reference in New Issue
Block a user