Skip to content

Commit fcb9d47

Browse files
authored
Merge pull request #45 from jpcapurro-atixlabs/integrate-js-bindings
Integrate js bindings
2 parents 0d04de5 + 6667823 commit fcb9d47

File tree

4 files changed

+63
-36
lines changed

4 files changed

+63
-36
lines changed

examples/wallet/README.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,46 @@ This is a light wallet, it does not run its own node, and depends on one running
66
The node address will be configurable in the future 🙃
77

88
## development tools
9-
* `npm run dev`: to run the app with a debugger
10-
* `npm run lint`: lint js files with eslint
11-
* `npm run lint-styles`: lint css files with stylelint
12-
* `npm run flow`: check [flow](https://flow.org/) type annotations
9+
10+
- `yarn install`: install dependencies
11+
- `yarn dev`: to run the app with a debugger
12+
- `yarn lint`: lint js files with eslint
13+
- `yarn lint-styles`: lint css files with stylelint
14+
- `yarn flow`: check [flow](https://flow.org/) type annotations
15+
16+
To run the application in development mode, first install the dependencies with
17+
`yarn install` and then run it with `yarn dev`.
18+
19+
To build an appimage package, first install the dependencies with
20+
`yarn install` and then package the app with `yarn package-{linux,win}`
1321

1422
## TODO
23+
1524
- [ x ] show the balance of a given address
16-
- [ ] verify the validity of an address before making a request to the a node (js bindings will be added here, ideally, before tackling any more complex issues such as creating transactione)
17-
- [ ] let the user use its private key.
18-
- [ ] prompt the user for its private key, ideally locking parts of the app until a valid one is inserted
19-
- [ ] bip39?
20-
- [ ] send account-based transactions
21-
- [ ] UI
22-
- [ ] verify validity of the recipient's address
23-
- [ ] update sender's account counter
24-
- [ ] generate transaction
25-
- [ ] add output
26-
- [ ] add witness
27-
- [ ] broadcast transaction
28-
- [ ] locally store the user's private key
29-
- [ ] define a password schema for unlocking the app (so the funds are secure if the user's device is used by someone else)
30-
- [ ] define a password schema for encrypting the private keys(so the funds are secure if the device's storage is compromised)
31-
- [ ] view mode?
32-
- [ ] list user transactions and their status?
25+
- [ ] verify the validity of an address before making a request to the a node (js bindings will be added here, ideally, before tackling any more complex issues such as creating transactione)
26+
- [ x ] add js-chain-libs bindings
27+
- [ ] handle errors in address format
28+
- [ ] let the user use its private key.
29+
- [ ] prompt the user for its private key, ideally locking parts of the app until a valid one is inserted
30+
- [ ] bip39?
31+
- [ ] send account-based transactions
32+
- [ ] UI
33+
- [ ] verify validity of the recipient's address
34+
- [ ] update sender's account counter
35+
- [ ] generate transaction
36+
- [ ] add output
37+
- [ ] add witness
38+
- [ ] broadcast transaction
39+
- [ ] locally store the user's private key
40+
- [ ] define a password schema for unlocking the app (so the funds are secure if the user's device is used by someone else)
41+
- [ ] define a password schema for encrypting the private keys(so the funds are secure if the device's storage is compromised)
42+
- [ ] view mode?
43+
- [ ] list user transactions and their status?
44+
45+
## Tech debt
46+
47+
- [ ] extract flow types from the js-chain-libs with [flowtype](https://github.com/joarwilk/flowgen), and have a module that exports them and abstracts the initialization of the wasm
48+
- [ ] research: Is the mechanism for importing wasm smart enough to not load it
49+
several times into memory if it is imported in more than one place?
50+
- [ ] if it is not, have the aforementioned module take care of
51+
initializing it only one time.
Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
// @flow
22
import type { Dispatch } from 'redux';
33
import { getBalance } from '../utils/nodeConnection';
4-
import { Address, Balance } from '../models';
4+
5+
const wasmBindings = import('js-chain-libs/js_chain_libs');
56

67
export const SET_ADDRESS = 'SET_ADDRESS';
78

89
export type SetAddressAction = {
910
type: 'SET_ADDRESS',
10-
address: Address,
11-
balance: Balance
11+
address: string,
12+
balance: string
1213
};
1314

14-
export function setAddress(address: string) {
15+
export function setAddress(addressStr: string) {
1516
return function setAddressAndRefreshBalance(
1617
dispatch: Dispatch<SetAddressAction>
1718
) {
18-
// FIXME: we should add the logic to convert from the address to the accountId.
19-
// currently, it only works if the accountId is passed instead.
20-
return getBalance(address).then(balance =>
21-
dispatch({
22-
type: SET_ADDRESS,
23-
address,
24-
balance
19+
return wasmBindings
20+
.then(({ Account, Address }) => {
21+
const address = Address.from_string(addressStr);
22+
const accountId = Account.from_address(address)
23+
.to_identifier()
24+
.to_hex();
25+
return getBalance(accountId);
2526
})
26-
);
27+
.then(balance =>
28+
dispatch({
29+
type: SET_ADDRESS,
30+
address: addressStr,
31+
balance
32+
})
33+
);
2734
};
2835
}

examples/wallet/app/components/AddressInfo.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export default ({ setAddress, balance, address }: Props) => {
1717
<div>
1818
<form onSubmit={handleSubmit}>
1919
<label htmlFor="address">
20-
{/* FIXME: get the address here and compute the accountId from it somewhere else */}
21-
accountId:
20+
Address:
2221
<input
2322
type="text"
2423
name="address"
@@ -28,7 +27,7 @@ export default ({ setAddress, balance, address }: Props) => {
2827
</label>
2928
<input type="submit" value="Get balance!" />
3029
</form>
31-
<p>Current Account Id: {address}</p>
30+
<p>Current Address: {address}</p>
3231
<p>Balance: {balance}</p>
3332
</div>
3433
);

examples/wallet/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"files": [
6262
"app/dist/",
6363
"app/app.html",
64+
"node_modules/js-chain-libs/js_chain_libs_bg.wasm",
6465
"app/main.prod.js",
6566
"app/main.prod.js.map",
6667
"package.json"
@@ -268,6 +269,7 @@
268269
"electron-log": "3.0.4",
269270
"electron-updater": "4.0.6",
270271
"history": "4.9.0",
272+
"js-chain-libs": "0.1.2",
271273
"react": "16.8.6",
272274
"react-dom": "16.8.6",
273275
"react-hot-loader": "4.8.2",

0 commit comments

Comments
 (0)