Add support for collectibles
This commit is contained in:
parent
4aabdc7140
commit
a3541d8a33
|
@ -1,6 +1,11 @@
|
||||||
|
import memoize from 'lodash.memoize'
|
||||||
import logo from 'src/assets/icons/icon_etherTokens.svg'
|
import logo from 'src/assets/icons/icon_etherTokens.svg'
|
||||||
import generateBatchRequests from 'src/logic/contracts/generateBatchRequests'
|
import generateBatchRequests from 'src/logic/contracts/generateBatchRequests'
|
||||||
import { getStandardTokenContract, getTokenInfos } from 'src/logic/tokens/store/actions/fetchTokens'
|
import {
|
||||||
|
getStandardTokenContract,
|
||||||
|
getTokenInfos,
|
||||||
|
getERC721TokenContract,
|
||||||
|
} from 'src/logic/tokens/store/actions/fetchTokens'
|
||||||
import { makeToken, Token } from 'src/logic/tokens/store/model/token'
|
import { makeToken, Token } from 'src/logic/tokens/store/model/token'
|
||||||
import { ALTERNATIVE_TOKEN_ABI } from 'src/logic/tokens/utils/alternativeAbi'
|
import { ALTERNATIVE_TOKEN_ABI } from 'src/logic/tokens/utils/alternativeAbi'
|
||||||
import { web3ReadOnly as web3 } from 'src/logic/wallets/getWeb3'
|
import { web3ReadOnly as web3 } from 'src/logic/wallets/getWeb3'
|
||||||
|
@ -46,6 +51,12 @@ export const isSendERC721Transaction = (tx: any, txCode: string, knownTokens: an
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getERC21Symbol = memoize(async (contractAddress) => {
|
||||||
|
const ERC21token = await getERC721TokenContract()
|
||||||
|
const tokenInstance = await ERC21token.at(contractAddress)
|
||||||
|
return tokenInstance.symbol()
|
||||||
|
})
|
||||||
|
|
||||||
export const getERC20DecimalsAndSymbol = async (
|
export const getERC20DecimalsAndSymbol = async (
|
||||||
tokenAddress: string,
|
tokenAddress: string,
|
||||||
): Promise<{ decimals: number; symbol: string }> => {
|
): Promise<{ decimals: number; symbol: string }> => {
|
||||||
|
|
|
@ -64,7 +64,7 @@ const ReviewCollectible = ({ closeSnackbar, enqueueSnackbar, onClose, onPrev, tx
|
||||||
|
|
||||||
const ERC721Token = methodToCall === 'transfer' ? await getHumanFriendlyToken() : await getERC721TokenContract()
|
const ERC721Token = methodToCall === 'transfer' ? await getHumanFriendlyToken() : await getERC721TokenContract()
|
||||||
const tokenInstance = await ERC721Token.at(tx.assetAddress)
|
const tokenInstance = await ERC721Token.at(tx.assetAddress)
|
||||||
const txData = tokenInstance.contract.methods[methodToCall](...params).encodeABI()
|
const txData = tokenInstance.contract.methods[`0x${methodToCall}`](...params).encodeABI()
|
||||||
|
|
||||||
const estimatedGasCosts = await estimateTxGasCosts(safeAddress, tx.recipientAddress, txData)
|
const estimatedGasCosts = await estimateTxGasCosts(safeAddress, tx.recipientAddress, txData)
|
||||||
const gasCostsAsEth = fromWei(toBN(estimatedGasCosts), 'ether')
|
const gasCostsAsEth = fromWei(toBN(estimatedGasCosts), 'ether')
|
||||||
|
|
|
@ -45,6 +45,10 @@ export const getTxAmount = (tx, formatted = true) => {
|
||||||
const { decimals = 18, decodedParams, isTokenTransfer, symbol } = tx
|
const { decimals = 18, decodedParams, isTokenTransfer, symbol } = tx
|
||||||
const { value } = isTokenTransfer && !!decodedParams && !!decodedParams.transfer ? decodedParams.transfer : tx
|
const { value } = isTokenTransfer && !!decodedParams && !!decodedParams.transfer ? decodedParams.transfer : tx
|
||||||
|
|
||||||
|
if (tx.isCollectibleTransfer) {
|
||||||
|
return `1 ${tx.symbol}`
|
||||||
|
}
|
||||||
|
|
||||||
if (!isTokenTransfer && !(Number(value) > 0)) {
|
if (!isTokenTransfer && !(Number(value) > 0)) {
|
||||||
return NOT_AVAILABLE
|
return NOT_AVAILABLE
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { DecodedMethods, decodeMethods } from 'src/logic/contracts/methodIds'
|
||||||
import { TOKEN_REDUCER_ID } from 'src/logic/tokens/store/reducer/tokens'
|
import { TOKEN_REDUCER_ID } from 'src/logic/tokens/store/reducer/tokens'
|
||||||
import {
|
import {
|
||||||
getERC20DecimalsAndSymbol,
|
getERC20DecimalsAndSymbol,
|
||||||
|
getERC21Symbol,
|
||||||
isSendERC20Transaction,
|
isSendERC20Transaction,
|
||||||
isSendERC721Transaction,
|
isSendERC721Transaction,
|
||||||
} from 'src/logic/tokens/utils/tokenHelpers'
|
} from 'src/logic/tokens/utils/tokenHelpers'
|
||||||
|
@ -266,7 +267,7 @@ export const buildTx = async ({
|
||||||
safeTxGas: tx.safeTxGas,
|
safeTxGas: tx.safeTxGas,
|
||||||
safeTxHash: tx.safeTxHash,
|
safeTxHash: tx.safeTxHash,
|
||||||
submissionDate: tx.submissionDate,
|
submissionDate: tx.submissionDate,
|
||||||
symbol,
|
symbol: isSendERC721Tx ? await getERC21Symbol(tx.to) : symbol,
|
||||||
upgradeTx: isUpgradeTx,
|
upgradeTx: isUpgradeTx,
|
||||||
value: tx.value.toString(),
|
value: tx.value.toString(),
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue