1
- import initWasm , { initThreadPool , WebWallet } from "@webzjs/webz-core" ;
1
+ import initWasm , { initThreadPool , WebWallet } from "@webzjs/webz-core" ;
2
2
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" ;
5
5
6
6
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
+ } ) ;
13
13
}
14
14
15
15
export async function addNewAccount ( state : State , dispatch : React . Dispatch < Action > , seedPhrase : string , birthdayHeight : number ) {
16
16
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 ] } ) ;
18
18
await syncStateWithWallet ( state , dispatch ) ;
19
19
}
20
20
21
21
export async function syncStateWithWallet (
22
- state : State ,
23
- dispatch : React . Dispatch < Action >
22
+ state : State ,
23
+ dispatch : React . Dispatch < Action >
24
24
) {
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 ] } ) ;
37
37
}
38
38
39
39
export async function triggerRescan (
40
- state : State ,
41
- dispatch : React . Dispatch < Action >
40
+ state : State ,
41
+ dispatch : React . Dispatch < Action >
42
42
) {
43
43
if ( ! state . webWallet ) {
44
44
throw new Error ( "Wallet not initialized" ) ;
45
45
}
46
- await state . webWallet ?. sync2 ( ) ;
46
+ await state . webWallet ?. sync ( ) ;
47
47
await syncStateWithWallet ( state , dispatch ) ;
48
48
}
49
49
50
50
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
55
55
) {
56
56
if ( ! state . webWallet ) {
57
57
throw new Error ( "Wallet not initialized" ) ;
@@ -61,12 +61,12 @@ export async function triggerTransfer(
61
61
}
62
62
63
63
let activeAccountSeedPhrase = state . accountSeeds . get ( state . activeAccount ) || "" ;
64
-
64
+
65
65
let proposal = await state . webWallet ?. propose_transfer ( state . activeAccount , toAddress , amount ) ;
66
66
console . log ( JSON . stringify ( proposal . describe ( ) , null , 2 ) ) ;
67
-
67
+
68
68
let txids = await state . webWallet . create_proposed_transactions ( proposal , activeAccountSeedPhrase ) ;
69
69
console . log ( JSON . stringify ( txids , null , 2 ) ) ;
70
-
70
+
71
71
await state . webWallet . send_authorized_transactions ( txids ) ;
72
72
}
0 commit comments