Allow sort for value column
This commit is contained in:
parent
283e62efd4
commit
6ffb7368cd
|
@ -13,6 +13,25 @@ export const BALANCE_TABLE_VALUE_ID = 'value'
|
||||||
|
|
||||||
const { nativeCoin } = getNetworkInfo()
|
const { nativeCoin } = getNetworkInfo()
|
||||||
|
|
||||||
|
const getTokenPriceValue = (token: Token, currencyValues?: BalanceCurrencyList, currencyRate?: number): string => {
|
||||||
|
const currencyValue = currencyValues?.find(({ tokenAddress }) => {
|
||||||
|
if (token.address === nativeCoin.address && !tokenAddress) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return token.address === tokenAddress
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!currencyValue || !currencyRate) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const { balanceInBaseCurrency } = currencyValue
|
||||||
|
const balance = new BigNumber(balanceInBaseCurrency).times(currencyRate).toFixed(2)
|
||||||
|
|
||||||
|
return formatAmountInUsFormat(balance)
|
||||||
|
}
|
||||||
|
|
||||||
const getTokenPriceInCurrency = (
|
const getTokenPriceInCurrency = (
|
||||||
token: Token,
|
token: Token,
|
||||||
currencySelected?: string,
|
currencySelected?: string,
|
||||||
|
@ -47,6 +66,7 @@ export interface BalanceData {
|
||||||
balanceOrder: number
|
balanceOrder: number
|
||||||
fixed: boolean
|
fixed: boolean
|
||||||
value: string
|
value: string
|
||||||
|
valueOrder: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getBalanceData = (
|
export const getBalanceData = (
|
||||||
|
@ -56,19 +76,22 @@ export const getBalanceData = (
|
||||||
currencyRate?: number,
|
currencyRate?: number,
|
||||||
): List<BalanceData> => {
|
): List<BalanceData> => {
|
||||||
const { nativeCoin } = getNetworkInfo()
|
const { nativeCoin } = getNetworkInfo()
|
||||||
return activeTokens.map((token) => ({
|
return activeTokens.map((token) => {
|
||||||
[BALANCE_TABLE_ASSET_ID]: {
|
return {
|
||||||
name: token.name,
|
[BALANCE_TABLE_ASSET_ID]: {
|
||||||
logoUri: token.logoUri,
|
name: token.name,
|
||||||
address: token.address,
|
logoUri: token.logoUri,
|
||||||
symbol: token.symbol,
|
address: token.address,
|
||||||
},
|
symbol: token.symbol,
|
||||||
assetOrder: token.name,
|
},
|
||||||
[BALANCE_TABLE_BALANCE_ID]: `${formatAmountInUsFormat(token.balance?.toString() || '0')} ${token.symbol}`,
|
assetOrder: token.name,
|
||||||
balanceOrder: Number(token.balance),
|
[BALANCE_TABLE_BALANCE_ID]: `${formatAmountInUsFormat(token.balance?.toString() || '0')} ${token.symbol}`,
|
||||||
[FIXED]: token.symbol === nativeCoin.symbol,
|
balanceOrder: Number(token.balance),
|
||||||
[BALANCE_TABLE_VALUE_ID]: getTokenPriceInCurrency(token, currencySelected, currencyValues, currencyRate),
|
[FIXED]: token.symbol === nativeCoin.symbol,
|
||||||
}))
|
[BALANCE_TABLE_VALUE_ID]: getTokenPriceInCurrency(token, currencySelected, currencyValues, currencyRate),
|
||||||
|
valueOrder: Number(getTokenPriceValue(token, currencyValues, currencyRate)),
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const generateColumns = (): List<TableColumn> => {
|
export const generateColumns = (): List<TableColumn> => {
|
||||||
|
@ -101,21 +124,10 @@ export const generateColumns = (): List<TableColumn> => {
|
||||||
|
|
||||||
const value: TableColumn = {
|
const value: TableColumn = {
|
||||||
id: BALANCE_TABLE_VALUE_ID,
|
id: BALANCE_TABLE_VALUE_ID,
|
||||||
order: false,
|
order: true,
|
||||||
label: 'Value',
|
label: 'Value',
|
||||||
custom: false,
|
custom: false,
|
||||||
static: true,
|
|
||||||
disablePadding: false,
|
disablePadding: false,
|
||||||
style: {
|
|
||||||
fontSize: '11px',
|
|
||||||
color: '#5d6d74',
|
|
||||||
borderBottomWidth: '2px',
|
|
||||||
width: '125px',
|
|
||||||
fontFamily: 'Averta',
|
|
||||||
fontWeight: 'normal',
|
|
||||||
fontStyle: 'normal',
|
|
||||||
textAlign: 'right',
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return List([assetColumn, balanceColumn, value, actions])
|
return List([assetColumn, balanceColumn, value, actions])
|
||||||
|
|
Loading…
Reference in New Issue