@@ -3,125 +3,21 @@ import { StyleSheet, View } from 'react-native';
3
3
import { ButtonPressAnimation } from '../animations' ;
4
4
import FastTransactionStatusBadge from './FastTransactionStatusBadge' ;
5
5
import { Bleed , Box , Inline , Text , globalColors , useForegroundColor } from '@/design-system' ;
6
- import { AssetType , NativeCurrencyKey , RainbowTransaction , TransactionStatus , TransactionType } from '@/entities' ;
6
+ import { NativeCurrencyKey , RainbowTransaction , TransactionStatus , TransactionType } from '@/entities' ;
7
7
import { ThemeContextProps } from '@/theme' ;
8
8
import { useNavigation } from '@/navigation' ;
9
9
import Routes from '@rainbow-me/routes' ;
10
10
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 { checkForSwap } from '@/helpers/checkForPendingSwap' ;
27
18
import { ChainImage } from '../coin-icon/ChainImage' ;
28
19
import { useSuperTokenStore } from '@/screens/token-launcher/state/rainbowSuperTokenStore' ;
29
-
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 checkForPendingSend = ( transaction : RainbowTransaction ) => {
76
- return transaction . status === TransactionStatus . pending && transaction . type === 'send' ;
77
- } ;
78
-
79
- const pendingSendTypeValues = ( transaction : RainbowTransaction , nativeCurrency : NativeCurrencyKey ) => {
80
- if ( transaction . asset ?. type === AssetType . nft || transaction . amount == null || transaction . asset ?. price ?. value == null ) return ;
81
- return [
82
- `${ transaction . amount } ${ transaction . asset ?. symbol } ` ,
83
- `- ${ convertAmountAndPriceToNativeDisplay ( transaction . amount , transaction . asset ?. price ?. value , nativeCurrency ) ?. display } ` ,
84
- ] ;
85
- } ;
86
-
87
- export const useRainbowSuperToken = ( transaction : RainbowTransaction ) => {
88
- return useMemo ( ( ) => {
89
- if ( transaction ?. type === 'launch' ) {
90
- return useSuperTokenStore . getState ( ) . getSuperTokenByTransactionHash ( transaction . hash ) ;
91
- }
92
- return undefined ;
93
- } , [ transaction . hash , transaction . type ] ) ;
94
- } ;
95
-
96
- export const activityValues = ( transaction : RainbowTransaction , nativeCurrency : NativeCurrencyKey ) => {
97
- const { changes, direction, type, status } = transaction ;
98
- if ( checkForSwap ( transaction ) ) return swapTypeValues ( changes , status ) ;
99
- if ( checkForPendingSend ( transaction ) ) return pendingSendTypeValues ( transaction , nativeCurrency ) ;
100
- if ( [ 'approve' , 'revoke' ] . includes ( type ) ) return approvalTypeValues ( transaction ) ;
101
-
102
- const change = changes ?. filter ( c => c ?. direction === direction && c ?. asset . type !== 'nft' ) [ 0 ] ;
103
- let valueSymbol = direction === 'out' ? '-' : '+' ;
104
-
105
- if ( type === 'send' ) {
106
- valueSymbol = '-' ;
107
- }
108
- if ( type === 'receive' ) {
109
- valueSymbol = '+' ;
110
- }
111
-
112
- if ( ! change ?. asset ) return ;
113
-
114
- const { balance } = change . asset ;
115
-
116
- const assetValue = convertAmountToBalanceDisplay ( balance ?. amount || '0' , change . asset ) ;
117
-
118
- const nativeBalance = convertAmountAndPriceToNativeDisplay ( balance ?. amount || '0' , change . asset . price ?. value || '0' , nativeCurrency ) ;
119
- const assetNativeValue = greaterThan ( nativeBalance . amount , '0' )
120
- ? `${ valueSymbol } ${ nativeBalance ?. display } `
121
- : lang . t ( lang . l . transactions . no_value ) ;
122
-
123
- return greaterThan ( nativeBalance . amount , '0' ) ? [ `${ assetValue } ` , assetNativeValue ] : [ assetNativeValue , `${ valueSymbol } ${ assetValue } ` ] ;
124
- } ;
20
+ import { activityValues , useTransactionLaunchToken } from '@/helpers/transactions' ;
125
21
126
22
const getIconTopMargin = ( type : TransactionType ) => {
127
23
switch ( type ) {
@@ -201,7 +97,7 @@ const BottomRow = React.memo(function BottomRow({
201
97
nativeCurrency : NativeCurrencyKey ;
202
98
theme : ThemeContextProps ;
203
99
} ) {
204
- const rainbowSuperToken = useRainbowSuperToken ( transaction ) ;
100
+ const launchToken = useTransactionLaunchToken ( transaction ) ;
205
101
206
102
const { type, to, asset } = transaction ;
207
103
const separatorSecondary = useForegroundColor ( 'separatorSecondary' ) ;
@@ -213,8 +109,8 @@ const BottomRow = React.memo(function BottomRow({
213
109
tag = transaction . description ;
214
110
}
215
111
216
- if ( type === 'launch' && rainbowSuperToken ) {
217
- description = rainbowSuperToken ?. name ;
112
+ if ( type === 'launch' && launchToken ) {
113
+ description = launchToken ?. name ;
218
114
}
219
115
220
116
if ( transaction ?. type === 'mint' ) {
0 commit comments