@@ -23,6 +23,7 @@ import {
23
23
Spinner ,
24
24
} from "@ui-kitten/components" ;
25
25
import SendConfirmed from "../../svgs/SendConfirmed" ;
26
+ import Rubics from "../../svgs/Rubics" ;
26
27
import { useRouter , Stack } from "expo-router" ;
27
28
28
29
const isValidBigInt = ( num : string ) => {
@@ -45,6 +46,9 @@ const CheckIcon = (props: IconProps) => (
45
46
< Icon { ...props } name = "checkmark-outline" />
46
47
) ;
47
48
49
+ // First add a new type for the transaction state
50
+ type TransactionState = "sending" | "sent" | "idle" ;
51
+
48
52
export default function Send ( ) {
49
53
const facade = useFacade ( ) ;
50
54
const router = useRouter ( ) ;
@@ -57,10 +61,10 @@ export default function Send() {
57
61
const [ selectedFee , setSelectedFee ] = useState < "default" | "custom" > (
58
62
"default" ,
59
63
) ;
60
- const [ showConfirmation , setShowConfirmation ] = useState ( false ) ;
61
64
const [ sentTxHash , setSentTxHash ] = useState < string > ( "" ) ;
62
65
const [ memo , setMemo ] = useState < string > ( "" ) ;
63
- const [ isLoading , setIsLoading ] = useState ( false ) ;
66
+ const [ transactionState , setTransactionState ] =
67
+ useState < TransactionState > ( "idle" ) ;
64
68
65
69
const getAccountResult = facade . getAccount . useQuery (
66
70
{ } ,
@@ -238,17 +242,14 @@ export default function Send() {
238
242
< Button
239
243
style = { styles . sendButton }
240
244
disabled = {
241
- isLoading ||
245
+ transactionState !== "idle" ||
242
246
isValidPublicAddress . data !== true ||
243
247
! isValidBigInt ( amount ) ||
244
248
( selectedFee === "custom" && ! isValidBigInt ( customFee ) )
245
249
}
246
- accessoryLeft = {
247
- isLoading ? ( props ) => < Spinner { ...props } /> : undefined
248
- }
249
250
onPress = { async ( ) => {
250
251
try {
251
- setIsLoading ( true ) ;
252
+ setTransactionState ( "sending" ) ;
252
253
253
254
const outputs = [
254
255
{
@@ -259,7 +260,7 @@ export default function Send() {
259
260
} ,
260
261
] ;
261
262
262
- const fee = selectedFee === "custom" ? customFee : "1" ; // Default fee value
263
+ const fee = selectedFee === "custom" ? customFee : "1" ;
263
264
264
265
const hash = await sendTransactionMutation . mutateAsync ( {
265
266
accountName : getAccountResult . data ?. name ?? "" ,
@@ -268,25 +269,23 @@ export default function Send() {
268
269
} ) ;
269
270
270
271
setSentTxHash ( hash ) ;
271
- setShowConfirmation ( true ) ;
272
+ setTransactionState ( "sent" ) ;
272
273
} catch ( error ) {
273
- // You may want to add proper error handling here
274
274
console . error ( "Failed to send transaction:" , error ) ;
275
- } finally {
276
- setIsLoading ( false ) ;
275
+ setTransactionState ( "idle" ) ;
277
276
}
278
277
} }
279
278
>
280
- { isLoading ? "SENDING..." : " SEND TRANSACTION" }
279
+ SEND TRANSACTION
281
280
</ Button >
282
281
283
- < Modal visible = { showConfirmation } style = { styles . modal } >
282
+ < Modal visible = { transactionState !== "idle" } style = { styles . modal } >
284
283
< Layout style = { styles . modalContainer } >
285
284
< View style = { styles . svgContainer } >
286
- < SendConfirmed />
285
+ { transactionState === "sending" ? < Rubics /> : < SendConfirmed /> }
287
286
</ View >
288
287
< Text category = "h1" style = { styles . sentText } >
289
- Sent!
288
+ { transactionState === "sending" ? "Sending..." : " Sent!" }
290
289
</ Text >
291
290
< Text category = "s1" style = { styles . amountText } >
292
291
{ amount } { " " }
@@ -304,25 +303,29 @@ export default function Send() {
304
303
</ Text >
305
304
) }
306
305
< View style = { styles . buttonContainer } >
307
- < Button
308
- appearance = "filled"
309
- style = { styles . confirmButton }
310
- onPress = { ( ) => {
311
- console . log ( "will navigate to" , sentTxHash ) ;
312
- } }
313
- >
314
- View Transaction
315
- </ Button >
316
- < Button
317
- appearance = "outline"
318
- style = { styles . confirmButton }
319
- onPress = { ( ) => {
320
- setShowConfirmation ( false ) ;
321
- router . back ( ) ;
322
- } }
323
- >
324
- Close
325
- </ Button >
306
+ { transactionState === "sent" && (
307
+ < >
308
+ < Button
309
+ appearance = "filled"
310
+ style = { styles . confirmButton }
311
+ onPress = { ( ) => {
312
+ console . log ( "will navigate to" , sentTxHash ) ;
313
+ } }
314
+ >
315
+ View Transaction
316
+ </ Button >
317
+ < Button
318
+ appearance = "outline"
319
+ style = { styles . confirmButton }
320
+ onPress = { ( ) => {
321
+ setTransactionState ( "idle" ) ;
322
+ router . back ( ) ;
323
+ } }
324
+ >
325
+ Close
326
+ </ Button >
327
+ </ >
328
+ ) }
326
329
</ View >
327
330
</ Layout >
328
331
</ Modal >
@@ -389,8 +392,10 @@ const styles = StyleSheet.create({
389
392
width : "100%" ,
390
393
} ,
391
394
svgContainer : {
392
- width : "70%" , // Make SVG slightly larger
395
+ width : "70%" ,
393
396
aspectRatio : 1 ,
397
+ justifyContent : "center" ,
398
+ alignItems : "center" ,
394
399
} ,
395
400
buttonContainer : {
396
401
width : "100%" ,
0 commit comments