Skip to content

Commit

Permalink
fix: #237: add available balance field to the limit order form (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
VanishMax authored Jan 17, 2025
1 parent ac232f3 commit db00112
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/pages/trade/ui/order-form/info-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface InfoRowProps {
isLoading?: boolean;
value?: string | number;
valueColor?: 'success' | 'error';
toolTip: string;
toolTip?: string;
}

const getValueColor = (valueColor: InfoRowProps['valueColor']) => {
Expand Down Expand Up @@ -42,9 +42,11 @@ export const InfoRow = observer(
</Text>
)}
</div>
<Tooltip message={toolTip}>
<Icon IconComponent={InfoIcon} size='sm' color='text.primary' />
</Tooltip>
{toolTip && (
<Tooltip message={toolTip}>
<Icon IconComponent={InfoIcon} size='sm' color='text.primary' />
</Tooltip>
)}
</div>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions src/pages/trade/ui/order-form/order-form-limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { InfoRowGasFee } from './info-row-gas-fee';
import { SelectGroup } from './select-group';
import { OrderFormStore } from './store/OrderFormStore';
import { BuyLimitOrderOptions, SellLimitOrderOptions } from './store/LimitOrderFormStore';
import { InfoRow } from '@/pages/trade/ui/order-form/info-row';

export const LimitOrderForm = observer(({ parentStore }: { parentStore: OrderFormStore }) => {
const { connected } = connectionStore;
Expand Down Expand Up @@ -54,6 +55,7 @@ export const LimitOrderForm = observer(({ parentStore }: { parentStore: OrderFor
/>
</div>
<div className='mb-4'>
<InfoRow label='Available balance' value={store.balance} />
<InfoRowTradingFee />
<InfoRowGasFee
gasFee={parentStore.gasFee.display}
Expand Down
10 changes: 10 additions & 0 deletions src/pages/trade/ui/order-form/store/LimitOrderFormStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ export class LimitOrderFormStore {
});
}

get balance(): string {
if (this.direction === 'buy' && this._quoteAsset?.balance) {
return this._quoteAsset.formatDisplayAmount(this._quoteAsset.balance);
}
if (this.direction === 'sell' && this._baseAsset?.balance) {
return this._baseAsset.formatDisplayAmount(this._baseAsset.balance);
}
return '--';
}

setAssets(base: AssetInfo, quote: AssetInfo, resetInputs = false) {
this._baseAsset = base;
this._quoteAsset = quote;
Expand Down

0 comments on commit db00112

Please sign in to comment.