-
Notifications
You must be signed in to change notification settings - Fork 839
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add/connect wallet * advanced import wallet * mnemonic word adjustments * username input adjustments * updates * cleanup * fix * turn off pssword when biometrics eanbled * undo images
- Loading branch information
Showing
13 changed files
with
657 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
const Images = { | ||
solanaLogo: require("../assets/blockchains/solana.png"), | ||
ethereumLogo: require("../assets/blockchains/ethereum.png"), | ||
logoAvalanche: require("./images/logo-avalanche.png"), | ||
logoBsc: require("./images/logo-bsc.png"), | ||
logoCosmos: require("./images/logo-cosmos.png"), | ||
logoEthereum: require("./images/logo-ethereum.png"), | ||
logoPolygon: require("./images/logo-polygon.png"), | ||
logoSolana: require("./images/logo-solana.png"), | ||
}; | ||
|
||
export default Images; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { Alert, Keyboard, Pressable } from "react-native"; | ||
|
||
import { | ||
UI_RPC_METHOD_KEYRING_STORE_MNEMONIC_CREATE, | ||
UI_RPC_METHOD_KEYRING_VALIDATE_MNEMONIC, | ||
} from "@coral-xyz/common"; | ||
import { useBackgroundClient } from "@coral-xyz/recoil"; | ||
import { StyledText, YStack } from "@coral-xyz/tamagui"; | ||
|
||
import { maybeRender } from "~lib/index"; | ||
|
||
import { MnemonicInputFields } from "~src/components/MnemonicInputFields"; | ||
import { CopyButton, PasteButton } from "~src/components/index"; | ||
|
||
type MnemonicInputProps = { | ||
readOnly: boolean; | ||
onComplete: ({ | ||
mnemonic, | ||
isValid, | ||
}: { | ||
mnemonic: string; | ||
isValid: boolean; | ||
}) => void; | ||
}; | ||
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({ | ||
method: UI_RPC_METHOD_KEYRING_STORE_MNEMONIC_CREATE, | ||
params: [mnemonicWords.length === 12 ? 128 : 256], | ||
}) | ||
.then((m: string) => { | ||
const words = m.split(" "); | ||
setMnemonicWords(words); | ||
}); | ||
}, []); // eslint-disable-line | ||
|
||
useEffect(() => { | ||
if (readOnly) { | ||
generateRandom(); | ||
} | ||
}, [readOnly, generateRandom]); | ||
|
||
const isValidAsync = (mnemonic: string) => { | ||
return background.request({ | ||
method: UI_RPC_METHOD_KEYRING_VALIDATE_MNEMONIC, | ||
params: [mnemonic], | ||
}); | ||
}; | ||
|
||
const onChange = async (words: string[]) => { | ||
setMnemonicWords(words); | ||
if (readOnly) { | ||
const mnemonic = mnemonicWords.map((f) => f.trim()).join(" "); | ||
onComplete({ isValid: true, mnemonic }); | ||
return; | ||
} | ||
|
||
if (words.length > 11) { | ||
const mnemonic = mnemonicWords.map((f) => f.trim()).join(" "); | ||
const isValid = words.length > 11 ? await isValidAsync(mnemonic) : false; | ||
onComplete({ isValid, mnemonic }); | ||
} | ||
}; | ||
|
||
return ( | ||
<YStack space={8}> | ||
<MnemonicInputFields | ||
mnemonicWords={mnemonicWords} | ||
onChange={readOnly ? undefined : onChange} | ||
onComplete={async () => { | ||
const isValid = await isValidAsync(mnemonic); | ||
onComplete({ isValid, mnemonic }); | ||
}} | ||
/> | ||
{readOnly ? ( | ||
<CopyButton text={mnemonicWords.join(", ")} /> | ||
) : keyboardStatus === "shown" ? null : ( | ||
<PasteButton | ||
onPaste={(words) => { | ||
const split = words.split(" "); | ||
if ([12, 24].includes(split.length)) { | ||
setMnemonicWords(words.split(" ")); | ||
} else { | ||
Alert.alert("Mnemonic should be either 12 or 24 words"); | ||
} | ||
}} | ||
/> | ||
)} | ||
{maybeRender(!readOnly, () => ( | ||
<Pressable | ||
hitSlop={12} | ||
onPress={() => { | ||
setMnemonicWords([ | ||
...Array(mnemonicWords.length === 12 ? 24 : 12).fill(""), | ||
]); | ||
}} | ||
> | ||
<StyledText fontSize="$sm" textAlign="center"> | ||
Use a {mnemonicWords.length === 12 ? "24" : "12"}-word recovery | ||
mnemonic | ||
</StyledText> | ||
</Pressable> | ||
))} | ||
</YStack> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
72bb031
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
backpack – ./
backpack-git-master-200ms.vercel.app
www.backpack.app
backpack-200ms.vercel.app
devnet.backpack.app
backpack.app