Skip to content

Commit ea6c42c

Browse files
committed
call sync not sync2
1 parent 5119121 commit ea6c42c

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

packages/demo-wallet/serve.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"headers": [
3+
{
4+
"source": "*/",
5+
"headers": [
6+
{
7+
"key": "Cross-Origin-Opener-Policy",
8+
"value": "same-origin"
9+
},
10+
{
11+
"key": "Cross-Origin-Embedder-Policy",
12+
"value": "require-corp"
13+
}
14+
]
15+
}
16+
]
17+
}
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
1-
import initWasm, { initThreadPool, WebWallet } from "@webzjs/webz-core";
1+
import initWasm, {initThreadPool, WebWallet} from "@webzjs/webz-core";
22

3-
import { State, Action } from "./App";
4-
import { MAINNET_LIGHTWALLETD_PROXY } from "./Constants";
3+
import {Action, State} from "./App";
4+
import {MAINNET_LIGHTWALLETD_PROXY} from "./Constants";
55

66
export async function init(dispatch: React.Dispatch<Action>) {
7-
await initWasm();
8-
await initThreadPool(10);
9-
dispatch({
10-
type: "set-web-wallet",
11-
payload: new WebWallet("main", MAINNET_LIGHTWALLETD_PROXY, 1),
12-
});
7+
await initWasm();
8+
await initThreadPool(10);
9+
dispatch({
10+
type: "set-web-wallet",
11+
payload: new WebWallet("main", MAINNET_LIGHTWALLETD_PROXY, 1),
12+
});
1313
}
1414

1515
export async function addNewAccount(state: State, dispatch: React.Dispatch<Action>, seedPhrase: string, birthdayHeight: number) {
1616
let account_id = await state.webWallet?.create_account(seedPhrase, 0, birthdayHeight) || 0;
17-
dispatch({ type: "add-account-seed", payload: [account_id, seedPhrase] });
17+
dispatch({type: "add-account-seed", payload: [account_id, seedPhrase]});
1818
await syncStateWithWallet(state, dispatch);
1919
}
2020

2121
export async function syncStateWithWallet(
22-
state: State,
23-
dispatch: React.Dispatch<Action>
22+
state: State,
23+
dispatch: React.Dispatch<Action>
2424
) {
25-
if (!state.webWallet) {
26-
throw new Error("Wallet not initialized");
27-
}
28-
let summary = await state.webWallet?.get_wallet_summary();
29-
if (summary) {
30-
dispatch({ type: "set-summary", payload: summary });
31-
}
32-
let chainHeight = await state.webWallet?.get_latest_block();
33-
if (chainHeight) {
34-
dispatch({ type: "set-chain-height", payload: chainHeight });
35-
}
36-
dispatch({ type: "set-active-account", payload: summary?.account_balances[0][0] });
25+
if (!state.webWallet) {
26+
throw new Error("Wallet not initialized");
27+
}
28+
let summary = await state.webWallet?.get_wallet_summary();
29+
if (summary) {
30+
dispatch({type: "set-summary", payload: summary});
31+
}
32+
let chainHeight = await state.webWallet?.get_latest_block();
33+
if (chainHeight) {
34+
dispatch({type: "set-chain-height", payload: chainHeight});
35+
}
36+
dispatch({type: "set-active-account", payload: summary?.account_balances[0][0]});
3737
}
3838

3939
export async function triggerRescan(
40-
state: State,
41-
dispatch: React.Dispatch<Action>
40+
state: State,
41+
dispatch: React.Dispatch<Action>
4242
) {
4343
if (!state.webWallet) {
4444
throw new Error("Wallet not initialized");
4545
}
46-
await state.webWallet?.sync2();
46+
await state.webWallet?.sync();
4747
await syncStateWithWallet(state, dispatch);
4848
}
4949

5050
export async function triggerTransfer(
51-
state: State,
52-
dispatch: React.Dispatch<Action>,
53-
toAddress: string,
54-
amount: bigint
51+
state: State,
52+
dispatch: React.Dispatch<Action>,
53+
toAddress: string,
54+
amount: bigint
5555
) {
5656
if (!state.webWallet) {
5757
throw new Error("Wallet not initialized");
@@ -61,12 +61,12 @@ export async function triggerTransfer(
6161
}
6262

6363
let activeAccountSeedPhrase = state.accountSeeds.get(state.activeAccount) || "";
64-
64+
6565
let proposal = await state.webWallet?.propose_transfer(state.activeAccount, toAddress, amount);
6666
console.log(JSON.stringify(proposal.describe(), null, 2));
67-
67+
6868
let txids = await state.webWallet.create_proposed_transactions(proposal, activeAccountSeedPhrase);
6969
console.log(JSON.stringify(txids, null, 2));
70-
70+
7171
await state.webWallet.send_authorized_transactions(txids);
7272
}

0 commit comments

Comments
 (0)