Skip to content

Commit

Permalink
update demo wallet with new api
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Sep 30, 2024
1 parent 88e65e4 commit a6ef53d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
9 changes: 5 additions & 4 deletions packages/demo-wallet/src/App/Actions.tsx
Original file line number Diff line number Diff line change
@@ -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<Action>) {
await initWasm();
Expand All @@ -13,8 +13,8 @@ export async function init(dispatch: React.Dispatch<Action>) {
}

export async function addNewAccount(state: State, dispatch: React.Dispatch<Action>, 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);
}

Expand Down Expand Up @@ -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);
}
10 changes: 5 additions & 5 deletions packages/demo-wallet/src/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ export type State = {
activeAccount?: number;
summary?: WalletSummary;
chainHeight?: bigint;
accountSeeds: string[];
accountSeeds: Map<number, string>;
};

const initialState: State = {
activeAccount: undefined,
summary: undefined,
chainHeight: undefined,
accountSeeds: [],
accountSeeds: new Map<number, string>(),
};

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 };
Expand All @@ -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 };
Expand Down
1 change: 0 additions & 1 deletion src/bindgen/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::num::NonZeroU32;
use std::ops::Deref;

use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;
Expand Down

0 comments on commit a6ef53d

Please sign in to comment.