Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add/connect wallet flow #4239

Merged
merged 9 commits into from
Jun 27, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix
  • Loading branch information
peterpme committed Jun 27, 2023
commit abb69cad04cea003a9091273342dc7c397490092
20 changes: 18 additions & 2 deletions packages/app-mobile/src/components/MnemonicInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useState } from "react";
import { Alert, Pressable } from "react-native";
import { Alert, Keyboard, Pressable } from "react-native";

import {
UI_RPC_METHOD_KEYRING_STORE_MNEMONIC_CREATE,
Expand All @@ -25,13 +25,28 @@ type MnemonicInputProps = {
};
export function MnemonicInput({ readOnly, onComplete }: MnemonicInputProps) {
const background = useBackgroundClient();
const [keyboardStatus, setKeyboardStatus] = useState("");

const [mnemonicWords, setMnemonicWords] = useState<string[]>([
...Array(12).fill(""),
]);

const mnemonic = mnemonicWords.map((f) => f.trim()).join(" ");

useEffect(() => {
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
setKeyboardStatus("shown");
});
const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
setKeyboardStatus("hidden");
});

return () => {
showSubscription.remove();
hideSubscription.remove();
};
}, []);

const generateRandom = useCallback(() => {
background
.request({
Expand Down Expand Up @@ -66,6 +81,7 @@ export function MnemonicInput({ readOnly, onComplete }: MnemonicInputProps) {
}

if (words.length > 11) {
const mnemonic = mnemonicWords.map((f) => f.trim()).join(" ");
const isValid = words.length > 11 ? await isValidAsync(mnemonic) : false;
onComplete({ isValid, mnemonic });
}
Expand All @@ -83,7 +99,7 @@ export function MnemonicInput({ readOnly, onComplete }: MnemonicInputProps) {
/>
{readOnly ? (
<CopyButton text={mnemonicWords.join(", ")} />
) : (
) : keyboardStatus === "shown" ? null : (
<PasteButton
onPaste={(words) => {
const split = words.split(" ");
Expand Down