diff --git a/packages/demo-wallet/src/App/Actions.tsx b/packages/demo-wallet/src/App/Actions.tsx index 3cb6786..8d82e8b 100644 --- a/packages/demo-wallet/src/App/Actions.tsx +++ b/packages/demo-wallet/src/App/Actions.tsx @@ -1,7 +1,7 @@ import initWasm, { initThreadPool, WebWallet } from "@webzjs/webz-core"; import { State, Action } from "./App"; -import { MAINNET_LIGHTWALLETD_PROXY } from "./constants"; +import { MAINNET_LIGHTWALLETD_PROXY } from "./Constants"; export async function init(dispatch: React.Dispatch) { await initWasm(); @@ -13,8 +13,8 @@ export async function init(dispatch: React.Dispatch) { } export async function addNewAccount(state: State, dispatch: React.Dispatch, seedPhrase: string, birthdayHeight: number) { - await state.webWallet?.create_account(seedPhrase, 0, birthdayHeight); - dispatch({ type: "append-account-seed", payload: seedPhrase }); + let account_id = await state.webWallet?.create_account(seedPhrase, 0, birthdayHeight) || 0; + dispatch({ type: "add-account-seed", payload: [account_id, seedPhrase] }); await syncStateWithWallet(state, dispatch); } @@ -60,6 +60,7 @@ export async function triggerTransfer( throw new Error("No active account"); } - await state.webWallet?.transfer(state.accountSeeds[state.activeAccount], state.activeAccount, toAddress, amount); + let activeAccountSeedPhrase = state.accountSeeds.get(state.activeAccount) || ""; + await state.webWallet?.transfer(activeAccountSeedPhrase, state.activeAccount, toAddress, amount); await syncStateWithWallet(state, dispatch); } diff --git a/packages/demo-wallet/src/App/App.tsx b/packages/demo-wallet/src/App/App.tsx index d650a94..16ae026 100644 --- a/packages/demo-wallet/src/App/App.tsx +++ b/packages/demo-wallet/src/App/App.tsx @@ -23,19 +23,19 @@ export type State = { activeAccount?: number; summary?: WalletSummary; chainHeight?: bigint; - accountSeeds: string[]; + accountSeeds: Map; }; const initialState: State = { activeAccount: undefined, summary: undefined, chainHeight: undefined, - accountSeeds: [], + accountSeeds: new Map(), }; export type Action = | { type: "set-active-account"; payload: number } - | { type: "append-account-seed"; payload: string } + | { type: "add-account-seed"; payload: [number, string] } | { type: "set-web-wallet"; payload: WebWallet } | { type: "set-summary"; payload: WalletSummary } | { type: "set-chain-height"; payload: bigint }; @@ -45,8 +45,8 @@ const reducer = (state: State, action: Action): State => { case "set-active-account": { return { ...state, activeAccount: action.payload }; } - case "append-account-seed": { - return { ...state, accountSeeds: [...state.accountSeeds, action.payload] }; + case "add-account-seed": { + return { ...state, accountSeeds: state.accountSeeds.set(action.payload[0], action.payload[1]) }; } case "set-web-wallet": { return { ...state, webWallet: action.payload }; diff --git a/src/bindgen/wallet.rs b/src/bindgen/wallet.rs index 927448d..f974f97 100644 --- a/src/bindgen/wallet.rs +++ b/src/bindgen/wallet.rs @@ -1,5 +1,4 @@ use std::num::NonZeroU32; -use std::ops::Deref; use serde::{Deserialize, Serialize}; use wasm_bindgen::prelude::*;