mirror of
https://github.com/status-im/safe-react.git
synced 2025-02-18 12:36:34 +00:00
WA-238 get Daily Limit by token from the safe smart contract (useful for spentToday)
This commit is contained in:
parent
1e42b3d67e
commit
86fad267ca
@ -12,8 +12,9 @@ import SafeView from '~/routes/safe/component/Safe'
|
|||||||
import AppRoutes from '~/routes'
|
import AppRoutes from '~/routes'
|
||||||
import { WITHDRAWN_BUTTON_TEXT } from '~/routes/safe/component/Safe/DailyLimit'
|
import { WITHDRAWN_BUTTON_TEXT } from '~/routes/safe/component/Safe/DailyLimit'
|
||||||
import WithdrawnComponent, { SEE_TXS_BUTTON_TEXT } from '~/routes/safe/component/Withdrawn'
|
import WithdrawnComponent, { SEE_TXS_BUTTON_TEXT } from '~/routes/safe/component/Withdrawn'
|
||||||
import { getBalanceInEtherOf } from '~/wallets/getWeb3'
|
import { getBalanceInEtherOf, getProviderInfo } from '~/wallets/getWeb3'
|
||||||
import { sleep } from '~/utils/timer'
|
import { sleep } from '~/utils/timer'
|
||||||
|
import withdrawn, { DESTINATION_PARAM, VALUE_PARAM, getDailyLimitFrom } from '~/routes/safe/component/Withdrawn/withdrawn'
|
||||||
|
|
||||||
describe('React DOM TESTS > Withdrawn funds from safe', () => {
|
describe('React DOM TESTS > Withdrawn funds from safe', () => {
|
||||||
let SafeDom
|
let SafeDom
|
||||||
@ -70,4 +71,22 @@ describe('React DOM TESTS > Withdrawn funds from safe', () => {
|
|||||||
const visitTxsButton = withdrawnButtons[0]
|
const visitTxsButton = withdrawnButtons[0]
|
||||||
expect(visitTxsButton.props.children).toEqual(SEE_TXS_BUTTON_TEXT)
|
expect(visitTxsButton.props.children).toEqual(SEE_TXS_BUTTON_TEXT)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('spentToday dailyLimitModule property is updated correctly', async () => {
|
||||||
|
const providerInfo = await getProviderInfo()
|
||||||
|
const userAddress = providerInfo.account
|
||||||
|
|
||||||
|
const values = {
|
||||||
|
[DESTINATION_PARAM]: userAddress,
|
||||||
|
[VALUE_PARAM]: '0.01',
|
||||||
|
}
|
||||||
|
await withdrawn(values, address, userAddress)
|
||||||
|
await withdrawn(values, address, userAddress)
|
||||||
|
|
||||||
|
const ethAddress = 0
|
||||||
|
const dailyLimit: DailyLimitProps = await getDailyLimitFrom(address, ethAddress)
|
||||||
|
|
||||||
|
expect(dailyLimit.value).toBe(0.5)
|
||||||
|
expect(dailyLimit.spentToday).toBe(0.02)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { getWeb3 } from '~/wallets/getWeb3'
|
import { getWeb3 } from '~/wallets/getWeb3'
|
||||||
import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts'
|
import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts'
|
||||||
|
import { type DailyLimitProps } from '~/routes/safe/store/model/safe'
|
||||||
|
|
||||||
|
export const LIMIT_POSITION = 0
|
||||||
|
export const SPENT_TODAY_POS = 1
|
||||||
export const DESTINATION_PARAM = 'destination'
|
export const DESTINATION_PARAM = 'destination'
|
||||||
export const VALUE_PARAM = 'ether'
|
export const VALUE_PARAM = 'ether'
|
||||||
|
|
||||||
const withdrawn = async (values: Object, safeAddress: string, userAccount: string): Promise<void> => {
|
const getDailyLimitModuleFrom = async (safeAddress) => {
|
||||||
const web3 = getWeb3()
|
const web3 = getWeb3()
|
||||||
const gnosisSafe = getGnosisSafeContract(web3).at(safeAddress)
|
const gnosisSafe = getGnosisSafeContract(web3).at(safeAddress)
|
||||||
|
|
||||||
@ -17,6 +20,25 @@ const withdrawn = async (values: Object, safeAddress: string, userAccount: strin
|
|||||||
throw new Error('Using an extension of different safe')
|
throw new Error('Using an extension of different safe')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return dailyLimitModule
|
||||||
|
}
|
||||||
|
|
||||||
|
export const getDailyLimitFrom = async (safeAddress, tokenAddress): DailyLimitProps => {
|
||||||
|
const web3 = getWeb3()
|
||||||
|
const dailyLimitModule = await getDailyLimitModuleFrom(safeAddress)
|
||||||
|
|
||||||
|
const dailyLimitEth = await dailyLimitModule.dailyLimits(tokenAddress)
|
||||||
|
|
||||||
|
const limit = web3.fromWei(dailyLimitEth[LIMIT_POSITION].valueOf(), 'ether').toString()
|
||||||
|
const spentToday = web3.fromWei(dailyLimitEth[SPENT_TODAY_POS].valueOf(), 'ether').toString()
|
||||||
|
|
||||||
|
return { value: Number(limit), spentToday: Number(spentToday) }
|
||||||
|
}
|
||||||
|
|
||||||
|
const withdrawn = async (values: Object, safeAddress: string, userAccount: string): Promise<void> => {
|
||||||
|
const web3 = getWeb3()
|
||||||
|
const dailyLimitModule = await getDailyLimitModuleFrom(safeAddress)
|
||||||
|
|
||||||
const destination = values[DESTINATION_PARAM]
|
const destination = values[DESTINATION_PARAM]
|
||||||
const value = web3.toWei(values[VALUE_PARAM], 'ether')
|
const value = web3.toWei(values[VALUE_PARAM], 'ether')
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user