Skip to content

Commit

Permalink
fix: invalid transaction data used for approve transaction (#6833) (#…
Browse files Browse the repository at this point in the history
…6914)

* use valid txn data when approving txn

* rename variable

Co-authored-by: Sylva Elendu <iamsylvaelendu@gmail.com>
  • Loading branch information
sethkfman and blackdevelopa authored Jul 26, 2023
1 parent a8c98ca commit 7909a6f
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions app/components/UI/ApproveTransactionReview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,9 @@ class ApproveTransactionReview extends PureComponent {
tokenBalance,
createdSpendCap;

const { spenderAddress, encodedAmount } = decodeApproveData(data);
const encodedValue = hexToBN(encodedAmount).toString();
const { spenderAddress, encodedAmount: encodedHexAmount } =
decodeApproveData(data);
const encodedDecimalAmount = hexToBN(encodedHexAmount).toString();

const erc20TokenBalance = await TokenBalancesController.getERC20BalanceOf(
to,
Expand All @@ -375,7 +376,7 @@ class ApproveTransactionReview extends PureComponent {
createdSpendCap = isReadyToApprove;
} else if (!contract) {
try {
const result = await getTokenDetails(to, from, encodedValue);
const result = await getTokenDetails(to, from, encodedDecimalAmount);

const { standard, name, decimals, symbol } = result;

Expand Down Expand Up @@ -406,7 +407,7 @@ class ApproveTransactionReview extends PureComponent {
}

const approveAmount = fromTokenMinimalUnit(
hexToBN(encodedAmount),
hexToBN(encodedHexAmount),
tokenDecimals,
);

Expand All @@ -417,7 +418,7 @@ class ApproveTransactionReview extends PureComponent {
spender: spenderAddress,
value:
tokenStandard === ERC721 || tokenStandard === ERC1155
? encodedValue
? encodedHexAmount
: '0',
});

Expand All @@ -441,13 +442,13 @@ class ApproveTransactionReview extends PureComponent {
tokenSymbol,
tokenDecimals,
tokenName,
tokenValue: encodedValue,
tokenValue: encodedDecimalAmount,
tokenStandard,
tokenBalance,
tokenImage: token[0]?.iconUrl,
},
spenderAddress,
encodedAmount,
encodedHexAmount,
fetchingUpdateDone: true,
isReadyToApprove: createdSpendCap,
tokenSpendValue: tokenAllowanceState
Expand Down Expand Up @@ -507,14 +508,14 @@ class ApproveTransactionReview extends PureComponent {
const {
token: { tokenSymbol },
originalApproveAmount,
encodedAmount,
encodedHexAmount,
} = this.state;
const { NetworkController } = Engine.context;
const { chainId } = NetworkController?.state?.providerConfig || {};
const isDapp = !Object.values(AppConstants.DEEPLINKS).includes(
transaction?.origin,
);
const unlimited = encodedAmount === UINT256_HEX_MAX_VALUE;
const unlimited = encodedHexAmount === UINT256_HEX_MAX_VALUE;
const params = {
account_type: getAddressAccountType(transaction?.from),
dapp_host_name: transaction?.origin,
Expand Down

0 comments on commit 7909a6f

Please sign in to comment.