-
Notifications
You must be signed in to change notification settings - Fork 1
/
useAddressObjects.js
37 lines (32 loc) · 1.11 KB
/
useAddressObjects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from "react";
import * as RavencoinHandler from "./_ravencoinhandler.js";
import config from "./config";
export function useAddressObjects(mnemonic) {
const [addressObjects, setAddressObjects] = React.useState([]);
//Naive and lazy, derive the first 10 external and internal addresses
const temp = [];
React.useEffect(() => {
if (mnemonic) {
//Generating the hd key is time consuming, so we do it once.
const hdKey = RavencoinHandler.getHDKey(config.network, mnemonic);
for (let position = 0; position < 10; position++) {
const externalPath = "m/44'/175'/0'/0/" + position;
const internalPath = "m/44'/175'/0'/1/" + position;
const external = RavencoinHandler.getAddressByPath(
config.network,
hdKey,
externalPath
);
const internal = RavencoinHandler.getAddressByPath(
config.network,
hdKey,
internalPath
);
temp.push(external);
temp.push(internal);
}
}
setAddressObjects(temp);
}, [mnemonic]); //run when mnemonic change
return addressObjects;
}