Skip to content

Commit 806f714

Browse files
committed
Adds memo and some sort of loading state
1 parent ba3ceca commit 806f714

File tree

1 file changed

+62
-5
lines changed

1 file changed

+62
-5
lines changed

packages/mobile-app/app/send/index.tsx

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useFacade } from "../../data/facades";
44
import { useState, useMemo } from "react";
55
import { IRON_ASSET_ID_HEX } from "../../data/constants";
66
import { CurrencyUtils } from "@ironfish/sdk";
7-
import { useQueries } from "@tanstack/react-query";
7+
import { useQueries, useMutation } from "@tanstack/react-query";
88
import { Asset } from "@/data/facades/chain/types";
99
import { AccountBalance } from "@/data/facades/wallet/types";
1010
import {
@@ -20,6 +20,7 @@ import {
2020
IndexPath,
2121
IconProps,
2222
Modal,
23+
Spinner,
2324
} from "@ui-kitten/components";
2425
import SendConfirmed from "../../svgs/SendConfirmed";
2526
import { useRouter, Stack } from "expo-router";
@@ -58,6 +59,8 @@ export default function Send() {
5859
);
5960
const [showConfirmation, setShowConfirmation] = useState(false);
6061
const [sentTxHash, setSentTxHash] = useState<string>("");
62+
const [memo, setMemo] = useState<string>("");
63+
const [isLoading, setIsLoading] = useState(false);
6164

6265
const getAccountResult = facade.getAccount.useQuery(
6366
{},
@@ -139,6 +142,9 @@ export default function Send() {
139142
? (assetMap.get(selectedAssetId)?.verification.decimals ?? 0)
140143
: 0;
141144

145+
// Add the mutation
146+
const sendTransactionMutation = facade.sendTransaction.useMutation();
147+
142148
return (
143149
<Layout style={styles.container} level="1">
144150
<Stack.Screen options={{ headerTitle: "Send Transaction" }} />
@@ -193,6 +199,15 @@ export default function Send() {
193199
caption={`Maximum ${decimals} decimal places`}
194200
/>
195201

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+
196211
<Text category="s1" style={styles.sectionTitle}>
197212
Transaction Fee
198213
</Text>
@@ -223,15 +238,46 @@ export default function Send() {
223238
<Button
224239
style={styles.sendButton}
225240
disabled={
241+
isLoading ||
226242
isValidPublicAddress.data !== true ||
243+
!isValidBigInt(amount) ||
227244
(selectedFee === "custom" && !isValidBigInt(customFee))
228245
}
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+
}
232278
}}
233279
>
234-
SEND TRANSACTION
280+
{isLoading ? "SENDING..." : "SEND TRANSACTION"}
235281
</Button>
236282

237283
<Modal visible={showConfirmation} style={styles.modal}>
@@ -252,6 +298,11 @@ export default function Send() {
252298
<Text category="s1" style={styles.addressText}>
253299
{selectedRecipient}
254300
</Text>
301+
{memo && (
302+
<Text category="s1" style={styles.memoText}>
303+
Memo: {memo}
304+
</Text>
305+
)}
255306
<View style={styles.buttonContainer}>
256307
<Button
257308
appearance="filled"
@@ -348,4 +399,10 @@ const styles = StyleSheet.create({
348399
marginBottom: 16,
349400
width: "100%",
350401
},
402+
memoText: {
403+
color: "gray",
404+
textAlign: "center",
405+
marginBottom: 16,
406+
fontStyle: "italic",
407+
},
351408
});

0 commit comments

Comments
 (0)