1
1
import {
2
2
CHAIN_ID_ACALA ,
3
3
CHAIN_ID_KARURA ,
4
+ CHAIN_ID_NEON ,
4
5
CHAIN_ID_TERRA ,
5
6
hexToNativeAssetString ,
6
7
isEVMChain ,
@@ -32,6 +33,7 @@ import {
32
33
} from "../store/selectors" ;
33
34
import { setRelayerFee , setUseRelayer } from "../store/transferSlice" ;
34
35
import { CHAINS_BY_ID , getDefaultNativeCurrencySymbol } from "../utils/consts" ;
36
+ import { useNeonRelayerInfo } from "../hooks/useNeonRelayerInfo" ;
35
37
36
38
const useStyles = makeStyles ( ( theme ) => ( {
37
39
feeSelectorContainer : {
@@ -107,6 +109,11 @@ function FeeMethodSelector() {
107
109
vaaNormalizedAmount ,
108
110
originChain ? hexToNativeAssetString ( originAsset , originChain ) : undefined
109
111
) ;
112
+ const neonRelayerInfo = useNeonRelayerInfo (
113
+ targetChain ,
114
+ vaaNormalizedAmount ,
115
+ originChain ? hexToNativeAssetString ( originAsset , originChain ) : undefined
116
+ ) ;
110
117
const sourceChain = useSelector ( selectTransferSourceChain ) ;
111
118
const dispatch = useDispatch ( ) ;
112
119
const relayerSelected = ! ! useSelector ( selectTransferUseRelayer ) ;
@@ -123,13 +130,23 @@ function FeeMethodSelector() {
123
130
targetChain === CHAIN_ID_ACALA || targetChain === CHAIN_ID_KARURA ;
124
131
const acalaRelayerEligible = acalaRelayerInfo . data ?. shouldRelay ;
125
132
133
+ const targetIsNeon = targetChain === CHAIN_ID_NEON ;
134
+ const neonRelayerEligible = neonRelayerInfo . data ?. shouldRelay ;
135
+
126
136
const chooseAcalaRelayer = useCallback ( ( ) => {
127
137
if ( targetIsAcala && acalaRelayerEligible ) {
128
138
dispatch ( setUseRelayer ( true ) ) ;
129
139
dispatch ( setRelayerFee ( undefined ) ) ;
130
140
}
131
141
} , [ dispatch , targetIsAcala , acalaRelayerEligible ] ) ;
132
142
143
+ const chooseNeonRelayer = useCallback ( ( ) => {
144
+ if ( targetIsNeon && neonRelayerEligible ) {
145
+ dispatch ( setUseRelayer ( true ) ) ;
146
+ dispatch ( setRelayerFee ( undefined ) ) ;
147
+ }
148
+ } , [ dispatch , targetIsNeon , neonRelayerEligible ] ) ;
149
+
133
150
const chooseRelayer = useCallback ( ( ) => {
134
151
if ( relayerEligible ) {
135
152
dispatch ( setUseRelayer ( true ) ) ;
@@ -149,6 +166,12 @@ function FeeMethodSelector() {
149
166
} else {
150
167
chooseManual ( ) ;
151
168
}
169
+ } else if ( targetIsNeon ) {
170
+ if ( neonRelayerEligible ) {
171
+ chooseNeonRelayer ( ) ;
172
+ } else {
173
+ chooseManual ( ) ;
174
+ }
152
175
} else if ( relayerInfo . data ?. isRelayable === true ) {
153
176
chooseRelayer ( ) ;
154
177
} else if ( relayerInfo . data ?. isRelayable === false ) {
@@ -162,53 +185,67 @@ function FeeMethodSelector() {
162
185
targetIsAcala ,
163
186
acalaRelayerEligible ,
164
187
chooseAcalaRelayer ,
188
+ targetIsNeon ,
189
+ neonRelayerEligible ,
190
+ chooseNeonRelayer ,
165
191
] ) ;
166
192
167
- const acalaRelayerContent = (
168
- < Card
169
- className = {
170
- classes . optionCardBase +
171
- " " +
172
- ( relayerSelected ? classes . optionCardSelected : "" ) +
173
- " " +
174
- ( acalaRelayerEligible ? classes . optionCardSelectable : "" )
175
- }
176
- onClick = { chooseAcalaRelayer }
177
- >
178
- < div className = { classes . alignCenterContainer } >
179
- < Checkbox
180
- checked = { relayerSelected }
181
- disabled = { ! acalaRelayerEligible }
182
- onClick = { chooseAcalaRelayer }
183
- className = { classes . inlineBlock }
184
- />
185
- < div className = { clsx ( classes . inlineBlock , classes . alignLeft ) } >
186
- { acalaRelayerEligible ? (
187
- < div >
188
- < Typography variant = "body1" >
189
- { CHAINS_BY_ID [ targetChain ] . name }
190
- </ Typography >
191
- < Typography variant = "body2" color = "textSecondary" >
192
- { CHAINS_BY_ID [ targetChain ] . name } pays gas for you & #127881 ;
193
- </ Typography >
194
- </ div >
195
- ) : (
196
- < >
197
- < Typography color = "textSecondary" variant = "body2" >
198
- { "Automatic redeem is unavailable for this token." }
199
- </ Typography >
200
- < div />
201
- </ >
202
- ) }
193
+ const relayerContentFactory = ( relayerEligible : any , chooseRelayer : any ) => {
194
+ return (
195
+ < Card
196
+ className = {
197
+ classes . optionCardBase +
198
+ " " +
199
+ ( relayerSelected ? classes . optionCardSelected : "" ) +
200
+ " " +
201
+ ( relayerEligible ? classes . optionCardSelectable : "" )
202
+ }
203
+ onClick = { chooseRelayer }
204
+ >
205
+ < div className = { classes . alignCenterContainer } >
206
+ < Checkbox
207
+ checked = { relayerSelected }
208
+ disabled = { ! relayerEligible }
209
+ onClick = { chooseRelayer }
210
+ className = { classes . inlineBlock }
211
+ />
212
+ < div className = { clsx ( classes . inlineBlock , classes . alignLeft ) } >
213
+ { relayerEligible ? (
214
+ < >
215
+ < Typography variant = "body1" >
216
+ { CHAINS_BY_ID [ targetChain ] . name }
217
+ </ Typography >
218
+ < Typography variant = "body2" color = "textSecondary" >
219
+ { CHAINS_BY_ID [ targetChain ] . name } pays gas for you & #127881 ;
220
+ </ Typography >
221
+ </ >
222
+ ) : (
223
+ < >
224
+ < Typography color = "textSecondary" variant = "body2" >
225
+ { "Automatic redeem is unavailable for this token." }
226
+ </ Typography >
227
+ < div />
228
+ </ >
229
+ ) }
230
+ </ div >
203
231
</ div >
204
- </ div >
205
- { acalaRelayerEligible ? (
206
- < >
207
- < div > </ div >
208
- < div > </ div >
209
- </ >
210
- ) : null }
211
- </ Card >
232
+ { relayerEligible ? (
233
+ < >
234
+ < div > </ div >
235
+ < div > </ div >
236
+ </ >
237
+ ) : null }
238
+ </ Card >
239
+ ) ;
240
+ } ;
241
+
242
+ const acalaRelayerContent = relayerContentFactory (
243
+ acalaRelayerEligible ,
244
+ chooseAcalaRelayer
245
+ ) ;
246
+ const neonRelayerContent = relayerContentFactory (
247
+ neonRelayerEligible ,
248
+ chooseNeonRelayer
212
249
) ;
213
250
214
251
const relayerContent = (
@@ -323,7 +360,11 @@ function FeeMethodSelector() {
323
360
>
324
361
How would you like to pay the target chain fees?
325
362
</ Typography >
326
- { targetIsAcala ? acalaRelayerContent : relayerContent }
363
+ { targetIsAcala
364
+ ? acalaRelayerContent
365
+ : targetIsNeon
366
+ ? neonRelayerContent
367
+ : relayerContent }
327
368
{ manualRedeemContent }
328
369
</ div >
329
370
) ;
0 commit comments