@@ -4,7 +4,7 @@ import { useFacade } from "../../data/facades";
4
4
import { useState , useMemo } from "react" ;
5
5
import { IRON_ASSET_ID_HEX } from "../../data/constants" ;
6
6
import { CurrencyUtils } from "@ironfish/sdk" ;
7
- import { useQueries } from "@tanstack/react-query" ;
7
+ import { useQueries , useMutation } from "@tanstack/react-query" ;
8
8
import { Asset } from "@/data/facades/chain/types" ;
9
9
import { AccountBalance } from "@/data/facades/wallet/types" ;
10
10
import {
@@ -20,6 +20,7 @@ import {
20
20
IndexPath ,
21
21
IconProps ,
22
22
Modal ,
23
+ Spinner ,
23
24
} from "@ui-kitten/components" ;
24
25
import SendConfirmed from "../../svgs/SendConfirmed" ;
25
26
import { useRouter , Stack } from "expo-router" ;
@@ -58,6 +59,8 @@ export default function Send() {
58
59
) ;
59
60
const [ showConfirmation , setShowConfirmation ] = useState ( false ) ;
60
61
const [ sentTxHash , setSentTxHash ] = useState < string > ( "" ) ;
62
+ const [ memo , setMemo ] = useState < string > ( "" ) ;
63
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
61
64
62
65
const getAccountResult = facade . getAccount . useQuery (
63
66
{ } ,
@@ -139,6 +142,9 @@ export default function Send() {
139
142
? ( assetMap . get ( selectedAssetId ) ?. verification . decimals ?? 0 )
140
143
: 0 ;
141
144
145
+ // Add the mutation
146
+ const sendTransactionMutation = facade . sendTransaction . useMutation ( ) ;
147
+
142
148
return (
143
149
< Layout style = { styles . container } level = "1" >
144
150
< Stack . Screen options = { { headerTitle : "Send Transaction" } } />
@@ -193,6 +199,15 @@ export default function Send() {
193
199
caption = { `Maximum ${ decimals } decimal places` }
194
200
/>
195
201
202
+ < Input
203
+ label = "Memo (Optional)"
204
+ placeholder = "Enter a memo for this transaction"
205
+ value = { memo }
206
+ onChangeText = { setMemo }
207
+ style = { styles . input }
208
+ maxLength = { 100 }
209
+ />
210
+
196
211
< Text category = "s1" style = { styles . sectionTitle } >
197
212
Transaction Fee
198
213
</ Text >
@@ -223,15 +238,46 @@ export default function Send() {
223
238
< Button
224
239
style = { styles . sendButton }
225
240
disabled = {
241
+ isLoading ||
226
242
isValidPublicAddress . data !== true ||
243
+ ! isValidBigInt ( amount ) ||
227
244
( selectedFee === "custom" && ! isValidBigInt ( customFee ) )
228
245
}
229
- onPress = { ( ) => {
230
- setShowConfirmation ( true ) ;
231
- setSentTxHash ( "mock_transaction_hash" ) ;
246
+ accessoryLeft = {
247
+ isLoading ? ( props ) => < Spinner { ...props } /> : undefined
248
+ }
249
+ onPress = { async ( ) => {
250
+ try {
251
+ setIsLoading ( true ) ;
252
+
253
+ const outputs = [
254
+ {
255
+ publicAddress : selectedRecipient ,
256
+ amount : amount ,
257
+ memo : memo ,
258
+ assetId : selectedAssetId ,
259
+ } ,
260
+ ] ;
261
+
262
+ const fee = selectedFee === "custom" ? customFee : "1" ; // Default fee value
263
+
264
+ const hash = await sendTransactionMutation . mutateAsync ( {
265
+ accountName : getAccountResult . data ?. name ?? "" ,
266
+ outputs,
267
+ fee,
268
+ } ) ;
269
+
270
+ setSentTxHash ( hash ) ;
271
+ setShowConfirmation ( true ) ;
272
+ } catch ( error ) {
273
+ // You may want to add proper error handling here
274
+ console . error ( "Failed to send transaction:" , error ) ;
275
+ } finally {
276
+ setIsLoading ( false ) ;
277
+ }
232
278
} }
233
279
>
234
- SEND TRANSACTION
280
+ { isLoading ? "SENDING..." : " SEND TRANSACTION" }
235
281
</ Button >
236
282
237
283
< Modal visible = { showConfirmation } style = { styles . modal } >
@@ -252,6 +298,11 @@ export default function Send() {
252
298
< Text category = "s1" style = { styles . addressText } >
253
299
{ selectedRecipient }
254
300
</ Text >
301
+ { memo && (
302
+ < Text category = "s1" style = { styles . memoText } >
303
+ Memo: { memo }
304
+ </ Text >
305
+ ) }
255
306
< View style = { styles . buttonContainer } >
256
307
< Button
257
308
appearance = "filled"
@@ -348,4 +399,10 @@ const styles = StyleSheet.create({
348
399
marginBottom : 16 ,
349
400
width : "100%" ,
350
401
} ,
402
+ memoText : {
403
+ color : "gray" ,
404
+ textAlign : "center" ,
405
+ marginBottom : 16 ,
406
+ fontStyle : "italic" ,
407
+ } ,
351
408
} ) ;
0 commit comments