Skip to content

Commit 71308f3

Browse files
authored
fix: correct pending send transaction amount display (#2170)
## What changed (plus any additional context for devs) - Fixed an issue in `ActivityValue.tsx` by refactoring how we handle transaction changes: - Renamed `changeAsset` to `changeWithAsset` to better reflect that we're storing the entire change object, not just the asset - Updated the logic to access the asset property from the change object - Enhanced transaction building in the Send page: - Added proper raw amount conversion for asset transactions - Improved how assets are handled in pending transactions by using `parseUserAssetBalances` - Ensured consistent asset formatting in transaction changes ## What to test - Send tokens and verify the transaction appears correctly in activity - Check that transaction values display properly in the activity list - Verify that NFT transactions show the correct asset information - Test sending various token amounts and confirm the raw amounts are calculated correctly - Ensure transaction direction is properly displayed in the activity feed <!-- start pr-codex --> --- ## PR-Codex overview This PR updates the version numbers in `manifest.json` and `package.json` to `1.5.179`. It also refines the logic in `ActivityValue.tsx` for handling asset changes and introduces new utility functions in `index.tsx` for converting amounts and parsing user asset balances in transaction handling. ### Detailed summary - Updated version in `manifest.json` from `1.5.178` to `1.5.179`. - Updated version in `package.json` from `1.5.178` to `1.5.179`. - Renamed variable `changeAsset` to `changeWithAsset` in `ActivityValue.tsx`. - Improved logic for determining asset changes in `ActivityValue.tsx`. - Added `convertAmountToRawAmount` and `parseUserAssetBalances` imports in `index.tsx`. - Modified `buildPendingTransaction` function to use `rawAmount` and `changeAsset`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 723f50d commit 71308f3

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "browser-extension",
33
"license": "GPL-3.0-only",
4-
"version": "1.5.178",
4+
"version": "1.5.179",
55
"scripts": {
66
"//enable dev mode": "",
77
"devmode:on": "sed -i'' -e 's/IS_DEV.*/IS_DEV=true/g' .env",

src/entries/popup/pages/home/Activity/ActivityValue.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ const activityValues = (transaction: RainbowTransaction) => {
108108
return approvalTypeValues(transaction);
109109

110110
const nonNftChanges = changes?.filter((c) => c?.asset.type !== 'nft') ?? [];
111-
const changeAsset =
111+
const changeWithAsset =
112112
!direction && nonNftChanges.length === 1 // if there's no direction and only one change
113-
? nonNftChanges[0]?.asset // use the first change
114-
: nonNftChanges.find((c) => c?.direction === direction)?.asset; // else: use the change with the direction
113+
? nonNftChanges[0] // use the first change
114+
: nonNftChanges.find((c) => c?.direction === direction); // else: use the change with the direction
115115

116-
const asset = changeAsset ?? _asset;
116+
const asset = changeWithAsset?.asset ?? _asset;
117117

118118
if (!asset || !isParsedUserAsset(asset) || asset.type === 'nft') return;
119119

src/entries/popup/pages/send/index.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ import {
4141
} from '~/core/types/gas';
4242
import { UniqueAsset } from '~/core/types/nfts';
4343
import { NewTransaction, TxHash } from '~/core/types/transactions';
44+
import { parseUserAssetBalances } from '~/core/utils/assets';
4445
import { chainIdToUse } from '~/core/utils/chains';
4546
import {
4647
getUniqueAssetImagePreviewURL,
4748
getUniqueAssetImageThumbnailURL,
4849
} from '~/core/utils/nfts';
50+
import { convertAmountToRawAmount } from '~/core/utils/numbers';
4951
import { addNewTransaction } from '~/core/utils/transactions';
5052
import {
5153
Box,
@@ -298,17 +300,32 @@ export function Send() {
298300

299301
const buildPendingTransaction = useCallback(
300302
(result: TransactionResponse) => {
303+
const rawAmount =
304+
asset && assetAmount
305+
? convertAmountToRawAmount(assetAmount, asset.decimals || 18)
306+
: '0';
307+
308+
const changeAsset = nft
309+
? buildNftAssetObject(nft)
310+
: asset && assetAmount
311+
? parseUserAssetBalances({
312+
asset,
313+
balance: rawAmount,
314+
currency: currentCurrency,
315+
})
316+
: asset;
317+
301318
return {
302319
changes: [
303320
nft
304321
? { direction: 'out', asset: buildNftAssetObject(nft) }
305322
: {
306323
direction: 'out',
307-
asset,
308-
value: assetAmount,
324+
asset: changeAsset,
325+
value: rawAmount,
309326
},
310327
],
311-
asset: nft ? buildNftAssetObject(nft) : asset,
328+
asset: changeAsset,
312329
data: result.data,
313330
value: result.value.toString(),
314331
from: fromAddress,
@@ -333,6 +350,7 @@ export function Send() {
333350
asset,
334351
assetAmount,
335352
buildNftAssetObject,
353+
currentCurrency,
336354
fromAddress,
337355
nft,
338356
selectedGas.transactionGasParams,

static/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"notifications"
6969
],
7070
"short_name": "Rainbow",
71-
"version": "1.5.178",
71+
"version": "1.5.179",
7272
"web_accessible_resources": [
7373
{
7474
"matches": [

0 commit comments

Comments
 (0)