Skip to content

Commit

Permalink
Actual import logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KaffinPX committed Apr 11, 2024
1 parent a307519 commit 3648d6b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
31 changes: 18 additions & 13 deletions src/pages/CreateWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,36 @@ export enum Tabs {

export default function CreateWallet () {
const [ tab, setTab ] = useState(Tabs.Landing)
const [ mnemonic, setMnemonic ] = useState<string | undefined>()
const [ sensitive, setSensitive ] = useState("")
const [ isImport, setIsImport ] = useState(false)

const navigate = useNavigate()
const kaspa = useKaspa()

return (
{
[ Tabs.Landing ]: <Landing forward={tab => { setTab(tab) }} />,
[ Tabs.Intro ]: <Intro onConfirm={() => { setTab(Tabs.Password) }} />,
[ Tabs.Import ]: <Import onMnemonicsSubmit={async (mnemonic) => {
setMnemonic(mnemonic)
setTab(Tabs.Password)
[ Tabs.Landing ]: <Landing forward={tab => {
if (tab === Tabs.Password) setIsImport(true)
setTab(tab)
}} />,
[ Tabs.Intro ]: <Intro onConfirm={() => { setTab(Tabs.Password) }} />,
[ Tabs.Password ]: <Password onPasswordSet={async (password) => {
if (mnemonic) {
await kaspa.request('wallet:import', [ mnemonic, password ])
navigate('/')
if (isImport) {
setSensitive(password)
setTab(Tabs.Import)
} else {
const generatedMnemonic = await kaspa.request('wallet:create', [ password ])

setMnemonic(generatedMnemonic)
const mnemonic = await kaspa.request('wallet:create', [ password ])
setSensitive(mnemonic)
setTab(Tabs.Create)
}
}} />,
[ Tabs.Create ]: <Create mnemonic={mnemonic!} onSaved={() => { navigate('/') }} />
[ Tabs.Import ]: <Import onMnemonicsSubmit={async (mnemonic) => {
await kaspa.request('wallet:import', [ mnemonic, sensitive ]) // TODO: in case of error, tell its an invalid mnemonics

navigate('/wallet')
}} />,
[ Tabs.Create ]: <Create mnemonic={sensitive} onSaved={() => { navigate('/wallet') }} />
}[tab]
)
}
2 changes: 1 addition & 1 deletion src/pages/CreateWallet/Import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Import ({ onMnemonicsSubmit }: {
onMnemonicsSubmit(mnemonic)
}}
>
{i18n.getMessage('importWallet')}
Import
</Button>
</div>
</main>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/CreateWallet/Landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function Landing({ forward }: {
<Button
className={"gap-2"}
onClick={() => {
forward(Tabs.Import)
forward(Tabs.Password)
}}
>
<Import />
Expand Down

0 comments on commit 3648d6b

Please sign in to comment.