on master help sign in
Refactor account options generation for hardware wallets
8b8b3eeFang
src/views/Login/Ledger.js+5−7
@@ -1,5 +1,6 @@
1import * as bip32 from 'bip32';
1import * as bip32 from 'bip32';
2import React, { useState } from 'react';
2import React, { useState } from 'react';
3+import { times } from 'lodash';
3import Maybe from 'folktale/maybe';
4import Maybe from 'folktale/maybe';
4import Transport from '@ledgerhq/hw-transport-u2f';
5import Transport from '@ledgerhq/hw-transport-u2f';
5import Eth from '@ledgerhq/hw-app-eth';
6import Eth from '@ledgerhq/hw-app-eth';
@@ -67,13 +68,10 @@ export default function Ledger({ loginCompleted }) {
67 ];
68 ];
68 const basePathTitle = pathOptions.find(o => o.value === basePath).title;
69 const basePathTitle = pathOptions.find(o => o.value === basePath).title;
69
70
70− let accountOptions = [];
71+ const accountOptions = times(20, i => ({
71− for (let i = 0; i < 20; i++) {
72− accountOptions.push({
73− title: 'Account #' + (i + 1),
72+ title: `Account #${i + 1}`,
74− value: i,
73+ value: i,
75− });
74+ }));
76− }
77 const accountTitle = accountOptions.find(o => o.value === account).title;
75 const accountTitle = accountOptions.find(o => o.value === account).title;
78
76
79 const basePathSelection = (
77 const basePathSelection = (
src/views/Login/Trezor.js+4−6
@@ -1,6 +1,7 @@
1import * as bip32 from 'bip32';
1import * as bip32 from 'bip32';
2import React, { useState } from 'react';
2import React, { useState } from 'react';
3import Maybe from 'folktale/maybe';
3import Maybe from 'folktale/maybe';
4+import { times } from 'lodash';
4import TrezorConnect from 'trezor-connect';
5import TrezorConnect from 'trezor-connect';
5import * as secp256k1 from 'secp256k1';
6import * as secp256k1 from 'secp256k1';
6
7
@@ -46,12 +47,9 @@ export default function Trezor({ loginCompleted }) {
46 };
47 };
47
48
48 let accountOptions = [{ title: 'Custom path', value: 'custom' }];
49 let accountOptions = [{ title: 'Custom path', value: 'custom' }];
49− for (let i = 0; i < 20; i++) {
50+ times(20, i => {
50− accountOptions.push({
51+ accountOptions.push({ title: `Account #${i + 1}`, value: i });
51− title: 'Account #' + (i + 1),
52− value: i,
53− });
54− }
52+ });
55 let accountTitle = accountOptions.find(o => o.value === account).title;
53 let accountTitle = accountOptions.find(o => o.value === account).title;
56
54
57 const accountSelection = (
55 const accountSelection = (