Skip to content

Commit 8abf7d6

Browse files
committed
Adds loading screen with rubics cube graphic
1 parent 806f714 commit 8abf7d6

File tree

2 files changed

+114
-36
lines changed

2 files changed

+114
-36
lines changed

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

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
Spinner,
2424
} from "@ui-kitten/components";
2525
import SendConfirmed from "../../svgs/SendConfirmed";
26+
import Rubics from "../../svgs/Rubics";
2627
import { useRouter, Stack } from "expo-router";
2728

2829
const isValidBigInt = (num: string) => {
@@ -45,6 +46,9 @@ const CheckIcon = (props: IconProps) => (
4546
<Icon {...props} name="checkmark-outline" />
4647
);
4748

49+
// First add a new type for the transaction state
50+
type TransactionState = "sending" | "sent" | "idle";
51+
4852
export default function Send() {
4953
const facade = useFacade();
5054
const router = useRouter();
@@ -57,10 +61,10 @@ export default function Send() {
5761
const [selectedFee, setSelectedFee] = useState<"default" | "custom">(
5862
"default",
5963
);
60-
const [showConfirmation, setShowConfirmation] = useState(false);
6164
const [sentTxHash, setSentTxHash] = useState<string>("");
6265
const [memo, setMemo] = useState<string>("");
63-
const [isLoading, setIsLoading] = useState(false);
66+
const [transactionState, setTransactionState] =
67+
useState<TransactionState>("idle");
6468

6569
const getAccountResult = facade.getAccount.useQuery(
6670
{},
@@ -238,17 +242,14 @@ export default function Send() {
238242
<Button
239243
style={styles.sendButton}
240244
disabled={
241-
isLoading ||
245+
transactionState !== "idle" ||
242246
isValidPublicAddress.data !== true ||
243247
!isValidBigInt(amount) ||
244248
(selectedFee === "custom" && !isValidBigInt(customFee))
245249
}
246-
accessoryLeft={
247-
isLoading ? (props) => <Spinner {...props} /> : undefined
248-
}
249250
onPress={async () => {
250251
try {
251-
setIsLoading(true);
252+
setTransactionState("sending");
252253

253254
const outputs = [
254255
{
@@ -259,7 +260,7 @@ export default function Send() {
259260
},
260261
];
261262

262-
const fee = selectedFee === "custom" ? customFee : "1"; // Default fee value
263+
const fee = selectedFee === "custom" ? customFee : "1";
263264

264265
const hash = await sendTransactionMutation.mutateAsync({
265266
accountName: getAccountResult.data?.name ?? "",
@@ -268,25 +269,23 @@ export default function Send() {
268269
});
269270

270271
setSentTxHash(hash);
271-
setShowConfirmation(true);
272+
setTransactionState("sent");
272273
} catch (error) {
273-
// You may want to add proper error handling here
274274
console.error("Failed to send transaction:", error);
275-
} finally {
276-
setIsLoading(false);
275+
setTransactionState("idle");
277276
}
278277
}}
279278
>
280-
{isLoading ? "SENDING..." : "SEND TRANSACTION"}
279+
SEND TRANSACTION
281280
</Button>
282281

283-
<Modal visible={showConfirmation} style={styles.modal}>
282+
<Modal visible={transactionState !== "idle"} style={styles.modal}>
284283
<Layout style={styles.modalContainer}>
285284
<View style={styles.svgContainer}>
286-
<SendConfirmed />
285+
{transactionState === "sending" ? <Rubics /> : <SendConfirmed />}
287286
</View>
288287
<Text category="h1" style={styles.sentText}>
289-
Sent!
288+
{transactionState === "sending" ? "Sending..." : "Sent!"}
290289
</Text>
291290
<Text category="s1" style={styles.amountText}>
292291
{amount}{" "}
@@ -304,25 +303,29 @@ export default function Send() {
304303
</Text>
305304
)}
306305
<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+
)}
326329
</View>
327330
</Layout>
328331
</Modal>
@@ -389,8 +392,10 @@ const styles = StyleSheet.create({
389392
width: "100%",
390393
},
391394
svgContainer: {
392-
width: "70%", // Make SVG slightly larger
395+
width: "70%",
393396
aspectRatio: 1,
397+
justifyContent: "center",
398+
alignItems: "center",
394399
},
395400
buttonContainer: {
396401
width: "100%",

0 commit comments

Comments
 (0)