@@ -3,15 +3,7 @@ import { OutputType } from "boltz-core";
3
3
import { Signature , TransactionResponse } from "ethers" ;
4
4
import { Network as LiquidNetwork } from "liquidjs-lib/src/networks" ;
5
5
import log from "loglevel" ;
6
- import {
7
- Accessor ,
8
- Match ,
9
- Setter ,
10
- Show ,
11
- Switch ,
12
- createResource ,
13
- createSignal ,
14
- } from "solid-js" ;
6
+ import { Accessor , Setter , Show , createResource , createSignal } from "solid-js" ;
15
7
import { ChainSwap , SubmarineSwap } from "src/utils/swapCreator" ;
16
8
17
9
import RefundEta from "../components/RefundEta" ;
@@ -136,14 +128,15 @@ export const RefundBtc = (props: {
136
128
const input = evt . currentTarget as HTMLInputElement ;
137
129
const inputValue = input . value . trim ( ) ;
138
130
131
+ setRefundAddress ( inputValue ) ;
132
+
139
133
const lockupAddress =
140
134
props . swap ( ) . type === SwapType . Submarine
141
135
? ( props . swap ( ) as SubmarineSwap ) . address
142
136
: ( props . swap ( ) as ChainSwap ) . lockupDetails . lockupAddress ;
143
137
144
138
if ( inputValue === lockupAddress ) {
145
139
log . debug ( "refunds to lockup address are blocked" ) ;
146
- input . setCustomValidity ( "lockup address" ) ;
147
140
return false ;
148
141
}
149
142
try {
@@ -152,14 +145,12 @@ export const RefundBtc = (props: {
152
145
getNetwork ( asset ) as LiquidNetwork ,
153
146
) ;
154
147
input . setCustomValidity ( "" ) ;
155
- setRefundAddress ( inputValue ) ;
156
148
return true ;
157
149
} catch ( e ) {
158
150
log . debug ( "parsing refund address failed" , e ) ;
159
151
input . setCustomValidity ( "invalid address" ) ;
152
+ return false ;
160
153
}
161
-
162
- return false ;
163
154
} ;
164
155
165
156
const refundAction = async ( ) => {
@@ -235,62 +226,60 @@ export const RefundBtc = (props: {
235
226
return transactionToRefund ;
236
227
} ) ;
237
228
229
+ const message = ( ) =>
230
+ props . buttonOverride ??
231
+ ( lockupTransaction . state == "errored"
232
+ ? t ( "no_lockup_transaction" )
233
+ : valid ( ) || ! refundAddress ( ) || ! props . swap ( )
234
+ ? t ( "refund" )
235
+ : t ( "invalid_address" , { asset : props . swap ( ) ?. assetSend } ) ) ;
236
+
238
237
return (
239
- < Switch >
240
- < Match
241
- when = {
242
- lockupTransaction . state === "ready" ||
243
- lockupTransaction . state == "unresolved"
244
- } >
245
- < Show when = { timeoutEta ( ) > 0 || timeoutBlockheight ( ) > 0 } >
246
- < RefundEta
247
- timeoutEta = { timeoutEta }
248
- timeoutBlockHeight = { timeoutBlockheight }
249
- />
250
- </ Show >
251
- < h3 style = { { color : "#fff" } } >
252
- { props . swap ( )
253
- ? t ( "refund_address_header" , {
238
+ < Show
239
+ when = {
240
+ lockupTransaction . state === "ready" ||
241
+ lockupTransaction . state == "unresolved" ||
242
+ lockupTransaction . state == "errored"
243
+ }
244
+ fallback = { < LoadingSpinner /> } >
245
+ < Show when = { timeoutEta ( ) > 0 || timeoutBlockheight ( ) > 0 } >
246
+ < RefundEta
247
+ timeoutEta = { timeoutEta }
248
+ timeoutBlockHeight = { timeoutBlockheight }
249
+ />
250
+ </ Show >
251
+ < h3 style = { { color : "#fff" } } >
252
+ { props . swap ( )
253
+ ? t ( "refund_address_header" , {
254
+ asset : props . swap ( ) ?. assetSend ,
255
+ } )
256
+ : t ( "refund_address_header_no_asset" ) }
257
+ </ h3 >
258
+ < input
259
+ data-testid = "refundAddress"
260
+ id = "refundAddress"
261
+ disabled = { lockupTransaction . state == "errored" }
262
+ onInput = { ( e ) =>
263
+ setValid ( refundAddressChange ( e , props . swap ( ) ?. assetSend ) )
264
+ }
265
+ type = "text"
266
+ name = "refundAddress"
267
+ placeholder = {
268
+ props . swap ( )
269
+ ? t ( "onchain_address" , {
254
270
asset : props . swap ( ) ?. assetSend ,
255
271
} )
256
- : t ( "refund_address_header_no_asset" ) }
257
- </ h3 >
258
- < input
259
- data-testid = "refundAddress"
260
- id = "refundAddress"
261
- disabled = { props . swap ( ) === null }
262
- onInput = { ( e ) =>
263
- setValid (
264
- refundAddressChange ( e , props . swap ( ) ?. assetSend ) ,
265
- )
266
- }
267
- type = "text"
268
- name = "refundAddress"
269
- placeholder = {
270
- props . swap ( )
271
- ? t ( "onchain_address" , {
272
- asset : props . swap ( ) ?. assetSend ,
273
- } )
274
- : t ( "onchain_address_no_asset" )
275
- }
276
- />
277
- < button
278
- data-testid = "refundButton"
279
- class = "btn"
280
- disabled = { ! valid ( ) || refundRunning ( ) }
281
- onClick = { ( ) => refundAction ( ) } >
282
- { props . buttonOverride ?? t ( "refund" ) }
283
- </ button >
284
- </ Match >
285
- < Match when = { lockupTransaction . state === "pending" } >
286
- < LoadingSpinner />
287
- </ Match >
288
- < Match when = { lockupTransaction . state === "errored" } >
289
- < button class = "btn" disabled = { true } >
290
- { t ( "no_lockup_transaction" ) }
291
- </ button >
292
- </ Match >
293
- </ Switch >
272
+ : t ( "onchain_address_no_asset" )
273
+ }
274
+ />
275
+ < button
276
+ data-testid = "refundButton"
277
+ class = "btn"
278
+ disabled = { ! valid ( ) || refundRunning ( ) }
279
+ onClick = { ( ) => refundAction ( ) } >
280
+ { message ( ) }
281
+ </ button >
282
+ </ Show >
294
283
) ;
295
284
} ;
296
285
0 commit comments