add more robust and performant formatting to pledges table
This commit is contained in:
parent
b8b89cdd7d
commit
8e358aa860
|
@ -2,8 +2,7 @@ import React, { Component } from 'react'
|
|||
import MaterialTable from 'material-table'
|
||||
import withObservables from '@nozbe/with-observables'
|
||||
import { withDatabase } from '@nozbe/watermelondb/DatabaseProvider'
|
||||
import { toEther } from '../utils/conversions'
|
||||
import { getTokenLabel } from '../utils/currencies'
|
||||
import { getTokenLabel, getFormattedPledgeAmount } from '../utils/currencies'
|
||||
import TransferCard from './table/TransferCard'
|
||||
import WithdrawCard from './table/WithdrawCard'
|
||||
|
||||
|
@ -27,7 +26,7 @@ const convertToDatetime = async field => {
|
|||
const formatField = async field => ({
|
||||
...field.getFields(),
|
||||
commitTime: await convertToDatetime(field),
|
||||
amount: toEther(field.amount),
|
||||
amount: getFormattedPledgeAmount(field),
|
||||
token: getTokenLabel(field.token),
|
||||
intendedProject: projectText(field.intendedProject),
|
||||
pledgeState: pledgeStateMap[field.pledgeState],
|
||||
|
@ -51,7 +50,7 @@ class PledgesTable extends Component {
|
|||
pledges.some((pledge, idx) => {
|
||||
const current = data[idx]
|
||||
if (current) {
|
||||
if (toEther(pledge.amount) !== current.amount || pledgeStateMap[pledge.pledgeState] !== current.pledgeState) this.setData()
|
||||
if (getFormattedPledgeAmount(pledge) !== current.amount || pledgeStateMap[pledge.pledgeState] !== current.pledgeState) this.setData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { memoizeWith, identity } from 'ramda'
|
||||
import SNT from '../embarkArtifacts/contracts/SNT'
|
||||
import DAI from '../embarkArtifacts/contracts/DAI'
|
||||
import cDAI from '../embarkArtifacts/contracts/cDAI'
|
||||
|
@ -54,7 +55,7 @@ export const currencies = [
|
|||
}
|
||||
]
|
||||
|
||||
export const getTokenByAddress = value => currencies.find(currency => currency.value.toLowerCase() === value.toLowerCase())
|
||||
export const getTokenByAddress = memoizeWith(identity, value => currencies.find(currency => currency.value.toLowerCase() === value.toLowerCase()))
|
||||
export const getTokenLabel = value => {
|
||||
const token = getTokenByAddress(value)
|
||||
return token ? token.label : null
|
||||
|
@ -64,3 +65,8 @@ export const getTokenAddress = label => {
|
|||
const token = currencies.find(currency => currency.label === label)
|
||||
return token ? token.value : null
|
||||
}
|
||||
|
||||
export const getFormattedPledgeAmount = pledge => {
|
||||
const { humanReadibleFn } = getTokenByAddress(pledge.token)
|
||||
return humanReadibleFn(pledge.amount)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue