1
- import { Pressable } from 'react-native' ;
1
+ import { useState } from 'react' ;
2
+ import { Pressable } from 'react-native-gesture-handler' ;
3
+ import Animated from 'react-native-reanimated' ;
2
4
import { useSelector } from 'react-redux' ;
3
5
4
- import { invariant } from '@suite-common/suite-utils' ;
6
+ import { useNavigation } from '@react-navigation/native' ;
7
+ import { DexApprovalType } from 'invity-api' ;
8
+
5
9
import {
6
10
TradingRootState ,
7
11
cryptoIdToNetworkAndContractAddress ,
8
12
selectTradingCoinSymbolByCryptoId ,
9
- selectTradingExchangeSelectedQuote ,
10
13
selectTradingProviderByNameAndTradeType ,
11
14
} from '@suite-common/trading' ;
12
15
import { asBaseCurrencyAmount } from '@suite-common/wallet-utils' ;
13
16
import { Box , Button , Card , HStack , InlineAlertBox , Text , VStack } from '@suite-native/atoms' ;
14
17
import { BaseCurrencyAmountFormatter } from '@suite-native/formatters' ;
15
18
import { CryptoIcon , Icon , NetworkIcon } from '@suite-native/icons' ;
16
19
import { Translation } from '@suite-native/intl' ;
17
- import { DynamicScreenHeader , Screen } from '@suite-native/navigation' ;
20
+ import {
21
+ DynamicScreenHeader ,
22
+ RootStackParamList ,
23
+ Screen ,
24
+ StackNavigationProps ,
25
+ StackToStackCompositeScreenProps ,
26
+ TradingStackParamList ,
27
+ TradingStackRoutes ,
28
+ } from '@suite-native/navigation' ;
18
29
import { BigNumber } from '@trezor/utils' ;
19
30
20
31
import { TradeInfoHeader } from '../components/TradeInfo/TradeInfoHeader' ;
21
32
import { TradeInfoRow } from '../components/TradeInfo/TradeInfoRow' ;
22
33
import { ExchangeApprovalLimitSheet } from '../components/exchange/ExchangeApprovalLimitSheet/ExchangeApprovalLimitSheet' ;
23
34
import { ProviderLogo } from '../components/general/ProviderLogo' ;
35
+ import { useExchangeFlow } from '../hooks/exchange/useExchangeFlow' ;
24
36
import { useBottomSheetControls } from '../hooks/general/useBottomSheetControls' ;
25
37
import { selectExchangeSelectedSendAccount } from '../selectors/exchangeSelectors' ;
26
38
27
- export const TradingExchangeApprovalScreen = ( ) => {
28
- const quote = useSelector ( selectTradingExchangeSelectedQuote ) ;
39
+ type TradingExchangeApprovalScreenProps = StackToStackCompositeScreenProps <
40
+ TradingStackParamList ,
41
+ TradingStackRoutes . TradingExchangeApproval ,
42
+ RootStackParamList
43
+ > ;
29
44
30
- invariant ( quote , 'quote must be defined' ) ;
45
+ export const TradingExchangeApprovalScreen = ( {
46
+ route : { params } ,
47
+ } : TradingExchangeApprovalScreenProps ) => {
48
+ const { quote, shouldIncreaseLimit, isRevoked } = params ;
49
+ const navigation =
50
+ useNavigation <
51
+ StackNavigationProps < TradingStackParamList , TradingStackRoutes . TradingExchangeApproval >
52
+ > ( ) ;
31
53
32
54
const account = useSelector ( selectExchangeSelectedSendAccount ) ;
55
+ const [ selectedApprovalType , setSelectedApprovalType ] = useState < DexApprovalType > ( 'INFINITE' ) ;
33
56
34
57
const { network, contractAddress } = quote . send
35
58
? cryptoIdToNetworkAndContractAddress ( quote . send )
@@ -45,8 +68,36 @@ export const TradingExchangeApprovalScreen = () => {
45
68
selectTradingCoinSymbolByCryptoId ( state , quote ?. send ) ,
46
69
) ;
47
70
71
+ const { confirmTrade, fetchFeesAndCompose } = useExchangeFlow ( ) ;
72
+
48
73
const fee = '4.76' ; // TODO
49
74
75
+ const handleContinue = async ( ) => {
76
+ const updatedQuote = {
77
+ ...quote ,
78
+ approvalType : selectedApprovalType ,
79
+ } ;
80
+
81
+ const success = await confirmTrade ( {
82
+ receiveAddress : quote . receiveAddress ?? '' ,
83
+ trade : updatedQuote ,
84
+ approvalFlow : true ,
85
+ nextStep : ( ) => { } ,
86
+ } ) ;
87
+
88
+ if ( success ) {
89
+ // TODO
90
+ await fetchFeesAndCompose ( ) ;
91
+
92
+ navigation . navigate ( TradingStackRoutes . TradingExchangePreview , { isApproved : true } ) ;
93
+ }
94
+ } ;
95
+
96
+ const handleApprovalTypeChange = ( newType : DexApprovalType ) => {
97
+ setSelectedApprovalType ( newType ) ;
98
+ hideSheet ( ) ;
99
+ } ;
100
+
50
101
return (
51
102
< Screen
52
103
header = {
@@ -63,23 +114,32 @@ export const TradingExchangeApprovalScreen = () => {
63
114
values = { { symbol : coinSymbol } }
64
115
/>
65
116
}
66
- closeActionType = "close "
117
+ closeActionType = "back "
67
118
/>
68
119
}
69
120
>
70
121
< VStack spacing = "sp16" >
71
- < InlineAlertBox
72
- title = {
73
- < Translation id = "moduleTrading.tradingExchangeApprovalScreen.revokeSuccessAlert" />
74
- }
75
- variant = "success"
76
- />
77
- < InlineAlertBox
78
- title = {
79
- < Translation id = "moduleTrading.tradingExchangeApprovalScreen.lowLimitInfoAlert" />
80
- }
81
- variant = "info"
82
- />
122
+ { ! ! shouldIncreaseLimit && (
123
+ < Animated . View >
124
+ < InlineAlertBox
125
+ title = {
126
+ < Translation id = "moduleTrading.tradingExchangeApprovalScreen.lowLimitInfoAlert" />
127
+ }
128
+ variant = "warning"
129
+ />
130
+ </ Animated . View >
131
+ ) }
132
+
133
+ { ! ! isRevoked && (
134
+ < Animated . View >
135
+ < InlineAlertBox
136
+ variant = "success"
137
+ title = {
138
+ < Translation id = "moduleTrading.tradingExchangeApprovalScreen.revokeSuccessAlert" />
139
+ }
140
+ />
141
+ </ Animated . View >
142
+ ) }
83
143
84
144
< Card noPadding >
85
145
< TradeInfoHeader
@@ -140,7 +200,11 @@ export const TradingExchangeApprovalScreen = () => {
140
200
/>
141
201
) }
142
202
< Text variant = "hint" color = "textSubdued" >
143
- < Translation id = "moduleTrading.tradingExchangeApprovalScreen.unlimitedLabel" />
203
+ { selectedApprovalType === 'INFINITE' ? (
204
+ < Translation id = "moduleTrading.tradingExchangeApprovalScreen.unlimitedLabel" />
205
+ ) : (
206
+ `${ quote . sendStringAmount } ${ coinSymbol } `
207
+ ) }
144
208
</ Text >
145
209
< Icon name = "caretDown" size = "medium" />
146
210
</ HStack >
@@ -177,15 +241,17 @@ export const TradingExchangeApprovalScreen = () => {
177
241
</ VStack >
178
242
179
243
< Box paddingTop = "sp20" >
180
- < Button
181
- onPress = { ( ) => {
182
- // TODO
183
- } }
184
- >
244
+ < Button onPress = { handleContinue } >
185
245
< Translation id = "generic.buttons.continue" />
186
246
</ Button >
187
247
</ Box >
188
- < ExchangeApprovalLimitSheet isVisible = { isSheetVisible } onDismiss = { hideSheet } />
248
+ < ExchangeApprovalLimitSheet
249
+ isVisible = { isSheetVisible }
250
+ onDismiss = { hideSheet }
251
+ onApprovalTypeSelect = { handleApprovalTypeChange }
252
+ selectedApprovalType = { selectedApprovalType }
253
+ quote = { quote }
254
+ />
189
255
</ Screen >
190
256
) ;
191
257
} ;
0 commit comments