-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from ChainSafe/willem/demo-wallet
Demo Web Wallet Implementation
- Loading branch information
Showing
34 changed files
with
3,251 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
node_modules | ||
.DS_STORE | ||
.idea | ||
.parcel-cache | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"rust-analyzer.workspace.discoverConfig": null, | ||
"rust-analyzer.cargo.features": "all" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,17 @@ | ||
{ | ||
"name": "webzjs", | ||
"workspaces": ["packages/*"] | ||
} | ||
"scripts": { | ||
"preinstall": "npx only-allow pnpm", | ||
"start:dev": "parcel --no-autoinstall packages/demo-wallet", | ||
"build": "parcel build --no-cache --no-autoinstall packages/demo-wallet" | ||
}, | ||
"dependencies": { | ||
"@webzjs/webz-core": "workspace:^", | ||
"@webzjs/demo-wallet": "workspace:^" | ||
}, | ||
"devDependencies": { | ||
"@parcel/core": "^2.12.0", | ||
"parcel": "^2.12.0", | ||
"process": "^0.11.10" | ||
}, | ||
"packageManager": "[email protected]+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.pnp.* | ||
.yarn/* | ||
!.yarn/patches | ||
!.yarn/plugins | ||
!.yarn/releases | ||
!.yarn/sdks | ||
!.yarn/versions | ||
|
||
dist | ||
.parcel-cache | ||
wasm-pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = function (app) { | ||
app.use((req, res, next) => { | ||
res.setHeader("Cross-Origin-Opener-Policy", "same-origin"); | ||
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp"); | ||
next(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# WebZjs Demo Web Wallet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "@webzjs/demo-wallet", | ||
"source": "src/index.html", | ||
"dependencies": { | ||
"@types/react": "^18.3.9", | ||
"@types/react-dom": "^18.3.0", | ||
"@webzjs/webz-core": "workspace:^", | ||
"bootstrap": "^5.3.3", | ||
"react": "^18.2.0", | ||
"react-bootstrap": "^2.10.4", | ||
"react-dom": "^18.2.0", | ||
"react-toastify": "^10.0.5", | ||
"typescript": "^5.6.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import initWasm, { initThreadPool, WebWallet } from "@webzjs/webz-core"; | ||
|
||
import { State, Action } from "./App"; | ||
import { MAINNET_LIGHTWALLETD_PROXY } from "./constants"; | ||
|
||
export async function init(dispatch: React.Dispatch<Action>) { | ||
await initWasm(); | ||
await initThreadPool(10); | ||
dispatch({ | ||
type: "set-web-wallet", | ||
payload: new WebWallet("main", MAINNET_LIGHTWALLETD_PROXY, 1), | ||
}); | ||
} | ||
|
||
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 }); | ||
await syncStateWithWallet(state, dispatch); | ||
} | ||
|
||
export async function syncStateWithWallet( | ||
state: State, | ||
dispatch: React.Dispatch<Action> | ||
) { | ||
if (!state.webWallet) { | ||
throw new Error("Wallet not initialized"); | ||
} | ||
let summary = await state.webWallet?.get_wallet_summary(); | ||
if (summary) { | ||
dispatch({ type: "set-summary", payload: summary }); | ||
} | ||
let chainHeight = await state.webWallet?.get_latest_block(); | ||
if (chainHeight) { | ||
dispatch({ type: "set-chain-height", payload: chainHeight }); | ||
} | ||
dispatch({ type: "set-active-account", payload: summary?.account_balances[0][0] }); | ||
} | ||
|
||
export async function triggerRescan( | ||
state: State, | ||
dispatch: React.Dispatch<Action> | ||
) { | ||
if (!state.webWallet) { | ||
throw new Error("Wallet not initialized"); | ||
} | ||
await state.webWallet?.sync2(); | ||
await syncStateWithWallet(state, dispatch); | ||
} | ||
|
||
export async function triggerTransfer( | ||
state: State, | ||
dispatch: React.Dispatch<Action>, | ||
toAddress: string, | ||
amount: bigint | ||
) { | ||
if (!state.webWallet) { | ||
throw new Error("Wallet not initialized"); | ||
} | ||
if (state.activeAccount == null) { | ||
throw new Error("No active account"); | ||
} | ||
|
||
await state.webWallet?.transfer(state.accountSeeds[state.activeAccount], state.activeAccount, toAddress, amount); | ||
await syncStateWithWallet(state, dispatch); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* Style inputs */ | ||
input, select, button { | ||
width: 100%; | ||
padding: 12px 20px; | ||
margin: 8px 0; | ||
display: inline-block; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
box-sizing: border-box; | ||
} |
Oops, something went wrong.