|
| 1 | +import clsx from "clsx"; |
| 2 | +import { useModal } from "../../providers"; |
| 3 | +import type { HandleCreateWalletParams } from "../../types/method-types"; |
| 4 | +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; |
| 5 | +import { faWallet } from "@fortawesome/free-solid-svg-icons"; |
| 6 | +import { ActionButton } from "../design/Buttons"; |
| 7 | +import { parseCreateWalletInput, v1WalletAccountParams } from "@turnkey/core"; |
| 8 | + |
| 9 | +type CreateWalletProps = HandleCreateWalletParams & { |
| 10 | + onSuccess: (walletId: string) => void; |
| 11 | + onError: (error: any) => void; |
| 12 | +}; |
| 13 | + |
| 14 | +function DetailEntry(props: { name: string; value: string | number | object }) { |
| 15 | + const { name, value } = props; |
| 16 | + const text = |
| 17 | + typeof value === "object" && value !== null |
| 18 | + ? JSON.stringify(value) |
| 19 | + : String(value); |
| 20 | + |
| 21 | + return ( |
| 22 | + <div key={name} className="flex gap-1 items-center"> |
| 23 | + <div className="font-mono! flex-shrink-0">{name}:</div> |
| 24 | + <div className="font-mono! truncate flex-1 min-w-0" title={text}> |
| 25 | + {text} |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + ); |
| 29 | +} |
| 30 | + |
| 31 | +export function CreateWallet(props: CreateWalletProps) { |
| 32 | + const { walletName, mnemonicLength, accounts } = props; |
| 33 | + const { isMobile } = useModal(); |
| 34 | + |
| 35 | + const parsedAccounts: v1WalletAccountParams[] = parseCreateWalletInput({ |
| 36 | + accounts, |
| 37 | + }); |
| 38 | + |
| 39 | + return ( |
| 40 | + <div className={clsx("mt-8", isMobile ? "w-full" : "w-96")}> |
| 41 | + <div className="mt-6 mb-5 flex flex-col items-center gap-3"> |
| 42 | + <FontAwesomeIcon icon={faWallet} size={"3x"} /> |
| 43 | + <div className="text-2xl font-bold text-center">{"Create Wallet"}</div> |
| 44 | + <div className="text-icon-text-light dark:text-icon-text-dark text-center !p-0"> |
| 45 | + {"You are about to create a new wallet with the following data:"} |
| 46 | + </div> |
| 47 | + <div className="w-full h-full overflow-y-scroll tk-scrollbar flex flex-col mt-2 max-h-56 rounded-md border border-modal-background-dark/10 dark:border-modal-background-light/10 bg-icon-background-light dark:bg-icon-background-dark text-icon-text-light dark:text-icon-text-dark text-sm font-mono!"> |
| 48 | + <div className="gap-2 flex flex-col p-3"> |
| 49 | + <DetailEntry name="Wallet name" value={walletName} /> |
| 50 | + <DetailEntry |
| 51 | + name="Mnemonic length" |
| 52 | + value={`${mnemonicLength ?? 12} words`} |
| 53 | + /> |
| 54 | + <div className="border-t border-modal-background-dark/10 dark:border-modal-background-light/10" /> |
| 55 | + <div className="gap-4 flex flex-col"> |
| 56 | + {parsedAccounts.length === 0 ? ( |
| 57 | + <div className="text-muted-foreground">No accounts</div> |
| 58 | + ) : ( |
| 59 | + parsedAccounts.map((acct, idx) => ( |
| 60 | + <div key={idx} className="bg-transparent"> |
| 61 | + <div className="font-mono! mb-2">Account {idx + 1}:</div> |
| 62 | + <div className="flex flex-col gap-2 ml-2"> |
| 63 | + {Object.entries(acct).map(([k, v]) => ( |
| 64 | + <DetailEntry name={k} value={v} /> |
| 65 | + ))} |
| 66 | + </div> |
| 67 | + </div> |
| 68 | + )) |
| 69 | + )} |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + <div className="flex my-2 mt-0"> |
| 75 | + <ActionButton |
| 76 | + onClick={() => {}} |
| 77 | + loading={false} |
| 78 | + className="w-full md:max-w-md bg-primary-light dark:bg-primary-dark text-primary-text-light dark:text-primary-text-dark" |
| 79 | + > |
| 80 | + Continue |
| 81 | + </ActionButton> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + ); |
| 85 | +} |
0 commit comments