Set lower reset time functions for Rinkeby (#2307)

This commit is contained in:
Daniel Sanchez 2021-05-18 17:24:12 +02:00 committed by GitHub
parent ec247d9017
commit 3f66ebd2a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 18 deletions

View File

@ -4,6 +4,7 @@ import React, { ReactElement } from 'react'
import { useField } from 'react-final-form'
import styled from 'styled-components'
import { getNetworkName } from 'src/config'
import { Field } from 'src/routes/safe/components/Settings/SpendingLimit/FormFields/Amount'
// TODO: propose refactor in safe-react-components based on this requirements
@ -81,17 +82,30 @@ const ResetTimeOptions = styled.div`
grid-area: resetTimeOption;
`
export const RESET_TIME_OPTIONS = [
{ label: '1 day', value: '1' },
{ label: '1 week', value: '7' },
{ label: '1 month', value: '30' },
const RESET_TIME_OPTIONS = [
{ label: '1 day', value: '1440' }, // 1 day x 24h x 60min
{ label: '1 week', value: '10080' }, // 7 days x 24h x 60min
{ label: '1 month', value: '43200' }, // 30 days x 24h x 60min
]
const RINKEBY_RESET_TIME_OPTIONS = [
{ label: '5 minutes', value: '5' },
{ label: '30 minutes', value: '30' },
{ label: '1 hour', value: '60' },
]
export const getResetTimeOptions = (): RadioButtonOption[] => {
const currentNetwork = getNetworkName().toLowerCase()
return currentNetwork !== 'rinkeby' ? RESET_TIME_OPTIONS : RINKEBY_RESET_TIME_OPTIONS
}
const ResetTime = (): ReactElement => {
const {
input: { value: withResetTime },
} = useField('withResetTime', { subscription: { value: true } })
const resetTimeOptions = getResetTimeOptions()
const switchExplanation = withResetTime ? 'choose reset time period' : 'one time'
return (
@ -104,11 +118,7 @@ const ResetTime = (): ReactElement => {
</ResetTimeToggle>
{withResetTime && (
<ResetTimeOptions>
<SafeRadioButtons
groupName="resetTime"
initialValue={RESET_TIME_OPTIONS[0].value}
options={RESET_TIME_OPTIONS}
/>
<SafeRadioButtons groupName="resetTime" initialValue={resetTimeOptions[0].value} options={resetTimeOptions} />
</ResetTimeOptions>
)}
</>

View File

@ -20,7 +20,7 @@ import { MultiSendTx } from 'src/logic/safe/utils/upgradeSafe'
import { makeToken, Token } from 'src/logic/tokens/store/model/token'
import { fromTokenUnit, toTokenUnit } from 'src/logic/tokens/utils/humanReadableValue'
import { sameAddress } from 'src/logic/wallets/ethAddresses'
import { RESET_TIME_OPTIONS } from 'src/routes/safe/components/Settings/SpendingLimit/FormFields/ResetTime'
import { getResetTimeOptions } from 'src/routes/safe/components/Settings/SpendingLimit/FormFields/ResetTime'
import { AddressInfo, ResetTimeInfo, TokenInfo } from 'src/routes/safe/components/Settings/SpendingLimit/InfoDisplay'
import { useStyles } from 'src/routes/safe/components/Settings/SpendingLimit/style'
import { safeParamAddressFromStateSelector, safeSpendingLimitsSelector } from 'src/logic/safe/store/selectors'
@ -104,7 +104,7 @@ const calculateSpendingLimitsTxData = (
beneficiary: values.beneficiary,
token: values.token,
spendingLimitInWei: toTokenUnit(values.amount, txToken.decimals),
resetTimeMin: values.withResetTime ? +values.resetTime * 60 * 24 : 0,
resetTimeMin: values.withResetTime ? +values.resetTime : 0,
resetBaseMin: values.withResetTime ? startTime : 0,
}
@ -209,13 +209,13 @@ export const ReviewSpendingLimits = ({ onBack, onClose, txToken, values }: Revie
}
const resetTimeLabel = useMemo(
() => (values.withResetTime ? RESET_TIME_OPTIONS.find(({ value }) => value === values.resetTime)?.label : ''),
() => (values.withResetTime ? getResetTimeOptions().find(({ value }) => value === values.resetTime)?.label : ''),
[values.resetTime, values.withResetTime],
)
const previousResetTime = (existentSpendingLimit: SpendingLimit) =>
RESET_TIME_OPTIONS.find(({ value }) => value === (+existentSpendingLimit.resetTimeMin / 60 / 24).toString())
?.label ?? 'One-time spending limit'
getResetTimeOptions().find(({ value }) => value === (+existentSpendingLimit.resetTimeMin).toString())?.label ??
'One-time spending limit'
const closeEditModalCallback = (txParameters: TxParameters) => {
const oldGasPrice = Number(gasPriceFormatted)

View File

@ -18,7 +18,7 @@ import { TxParametersDetail } from 'src/routes/safe/components/Transactions/help
import { TxParameters } from 'src/routes/safe/container/hooks/useTransactionParameters'
import { SPENDING_LIMIT_MODULE_ADDRESS } from 'src/utils/constants'
import { RESET_TIME_OPTIONS } from './FormFields/ResetTime'
import { getResetTimeOptions } from './FormFields/ResetTime'
import { AddressInfo, ResetTimeInfo, TokenInfo } from './InfoDisplay'
import { SpendingLimitTable } from './LimitsTable/dataFetcher'
import { useStyles } from './style'
@ -91,7 +91,7 @@ export const RemoveLimitModal = ({ onClose, spendingLimit, open }: RemoveSpendin
}
const resetTimeLabel =
RESET_TIME_OPTIONS.find(({ value }) => +value === +spendingLimit.resetTime.resetTimeMin / 24 / 60)?.label ?? ''
getResetTimeOptions().find(({ value }) => +value === +spendingLimit.resetTime.resetTimeMin)?.label ?? ''
const closeEditModalCallback = (txParameters: TxParameters) => {
const oldGasPrice = Number(gasPriceFormatted)

View File

@ -6,7 +6,7 @@ import styled from 'styled-components'
import useTokenInfo from 'src/logic/safe/hooks/useTokenInfo'
import { DataDecoded } from 'src/logic/safe/store/models/types/gateway.d'
import { fromTokenUnit } from 'src/logic/tokens/utils/humanReadableValue'
import { RESET_TIME_OPTIONS } from 'src/routes/safe/components/Settings/SpendingLimit/FormFields/ResetTime'
import { getResetTimeOptions } from 'src/routes/safe/components/Settings/SpendingLimit/FormFields/ResetTime'
import { AddressInfo, ResetTimeInfo, TokenInfo } from 'src/routes/safe/components/Settings/SpendingLimit/InfoDisplay'
const SET_ALLOWANCE = 'setAllowance'
@ -35,7 +35,7 @@ export const ModifySpendingLimitDetails = ({ data }: { data: DataDecoded }): Rea
)
const resetTimeLabel = React.useMemo(
() => RESET_TIME_OPTIONS.find(({ value }) => +value === +resetTimeMin / 24 / 60)?.label ?? '',
() => getResetTimeOptions().find(({ value }) => +value === +resetTimeMin)?.label ?? '',
[resetTimeMin],
)