@@ -11,95 +11,14 @@ import { ImgixImage } from '../images';
11
11
import { CardSize } from '../unique-token/CardSize' ;
12
12
import { ChainId } from '@/state/backendNetworks/types' ;
13
13
import { address } from '@/utils/abbreviations' ;
14
- import {
15
- convertAmountAndPriceToNativeDisplay ,
16
- convertAmountToBalanceDisplay ,
17
- convertRawAmountToBalance ,
18
- convertRawAmountToDecimalFormat ,
19
- greaterThan ,
20
- handleSignificantDecimals ,
21
- } from '@/helpers/utilities' ;
22
14
import { TwoCoinsIcon } from '../coin-icon/TwoCoinsIcon' ;
23
15
import Spinner from '../Spinner' ;
24
- import * as lang from '@/languages' ;
16
+
25
17
import RainbowCoinIcon from '@/components/coin-icon/RainbowCoinIcon' ;
26
- import { checkForPendingSwap } from '@/helpers/checkForPendingSwap' ;
27
18
import { ChainImage } from '../coin-icon/ChainImage' ;
28
19
import { useSuperTokenStore } from '@/screens/token-launcher/state/rainbowSuperTokenStore' ;
20
+ import { activityValues , useTransactionLaunchToken } from '@/helpers/transactions' ;
29
21
30
- export const getApprovalLabel = ( { approvalAmount, asset, type } : Pick < RainbowTransaction , 'type' | 'asset' | 'approvalAmount' > ) => {
31
- if ( ! approvalAmount || ! asset ) return ;
32
- if ( approvalAmount === 'UNLIMITED' ) return lang . t ( lang . l . transactions . approvals . unlimited ) ;
33
- if ( type === 'revoke' ) return lang . t ( lang . l . transactions . approvals . no_allowance ) ;
34
- const amountDisplay = convertRawAmountToBalance (
35
- approvalAmount ,
36
- { decimals : asset ?. decimals , symbol : asset ?. symbol } ,
37
- undefined ,
38
- true
39
- ) ?. display ;
40
- return amountDisplay || '' ;
41
- } ;
42
-
43
- const approvalTypeValues = ( transaction : RainbowTransaction ) => {
44
- const { asset, approvalAmount } = transaction ;
45
-
46
- if ( ! asset || ! approvalAmount ) return ;
47
- transaction . protocol ;
48
- return [ transaction . protocol || '' , getApprovalLabel ( transaction ) ] ;
49
- } ;
50
-
51
- const swapTypeValues = ( changes : RainbowTransaction [ 'changes' ] , status : RainbowTransaction [ 'status' ] ) => {
52
- const tokenIn = changes ?. filter ( c => c ?. direction === 'in' ) [ 0 ] ;
53
- const tokenOut = changes ?. filter ( c => c ?. direction === 'out' ) [ 0 ] ;
54
-
55
- // NOTE: For pending txns let's use the change values instead of
56
- // the transaction balance change since that hasn't happened yet
57
- if ( status === TransactionStatus . pending ) {
58
- const decimalsOut = typeof tokenOut ?. asset . decimals === 'number' ? tokenOut . asset . decimals : 18 ;
59
- const decimalsIn = typeof tokenIn ?. asset . decimals === 'number' ? tokenIn . asset . decimals : 18 ;
60
-
61
- const valueOut = `${ handleSignificantDecimals ( convertRawAmountToDecimalFormat ( tokenOut ?. value ?. toString ( ) || '0' , decimalsOut ) , decimalsOut ) } ${ tokenOut ?. asset . symbol } ` ;
62
- const valueIn = `+${ handleSignificantDecimals ( convertRawAmountToDecimalFormat ( tokenIn ?. value ?. toString ( ) || '0' , decimalsIn ) , decimalsIn ) } ${ tokenIn ?. asset . symbol } ` ;
63
-
64
- return [ valueOut , valueIn ] ;
65
- }
66
-
67
- if ( ! tokenIn ?. asset . balance ?. amount || ! tokenOut ?. asset . balance ?. amount ) return ;
68
-
69
- const valueOut = `${ convertAmountToBalanceDisplay ( tokenOut ?. asset . balance ?. amount , { ...tokenOut ?. asset } ) } ` ;
70
- const valueIn = `+${ convertAmountToBalanceDisplay ( tokenIn ?. asset . balance ?. amount , { ...tokenIn ?. asset } ) } ` ;
71
-
72
- return [ valueOut , valueIn ] ;
73
- } ;
74
-
75
- const activityValues = ( transaction : RainbowTransaction , nativeCurrency : NativeCurrencyKey ) => {
76
- const { changes, direction, type, status } = transaction ;
77
- if ( checkForPendingSwap ( transaction ) ) return swapTypeValues ( changes , status ) ;
78
- if ( [ 'approve' , 'revoke' ] . includes ( type ) ) return approvalTypeValues ( transaction as RainbowTransaction ) ;
79
-
80
- const change = changes ?. filter ( c => c ?. direction === direction && c ?. asset . type !== 'nft' ) [ 0 ] ;
81
- let valueSymbol = direction === 'out' ? '-' : '+' ;
82
-
83
- if ( type === 'send' ) {
84
- valueSymbol = '-' ;
85
- }
86
- if ( type === 'receive' ) {
87
- valueSymbol = '+' ;
88
- }
89
-
90
- if ( ! change ?. asset ) return ;
91
-
92
- const { balance } = change . asset ;
93
-
94
- const assetValue = convertAmountToBalanceDisplay ( balance ?. amount || '0' , change . asset ) ;
95
-
96
- const nativeBalance = convertAmountAndPriceToNativeDisplay ( balance ?. amount || '0' , change . asset . price ?. value || '0' , nativeCurrency ) ;
97
- const assetNativeValue = greaterThan ( nativeBalance . amount , '0' )
98
- ? `${ valueSymbol } ${ nativeBalance ?. display } `
99
- : lang . t ( lang . l . transactions . no_value ) ;
100
-
101
- return greaterThan ( nativeBalance . amount , '0' ) ? [ `${ assetValue } ` , assetNativeValue ] : [ assetNativeValue , `${ valueSymbol } ${ assetValue } ` ] ;
102
- } ;
103
22
const getIconTopMargin = ( type : TransactionType ) => {
104
23
switch ( type ) {
105
24
case 'swap' :
@@ -137,6 +56,7 @@ const activityTypeIcon: Record<TransactionType, string> = {
137
56
claim : '' ,
138
57
borrow : '' ,
139
58
deployment : '' ,
59
+ launch : '' ,
140
60
} ;
141
61
142
62
export const ActivityTypeIcon = ( {
@@ -177,12 +97,7 @@ const BottomRow = React.memo(function BottomRow({
177
97
nativeCurrency : NativeCurrencyKey ;
178
98
theme : ThemeContextProps ;
179
99
} ) {
180
- const rainbowSuperToken = useMemo ( ( ) => {
181
- if ( transaction ?. type === 'launch' ) {
182
- return useSuperTokenStore . getState ( ) . getSuperTokenByTransactionHash ( transaction . hash ) ;
183
- }
184
- return undefined ;
185
- } , [ transaction . hash , transaction . type ] ) ;
100
+ const launchToken = useTransactionLaunchToken ( transaction ) ;
186
101
187
102
const { type, to, asset } = transaction ;
188
103
const separatorSecondary = useForegroundColor ( 'separatorSecondary' ) ;
@@ -194,8 +109,8 @@ const BottomRow = React.memo(function BottomRow({
194
109
tag = transaction . description ;
195
110
}
196
111
197
- if ( type === 'launch' && rainbowSuperToken ) {
198
- description = rainbowSuperToken ?. name ;
112
+ if ( type === 'launch' && launchToken ) {
113
+ description = launchToken ?. name ;
199
114
}
200
115
201
116
if ( transaction ?. type === 'mint' ) {
0 commit comments