1
1
import { useTheme } from '@yoroi/theme'
2
+ import { Swap } from '@yoroi/types'
2
3
import * as React from 'react'
3
4
import { StyleSheet , Text , View } from 'react-native'
4
5
@@ -18,9 +19,16 @@ export const EstimateSummary = () => {
18
19
const { wallet} = useSelectedWallet ( )
19
20
const navigateTo = useNavigateTo ( )
20
21
const swapForm = useSwap ( )
22
+ const { openModal} = useModal ( )
21
23
22
24
const protocol = swapForm . estimate ?. splits [ 0 ] ?. protocol
23
- const originSelection = `${ swapForm . selectedProtocol . isTouched ? '' : ` ${ strings . autoPool } ` } `
25
+
26
+ const expand = ( ) =>
27
+ openModal ( {
28
+ title : strings . route ,
29
+ height : 400 ,
30
+ content : < Splits data = { swapForm . estimate ?. splits ?? [ ] } /> ,
31
+ } )
24
32
25
33
return (
26
34
< View >
@@ -34,14 +42,33 @@ export const EstimateSummary = () => {
34
42
35
43
{ swapForm . estimate !== undefined && (
36
44
< View style = { styles . list } >
37
- < View style = { styles . composedText } >
38
- { protocol !== undefined && < ProtocolAvatar protocol = { protocol } append = { originSelection } preventOpenLink /> }
39
- </ View >
45
+ < Row
46
+ label = { strings . route }
47
+ description = { strings . routeDescription }
48
+ value = {
49
+ protocol !== undefined && (
50
+ < View style = { styles . composedText } >
51
+ < ProtocolAvatar protocol = { protocol } preventOpenLink />
52
+
53
+ { swapForm . estimate ?. splits . length > 1 && (
54
+ < Button
55
+ type = { ButtonType . SecondaryText }
56
+ title = "…"
57
+ rightIcon
58
+ icon = { Icon . Chevron }
59
+ style = { styles . reducedPadding }
60
+ onPress = { expand }
61
+ />
62
+ ) }
63
+ </ View >
64
+ )
65
+ }
66
+ />
40
67
41
68
< Row
42
- label = { strings . swapMinAdaTitle }
43
- description = { strings . swapMinAda }
44
- value = { `${ swapForm . estimate ?. deposits } ${ wallet . portfolioPrimaryTokenInfo . ticker } ` }
69
+ label = { strings . price }
70
+ description = { swapForm . orderType === 'limit' ? strings . limitPriceInfo : strings . marketPriceInfo }
71
+ value = { `${ swapForm . estimate ?. netPrice } ${ wallet . portfolioPrimaryTokenInfo . ticker } ` }
45
72
/>
46
73
47
74
< Row
@@ -57,6 +84,12 @@ export const EstimateSummary = () => {
57
84
swapForm . tokenInfos . get ( swapForm . tokenOutInput . tokenId ?? undefinedToken ) ?. ticker
58
85
} `}
59
86
/>
87
+
88
+ < Row
89
+ label = { strings . slippageTolerance }
90
+ description = { strings . slippageToleranceInfo }
91
+ value = { `${ swapForm . slippageInput . value } %` }
92
+ />
60
93
</ View >
61
94
) }
62
95
</ View >
@@ -82,10 +115,11 @@ const Row = ({
82
115
83
116
{ description !== undefined && (
84
117
< Button
85
- style = { styles . info }
118
+ style = { styles . reducedPadding }
86
119
onPress = { ( ) => openModal ( { title : label , content : < Text style = { styles . textContent } > { description } </ Text > } ) }
87
120
type = { ButtonType . SecondaryText }
88
121
icon = { Icon . Info }
122
+ size = "S"
89
123
/>
90
124
) }
91
125
</ View >
@@ -95,6 +129,26 @@ const Row = ({
95
129
)
96
130
}
97
131
132
+ export const Splits = ( { data} : { data : Swap . Split [ ] } ) => {
133
+ const { styles} = useStyles ( )
134
+
135
+ const total = data . reduce ( ( acc , curr ) => ( acc += curr . expectedOutputWithoutSlippage ) , 0 )
136
+
137
+ return (
138
+ < View style = { styles . splitList } >
139
+ { data . map ( ( split , index ) => (
140
+ < View key = { index } style = { [ styles . composedText , styles . between ] } >
141
+ < ProtocolAvatar protocol = { split . protocol } preventOpenLink />
142
+
143
+ < Text style = { styles . textContent } >
144
+ { ( ( 100 * ( split . expectedOutputWithoutSlippage ?? 0 ) ) / total ) . toFixed ( 2 ) } %
145
+ </ Text >
146
+ </ View >
147
+ ) ) }
148
+ </ View >
149
+ )
150
+ }
151
+
98
152
const useStyles = ( ) => {
99
153
const { color, atoms} = useTheme ( )
100
154
const styles = StyleSheet . create ( {
@@ -107,7 +161,11 @@ const useStyles = () => {
107
161
} ,
108
162
list : {
109
163
...atoms . pt_md ,
110
- ...atoms . gap_2xs ,
164
+ ...atoms . gap_md ,
165
+ } ,
166
+ splitList : {
167
+ ...atoms . gap_sm ,
168
+ ...atoms . p_lg ,
111
169
} ,
112
170
row : {
113
171
...atoms . flex_row ,
@@ -132,8 +190,11 @@ const useStyles = () => {
132
190
...atoms . body_1_lg_regular ,
133
191
...atoms . px_lg ,
134
192
} ,
135
- info : {
136
- ...atoms . p_0 ,
193
+ reducedPadding : {
194
+ ...atoms . pl_2xs ,
195
+ ...atoms . pr_2xs ,
196
+ ...atoms . pt_2xs ,
197
+ ...atoms . pb_2xs ,
137
198
} ,
138
199
} )
139
200
0 commit comments