Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 17 additions & 3 deletions packages/backend/bindings/node/native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/shared/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ export const logout = () => {
resetWallet()
resetRouter()
clearActiveProfile()
mnemonic.set(null)
}
2 changes: 1 addition & 1 deletion packages/shared/lib/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const path = readable<string>(null, (set) => {
/**
* Onboarding/setup type
*/
let walletSetupType = writable<SetupType>(null)
export const walletSetupType = writable<SetupType>(null)

/*
* Current view
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/lib/walletApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const eventsApiResponseTypes = Object.values(eventsApiToResponseTypeMap)
* Response subscriber.
* Receives messages from wallet.rs.
*/

Wallet.onMessage((message: MessageResponse) => {
if (message && message.id === undefined) {
// There is no message id
Expand All @@ -126,7 +127,7 @@ Wallet.onMessage((message: MessageResponse) => {
}

const _deleteCallbackId = (_id: string) => {
// Do not delete callback ids for events api methods
// Do not delete callback ids for events api methods
if (!eventsApiResponseTypes.includes(message.type)) {
delete callbacksStore[_id]
}
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/routes/setup/backup/Backup.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
},
{
onSuccess() {
// Clear mnemonic
mnemonic.set(null);
dispatch('next')
},
onError(err) {
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/routes/setup/import/Import.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Transition } from 'shared/components'
import { Import, TextImport, FileImport, BackupPassword, Success } from './views/'
import { api } from 'shared/lib/wallet'
import { mnemonic } from 'shared/lib/app'

export let locale
export let mobile
Expand Down Expand Up @@ -46,6 +47,7 @@
dispatch('next', { importType })
} else {
importType = 'mnemonic'
mnemonic.set(input.split(' '))
nextState = ImportState.Success
}
break
Expand Down
67 changes: 64 additions & 3 deletions packages/shared/routes/setup/protect/Protect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
import { get } from 'svelte/store'
import { Pin, Protect } from './views/'
import { showAppNotification } from 'shared/lib/notifications'
import { walletSetupType } from 'shared/lib/router'
import { mnemonic } from 'shared/lib/app'
import { DEFAULT_NODE, DEFAULT_NODES, network } from 'shared/lib/network'
import { SetupType } from 'shared/lib/typings/routes'

export let locale
export let mobile

let isVerifyingPin = false

enum ProtectState {
Init = 'init',
Biometric = 'biometric',
Expand All @@ -34,6 +40,47 @@
break
}

// Initialises wallet from imported mnemonic
// Verifies mnemonic syntactically
// Stores mnemonic
// Creates first account
function initialiseWallet(input: string): Promise<void> {
return new Promise((resolve, reject) => {
api.verifyMnemonic(input, {
onSuccess() {
api.storeMnemonic(input, {
onSuccess() {
api.createAccount(
{
signerType: { type: 'Stronghold' },
clientOptions: {
node: DEFAULT_NODE,
nodes: DEFAULT_NODES,
network: $network,
},
},
{
onSuccess() {
resolve()
},
onError(error) {
reject(error)
},
}
)
},
onError(error) {
reject(error)
},
})
},
onError(error) {
reject(error)
},
})
})
}

const _next = async (event) => {
let nextState
let params = event.detail || {}
Expand All @@ -53,17 +100,30 @@
break
case ProtectState.Confirm:
try {
isVerifyingPin = true

if (!validatePinFormat(pin)) {
throw new Error('Invalid pin code!')
}

await Electron.PincodeManager.set(get(activeProfile)?.id, pin)

api.setStoragePassword(pin, {
onSuccess() {
dispatch('next', { pin })
async onSuccess() {
if ($walletSetupType === SetupType.Mnemonic) {
await initialiseWallet(get(mnemonic).join(' '))

// Clear mnemonic
mnemonic.set(null)
dispatch('next', { pin })
} else {
dispatch('next', { pin })
}

isVerifyingPin = false
},
onError(err) {
isVerifyingPin = false
showAppNotification({
type: 'error',
message: locale(err.error),
Expand All @@ -72,6 +132,7 @@
})
break
} catch (error) {
isVerifyingPin = false
console.error(error)
}
}
Expand Down Expand Up @@ -102,6 +163,6 @@

{#if state === ProtectState.Pin || state === ProtectState.Confirm}
<Transition>
<Pin on:next={_next} on:previous={_previous} pinCandidate={pin} {locale} {mobile} />
<Pin loading={isVerifyingPin} on:next={_next} on:previous={_previous} pinCandidate={pin} {locale} {mobile} />
</Transition>
{/if}
4 changes: 3 additions & 1 deletion packages/shared/routes/setup/protect/views/Pin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
export let mobile
export let pinCandidate

export let loading

let pinInput

const dispatch = createEventDispatcher()
Expand Down Expand Up @@ -44,7 +46,7 @@
</div>
<div slot="leftpane__action" class="flex flex-row flex-wrap justify-between items-center space-x-4">
<Button secondary classes="flex-1" onClick={() => handleBackClick()}>{locale('actions.back')}</Button>
<Button classes="flex-1" disabled={!valid} onClick={() => onSubmit()}>{locale('actions.set_pin')}</Button>
<Button classes="flex-1" disabled={!valid || loading} onClick={() => onSubmit()}>{locale('actions.set_pin')}</Button>
</div>
<div slot="rightpane" class="w-full h-full flex justify-end items-center">
{#if !confirmInput}
Expand Down