Fix useTxData refactor

Remove unnecessary useTxAmount
This commit is contained in:
Agustin Pane 2021-01-15 12:35:09 -03:00
parent 10f1891f8f
commit 4c45daa2e2
2 changed files with 7 additions and 66 deletions

View File

@ -37,6 +37,7 @@ import { TokenProps } from 'src/logic/tokens/store/model/token'
import { RecordOf } from 'immutable'
import { useEstimateTransactionGas } from 'src/logic/hooks/useEstimateTransactionGas'
import { TransactionFees } from 'src/components/TransactionsFees'
import BigNumber from 'bignumber.js'
const useStyles = makeStyles(styles)
const { nativeCoin } = getNetworkInfo()
@ -56,20 +57,6 @@ type ReviewTxProps = {
tx: ReviewTxProp
}
const useTxAmount = (tx: ReviewTxProp, isSendingNativeToken: boolean, txToken?: RecordOf<TokenProps>): string => {
const [txAmount, setTxAmount] = useState('0')
// txAmount should be 0 if we send tokens
// the real value is encoded in txData and will be used by the contract
// if txAmount > 0 it would send ETH from the Safe (and the data will be empty)
useEffect(() => {
const txAmount = isSendingNativeToken ? toTokenUnit(tx.amount, nativeCoin.decimals) : '0'
setTxAmount(txAmount)
}, [tx.amount, txToken, isSendingNativeToken])
return txAmount
}
const useTxData = (
isSendingNativeToken: boolean,
txAmount: string,
@ -88,7 +75,9 @@ const useTxData = (
if (!isSendingNativeToken) {
const StandardToken = await getHumanFriendlyToken()
const tokenInstance = await StandardToken.at(txToken.address as string)
txData = tokenInstance.contract.methods.transfer(recipientAddress, txAmount).encodeABI()
const decimals = await tokenInstance.decimals()
const erc20TransferAmount = new BigNumber(txAmount).times(10 ** decimals.toNumber()).toString()
txData = tokenInstance.contract.methods.transfer(recipientAddress, erc20TransferAmount).encodeABI()
}
setData(txData)
}
@ -107,9 +96,8 @@ const ReviewTx = ({ onClose, onPrev, tx }: ReviewTxProps): React.ReactElement =>
const txToken = useMemo(() => tokens.find((token) => sameAddress(token.address, tx.token)), [tokens, tx.token])
const isSendingNativeToken = sameAddress(txToken?.address, nativeCoin.address)
const txRecipient = isSendingNativeToken ? tx.recipientAddress : txToken?.address || ''
const txAmount = useTxAmount(tx, isSendingNativeToken, txToken)
const data = useTxData(isSendingNativeToken, txAmount, tx.recipientAddress, txToken)
const txValue = isSendingNativeToken ? toTokenUnit(tx.amount, nativeCoin.decimals) : '0'
const data = useTxData(isSendingNativeToken, tx.amount, tx.recipientAddress, txToken)
const {
gasCostFormatted,
@ -153,7 +141,7 @@ const ReviewTx = ({ onClose, onPrev, tx }: ReviewTxProps): React.ReactElement =>
createTransaction({
safeAddress: safeAddress,
to: txRecipient as string,
valueInWei: txAmount,
valueInWei: txValue,
txData: data,
notifiedTransaction: TX_NOTIFICATION_TYPES.STANDARD_TX,
}),

View File

@ -3558,18 +3558,6 @@
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/experimental-utils@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.12.0.tgz#372838e76db76c9a56959217b768a19f7129546b"
integrity sha512-MpXZXUAvHt99c9ScXijx7i061o5HEjXltO+sbYfZAAHxv3XankQkPaNi5myy0Yh0Tyea3Hdq1pi7Vsh0GJb0fA==
dependencies:
"@types/json-schema" "^7.0.3"
"@typescript-eslint/scope-manager" "4.12.0"
"@typescript-eslint/types" "4.12.0"
"@typescript-eslint/typescript-estree" "4.12.0"
eslint-scope "^5.0.0"
eslint-utils "^2.0.0"
"@typescript-eslint/experimental-utils@4.13.0", "@typescript-eslint/experimental-utils@^4.0.1":
version "4.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-4.13.0.tgz#9dc9ab375d65603b43d938a0786190a0c72be44e"
@ -3603,14 +3591,6 @@
"@typescript-eslint/typescript-estree" "4.13.0"
debug "^4.1.1"
"@typescript-eslint/scope-manager@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.12.0.tgz#beeb8beca895a07b10c593185a5612f1085ef279"
integrity sha512-QVf9oCSVLte/8jvOsxmgBdOaoe2J0wtEmBr13Yz0rkBNkl5D8bfnf6G4Vhox9qqMIoG7QQoVwd2eG9DM/ge4Qg==
dependencies:
"@typescript-eslint/types" "4.12.0"
"@typescript-eslint/visitor-keys" "4.12.0"
"@typescript-eslint/scope-manager@4.13.0":
version "4.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.13.0.tgz#5b45912a9aa26b29603d8fa28f5e09088b947141"
@ -3624,11 +3604,6 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.10.1.tgz#1d7463fa7c32d8a23ab508a803ca2fe26e758727"
integrity sha512-+3+FCUJIahE9q0lDi1WleYzjCwJs5hIsbugIgnbB+dSCYUxl8L6PwmsyOPFZde2hc1DlTo/xnkOgiTLSyAbHiQ==
"@typescript-eslint/types@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.12.0.tgz#fb891fe7ccc9ea8b2bbd2780e36da45d0dc055e5"
integrity sha512-N2RhGeheVLGtyy+CxRmxdsniB7sMSCfsnbh8K/+RUIXYYq3Ub5+sukRCjVE80QerrUBvuEvs4fDhz5AW/pcL6g==
"@typescript-eslint/types@4.13.0":
version "4.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.13.0.tgz#6a7c6015a59a08fbd70daa8c83dfff86250502f8"
@ -3648,20 +3623,6 @@
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/typescript-estree@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.12.0.tgz#3963418c850f564bdab3882ae23795d115d6d32e"
integrity sha512-gZkFcmmp/CnzqD2RKMich2/FjBTsYopjiwJCroxqHZIY11IIoN0l5lKqcgoAPKHt33H2mAkSfvzj8i44Jm7F4w==
dependencies:
"@typescript-eslint/types" "4.12.0"
"@typescript-eslint/visitor-keys" "4.12.0"
debug "^4.1.1"
globby "^11.0.1"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/typescript-estree@4.13.0":
version "4.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.13.0.tgz#cf6e2207c7d760f5dfd8d18051428fadfc37b45e"
@ -3683,14 +3644,6 @@
dependencies:
eslint-visitor-keys "^1.1.0"
"@typescript-eslint/visitor-keys@4.12.0":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.12.0.tgz#a470a79be6958075fa91c725371a83baf428a67a"
integrity sha512-hVpsLARbDh4B9TKYz5cLbcdMIOAoBYgFPCSP9FFS/liSF+b33gVNq8JHY3QGhHNVz85hObvL7BEYLlgx553WCw==
dependencies:
"@typescript-eslint/types" "4.12.0"
eslint-visitor-keys "^2.0.0"
"@typescript-eslint/visitor-keys@4.13.0":
version "4.13.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.13.0.tgz#9acb1772d3b3183182b6540d3734143dce9476fe"