Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Re-work the account types (seedIdentifier, derivationMode) (#84)
Browse files Browse the repository at this point in the history
Re-work the account types (seedIdentifier, derivationMode) and many other changes

* update test snapshots

* Refactor bridgestream to its strict minimum

* also export seedIdentifier and derivationMode

* Add getAccountPlaceholderName utilities

* Delete account model (move to desktop)

* Add sortAccounts utility

* update accountId format

* add utility functions

* fix the datamodel migration ^_^

* include the currencyId back in the accountId because collisions

possible collision is ETC using ethM derivation (which is basically the unsplit equivalent but in eth mew)
safer to always have currencyId as part of id for now

* Bugfix

* Move helpers/* to src/*, add some common code

* Fixes

* v4.0.0-beta.1
  • Loading branch information
gre authored Oct 12, 2018
1 parent 2b058c3 commit dfe82d7
Show file tree
Hide file tree
Showing 46 changed files with 849 additions and 1,358 deletions.
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[ignore]
<PROJECT_ROOT>/lib
<PROJECT_ROOT>/demo
<PROJECT_ROOT>/scripts

[include]

Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/live-common",
"version": "3.8.0",
"version": "4.0.0-beta.1",
"main": "lib/index.js",
"license": "MIT",
"scripts": {
Expand All @@ -17,7 +17,9 @@
"files": [
"lib",
"src",
"flow"
"flow",
"*.js",
".flowconfig"
],
"jest": {
"setupFiles": [
Expand All @@ -33,6 +35,7 @@
"numeral": "^2.0.6",
"prando": "^3.0.1",
"react": "^16.4.0",
"react-i18next": "^8.0.7",
"react-redux": "^5.0.7",
"redux": "^4.0.0",
"reselect": "^3.0.1"
Expand Down
1 change: 1 addition & 0 deletions react.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @flow
module.exports = require("./lib/react");
1 change: 1 addition & 0 deletions reactNative.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// @flow
module.exports = require("./lib/reactNative");
6 changes: 1 addition & 5 deletions src/DataModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ export function createDataModel<R, M>(
function decodeModel(raw) {
let data = raw.data;
for (let i = raw.version; i < version; i++) {
// we need to migrate for entering version (i+1)
const newVersion = i + 1;
if (newVersion in migrations) {
data = migrations[newVersion](data);
}
data = migrations[i](data);
}
data = decode(data);
return data;
Expand Down
10 changes: 0 additions & 10 deletions src/__tests__/bridgestream/__snapshots__/exporter.js.snap

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`import 1`] = `
exports[`encode/decode 1`] = `
Object {
"accounts": Array [
Object {
"balance": "1797257488",
"currencyId": "zcash",
"id": "mock_account_export_0",
"derivationMode": "",
"id": "mock:1:zcash:export_0:",
"index": 1,
"name": "PcbUsj9a5mnpn6wT6InSD9n",
"seedIdentifier": "mock",
},
Object {
"balance": "38657242",
"currencyId": "zcoin",
"id": "mock_account_export_1",
"derivationMode": "",
"id": "mock:1:zcoin:export_1:",
"index": 1,
"name": "rv6RjflCC8",
"seedIdentifier": "mock",
},
Object {
"balance": "80627416",
"currencyId": "zencash",
"id": "mock_account_export_2",
"derivationMode": "",
"id": "mock:1:zencash:export_2:",
"index": 1,
"name": "f9mx3pw3IAcuP7ovSPao6EQ",
"seedIdentifier": "mock",
},
],
"meta": Object {
Expand Down
24 changes: 0 additions & 24 deletions src/__tests__/bridgestream/exporter.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// @flow
import { makeChunks } from "../../bridgestream/exporter";
import { encode, decode } from "../../cross";
import shuffle from "lodash/shuffle"
import {
parseChunksReducer,
areChunksComplete,
chunksToResult
} from "../../bridgestream/importer";
import { genAccount } from "../../mock/account";

test("import", () => {
test("encode/decode", () => {
const accounts = Array(3)
.fill(null)
.map((_, i) => genAccount("export_" + i));
Expand All @@ -27,18 +22,8 @@ test("import", () => {
exporterVersion: "0.0.0",
chunkSize: 100
};
const chunks = makeChunks(arg);

let data = [];
shuffle(chunks).forEach((chunk, i) => {
expect(areChunksComplete(data)).toBe(false);
data = parseChunksReducer(data, chunk, console);
expect(data.length).toBe(i + 1);
data = parseChunksReducer(data, chunk, console);
expect(data.length).toBe(i + 1); // chunk already existed
});
expect(areChunksComplete(data)).toBe(true);
const res = chunksToResult(data);
const data = encode(arg);
const res = decode(data);
expect(res.accounts).toMatchObject(
accounts.map(a => ({
balance: a.balance.toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/helpers/BigNumberToLocaleString.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow

import { BigNumber } from "bignumber.js";
import { toLocaleString } from "../../helpers/currencies/BigNumberToLocaleString";
import { toLocaleString } from "../../currencies/BigNumberToLocaleString";

test("basic toLocaleString usage", () => {
expect(toLocaleString(BigNumber(0))).toBe("0");
Expand Down
Loading

0 comments on commit dfe82d7

Please sign in to comment.