(Chore) Update `nativeCoin` address to ZERO_ADDRESS (#2059)

This commit is contained in:
Fernando 2021-03-18 14:02:48 -03:00 committed by GitHub
parent e2c1113377
commit c41ab4eaec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 22 additions and 55 deletions

View File

@ -286,7 +286,7 @@ const xDai: NetworkConfig = {
label: 'xDai',
isTestNet: false,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'xDai',
symbol: 'xDai',
decimals: 18,
@ -343,7 +343,7 @@ const mainnet: NetworkConfig = {
label: 'Mainnet',
isTestNet: false,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,

View File

@ -38,7 +38,7 @@ const mainnet: NetworkConfig = {
label: 'EWC',
isTestNet: false,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'Energy web token',
symbol: 'EWT',
decimals: 18,

View File

@ -29,7 +29,7 @@ const local: NetworkConfig = {
label: 'LocalRPC',
isTestNet: true,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,

View File

@ -38,7 +38,7 @@ const mainnet: NetworkConfig = {
label: 'Mainnet',
isTestNet: false,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,

View File

@ -38,7 +38,7 @@ const rinkeby: NetworkConfig = {
label: 'Rinkeby',
isTestNet: true,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'Ether',
symbol: 'ETH',
decimals: 18,

View File

@ -35,7 +35,7 @@ const mainnet: NetworkConfig = {
label: 'Volta',
isTestNet: true,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'Energy web token',
symbol: 'EWT',
decimals: 18,

View File

@ -29,7 +29,7 @@ const xDai: NetworkConfig = {
label: 'xDai',
isTestNet: false,
nativeCoin: {
address: '0x000',
address: '0x0000000000000000000000000000000000000000',
name: 'xDai',
symbol: 'xDai',
decimals: 18,

View File

@ -1,18 +1,14 @@
import { useSelector } from 'react-redux'
import { getNetworkInfo } from 'src/config'
import { Token } from 'src/logic/tokens/store/model/token'
import { sameAddress, ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { sameAddress } from 'src/logic/wallets/ethAddresses'
import { safeKnownCoins } from 'src/routes/safe/container/selector'
const { nativeCoin } = getNetworkInfo()
const useTokenInfo = (address: string): Token | undefined => {
const tokens = useSelector(safeKnownCoins)
if (tokens) {
const tokenAddress = sameAddress(address, ZERO_ADDRESS) ? nativeCoin.address : address
return tokens.find((token) => sameAddress(token.address, tokenAddress)) ?? undefined
return tokens.find((token) => sameAddress(token.address, address))
}
}

View File

@ -1,5 +1,4 @@
import { BigNumber } from 'bignumber.js'
import { getNetworkInfo } from 'src/config'
import { AbiItem } from 'web3-utils'
import { CreateTransactionArgs } from 'src/logic/safe/store/actions/createTransaction'
@ -9,7 +8,7 @@ import SpendingLimitModule from 'src/logic/contracts/artifacts/AllowanceModule.j
import generateBatchRequests from 'src/logic/contracts/generateBatchRequests'
import { getSpendingLimitContract, MULTI_SEND_ADDRESS } from 'src/logic/contracts/safeContracts'
import { SpendingLimit } from 'src/logic/safe/store/models/safe'
import { sameAddress, ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { sameAddress } from 'src/logic/wallets/ethAddresses'
import { getWeb3, web3ReadOnly } from 'src/logic/wallets/getWeb3'
import { SPENDING_LIMIT_MODULE_ADDRESS } from 'src/utils/constants'
import { getEncodedMultiSendCallData, MultiSendTx } from './upgradeSafe'
@ -138,16 +137,13 @@ type DeleteAllowanceParams = {
}
export const getDeleteAllowanceTxData = ({ beneficiary, tokenAddress }: DeleteAllowanceParams): string => {
const { nativeCoin } = getNetworkInfo()
const token = sameAddress(tokenAddress, nativeCoin.address) ? ZERO_ADDRESS : tokenAddress
const web3 = getWeb3()
const spendingLimitContract = new web3.eth.Contract(
SpendingLimitModule.abi as AbiItem[],
SPENDING_LIMIT_MODULE_ADDRESS,
)
return spendingLimitContract.methods.deleteAllowance(beneficiary, token).encodeABI()
return spendingLimitContract.methods.deleteAllowance(beneficiary, tokenAddress).encodeABI()
}
export const enableSpendingLimitModuleMultiSendTx = (safeAddress: string): MultiSendTx => {
@ -188,20 +184,13 @@ export const setSpendingLimitTx = ({
safeAddress,
}: SpendingLimitTxParams): CreateTransactionArgs => {
const spendingLimitContract = getSpendingLimitContract()
const { nativeCoin } = getNetworkInfo()
const txArgs: CreateTransactionArgs = {
safeAddress,
to: SPENDING_LIMIT_MODULE_ADDRESS,
valueInWei: ZERO_VALUE,
txData: spendingLimitContract.methods
.setAllowance(
beneficiary,
token === nativeCoin.address ? ZERO_ADDRESS : token,
spendingLimitInWei,
resetTimeMin,
resetBaseMin,
)
.setAllowance(beneficiary, token, spendingLimitInWei, resetTimeMin, resetBaseMin)
.encodeABI(),
operation: CALL,
notifiedTransaction: TX_NOTIFICATION_TYPES.NEW_SPENDING_LIMIT_TX,
@ -285,12 +274,5 @@ export const getSpendingLimitByTokenAddress = ({
return
}
const { nativeCoin } = getNetworkInfo()
return spendingLimits.find(({ token: spendingLimitTokenAddress }) => {
spendingLimitTokenAddress = sameAddress(spendingLimitTokenAddress, ZERO_ADDRESS)
? nativeCoin.address
: spendingLimitTokenAddress
return sameAddress(spendingLimitTokenAddress, tokenAddress)
})
return spendingLimits.find(({ token }) => sameAddress(token, tokenAddress))
}

View File

@ -11,8 +11,6 @@ import { AppReduxState } from 'src/store'
import { humanReadableValue } from 'src/logic/tokens/utils/humanReadableValue'
import { safeActiveTokensSelector, safeSelector } from 'src/logic/safe/store/selectors'
import { tokensSelector } from 'src/logic/tokens/store/selectors'
import { sameAddress, ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { getNetworkInfo } from 'src/config'
import BigNumber from 'bignumber.js'
import { currentCurrencySelector } from 'src/logic/currencyValues/store/selectors'
@ -27,24 +25,20 @@ interface ExtractedData {
tokens: List<Token>
}
const { nativeCoin } = getNetworkInfo()
const extractDataFromResult = (currentTokens: TokenState) => (
acc: ExtractedData,
{ balance, fiatBalance, tokenInfo }: TokenBalance,
): ExtractedData => {
const { address: tokenAddress, decimals } = tokenInfo
if (sameAddress(tokenAddress, ZERO_ADDRESS) || sameAddress(tokenAddress, nativeCoin.address)) {
acc.ethBalance = humanReadableValue(balance, 18)
}
const { address, decimals } = tokenInfo
acc.balances = acc.balances.merge({
[tokenAddress]: {
[address]: {
fiatBalance,
tokenBalance: humanReadableValue(balance, Number(decimals)),
},
})
if (currentTokens && !currentTokens.get(tokenAddress)) {
if (currentTokens && !currentTokens.get(address)) {
acc.tokens = acc.tokens.push(makeToken({ ...tokenInfo }))
}

View File

@ -5,7 +5,6 @@ import { useDispatch, useSelector } from 'react-redux'
import Block from 'src/components/layout/Block'
import Col from 'src/components/layout/Col'
import Row from 'src/components/layout/Row'
import { getNetworkInfo } from 'src/config'
import { createTransaction, CreateTransactionArgs } from 'src/logic/safe/store/actions/createTransaction'
import { SafeRecordProps, SpendingLimit } from 'src/logic/safe/store/models/safe'
import {
@ -20,7 +19,7 @@ import {
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, ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { sameAddress } from 'src/logic/wallets/ethAddresses'
import { RESET_TIME_OPTIONS } from 'src/routes/safe/components/Settings/SpendingLimit/FormFields/ResetTime'
import { AddressInfo, ResetTimeInfo, TokenInfo } from 'src/routes/safe/components/Settings/SpendingLimit/InfoDisplay'
import Modal from 'src/routes/safe/components/Settings/SpendingLimit/Modal'
@ -34,8 +33,6 @@ import { EditableTxParameters } from 'src/routes/safe/components/Transactions/he
import { TransactionFees } from 'src/components/TransactionsFees'
import { EstimationStatus, useEstimateTransactionGas } from 'src/logic/hooks/useEstimateTransactionGas'
const { nativeCoin } = getNetworkInfo()
const useExistentSpendingLimit = ({
spendingLimits,
txToken,
@ -51,9 +48,7 @@ const useExistentSpendingLimit = ({
return useMemo<SpendingLimit | null>(() => {
// if `delegate` already exist, check what tokens were delegated to the _beneficiary_ `getTokens(safe, delegate)`
const currentDelegate = spendingLimits?.find(
({ delegate, token }) =>
sameAddress(delegate, values.beneficiary) &&
sameAddress(token, sameAddress(values.token, nativeCoin.address) ? ZERO_ADDRESS : values.token),
({ delegate, token }) => sameAddress(delegate, values.beneficiary) && sameAddress(token, values.token),
)
// let the user know that is about to replace an existent allowance

View File

@ -4,7 +4,7 @@ import { createSelector } from 'reselect'
import { Token } from 'src/logic/tokens/store/model/token'
import { tokensSelector } from 'src/logic/tokens/store/selectors'
import { getEthAsToken } from 'src/logic/tokens/utils/tokenHelpers'
import { isUserAnOwner, sameAddress, ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { isUserAnOwner, sameAddress } from 'src/logic/wallets/ethAddresses'
import { userAccountSelector } from 'src/logic/wallets/store/selectors'
import { safeActiveTokensSelector, safeBalancesSelector, safeSelector } from 'src/logic/safe/store/selectors'
@ -37,7 +37,7 @@ export const extendedSafeTokensSelector = createSelector(
if (baseToken) {
const updatedBaseToken = baseToken.set('balance', tokenBalance || { tokenBalance: '0', fiatBalance: '0' })
if (sameAddress(tokenAddress, ZERO_ADDRESS) || sameAddress(tokenAddress, ethAsToken?.address)) {
if (sameAddress(tokenAddress, ethAsToken?.address)) {
map.set(tokenAddress, updatedBaseToken.set('logoUri', ethAsToken?.logoUri || baseToken.logoUri))
} else {
map.set(tokenAddress, updatedBaseToken)