on master help sign in
invites: fix wallet gen web worker
1585090tomholford
src/lib/walletgen.js+9−6
@@ -16,8 +16,8 @@ import {
16} from './constants';
16} from './constants';
17import { stripHexPrefix } from './utils/address';
17import { stripHexPrefix } from './utils/address';
18
18
19−const worker = wrap(
19+const WalletGenerator = wrap(
20− new Worker('../worker/worker.js', { type: 'module' })
20+ new Worker('src/worker/worker.ts', { type: 'module' })
21);
21);
22
22
23const SEED_LENGTH_BYTES = SEED_ENTROPY_BITS / 8;
23const SEED_LENGTH_BYTES = SEED_ENTROPY_BITS / 8;
@@ -85,11 +85,14 @@ export const generateWallet = async (point, ticket, boot, revision = 0) => {
85 // hangs, blocking UI updates so this cannot be done in the UI
85 // hangs, blocking UI updates so this cannot be done in the UI
86 console.log('Generating Wallet for point address: ', point);
86 console.log('Generating Wallet for point address: ', point);
87
87
88− return new Promise(async resolve => {
88+ return new Promise(async (resolve, reject) => {
89 // Use a web worker to process the data
89 // Use a web worker to process the data
90+ try {
90− const processed = await worker.generateWallet(JSON.stringify(config));
91+ const processed = await WalletGenerator.generateWallet(JSON.stringify(config));
91−
92− resolve(processed);
92+ resolve(processed);
93+ } catch (error) {
94+ reject(error);
95+ }
93 });
96 });
94};
97};
95
98
src/store/pointCache.jsx+1−1
@@ -15,7 +15,7 @@ import usePointStore from './lib/usePointStore';
15const initialContext = {
15const initialContext = {
16 details: Nothing(),
16 details: Nothing(),
17 rekeyDates: Nothing(),
17 rekeyDates: Nothing(),
18− controlledPoints: Just(Result.Error('not yet loaded')),
18+ controlledPoints: Nothing(),
19 ecliptic: Nothing(),
19 ecliptic: Nothing(),
20 residents: Nothing(),
20 residents: Nothing(),
21 pointCursor: Nothing(),
21 pointCursor: Nothing(),
src/worker/WalletGenerator.tsnew file+13
@@ -0,0 +1,13 @@
1+import kg from 'urbit-key-generation';
2+
3+export const WalletGenerator = {
4+ async generateWallet(data: string): Promise<UrbitWallet> {
5+ // Process the data without stalling the UI
6+ const config = JSON.parse(data);
7+ const wallet = await kg.generateWallet(config);
8+
9+ return wallet;
10+ },
11+}
12+
13+export default WalletGenerator;
src/worker/generateWalletWorker.tsdeleted−9
@@ -1,9 +0,0 @@
1−import kg from 'urbit-key-generation';
2−
3−export async function generateWallet(data: string): Promise<UrbitWallet> {
4− // Process the data without stalling the UI
5− const config = JSON.parse(data);
6− const wallet = await kg.generateWallet(config);
7−
8− return wallet;
9−}
src/worker/worker.ts+2−2
@@ -1,4 +1,4 @@
1import { expose } from "comlink";
1import { expose } from "comlink";
2−import { generateWallet } from './generateWalletWorker';
2+import { WalletGenerator } from './WalletGenerator';
3
3
4−expose(generateWallet);
4+expose(WalletGenerator);