From 329bcd291e335be307f4b3f2b743c3dbac2b3cdb Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 14 Sep 2020 22:26:28 +0200 Subject: [PATCH] Ledger derivation (account/address indexes) (#3680) * Ledger derivation (account/address indexes) * Fix API version --- package.json | 6 +- .../apps/public/locales/ar/translation.json | 4 +- .../apps/public/locales/en/app-accounts.json | 4 +- .../apps/public/locales/en/translation.json | 4 +- .../apps/public/locales/es/translation.json | 4 +- .../apps/public/locales/id/translation.json | 4 +- .../apps/public/locales/it/translation.json | 4 +- .../apps/public/locales/ja/translation.json | 4 +- .../apps/public/locales/ko/translation.json | 4 +- .../apps/public/locales/pt/translation.json | 4 +- .../apps/public/locales/ru/translation.json | 4 +- .../apps/public/locales/zh/translation.json | 4 +- .../page-accounts/src/Accounts/Account.tsx | 4 +- packages/page-accounts/src/Accounts/index.tsx | 25 +-- packages/page-accounts/src/modals/Ledger.tsx | 121 +++++++++++++ packages/page-contracts/package.json | 2 +- packages/react-api/package.json | 2 +- packages/react-components/package.json | 8 +- yarn.lock | 164 +++++++++--------- 19 files changed, 244 insertions(+), 132 deletions(-) create mode 100644 packages/page-accounts/src/modals/Ledger.tsx diff --git a/package.json b/package.json index 7a5ba281ea..51ff474da1 100644 --- a/package.json +++ b/package.json @@ -33,10 +33,10 @@ "afterSign": "electron-builder-notarize" }, "resolutions": { - "@polkadot/api": "^1.34.0-beta.2", - "@polkadot/api-contract": "^1.34.0-beta.2", + "@polkadot/api": "^1.33.1", + "@polkadot/api-contract": "^1.33.1", "@polkadot/keyring": "^3.4.1", - "@polkadot/types": "^1.34.0-beta.2", + "@polkadot/types": "^1.33.1", "@polkadot/util": "^3.4.1", "@polkadot/util-crypto": "^3.4.1", "@polkadot/wasm-crypto": "^1.4.1", diff --git a/packages/apps/public/locales/ar/translation.json b/packages/apps/public/locales/ar/translation.json index 709a90d92b..c1da0f8669 100644 --- a/packages/apps/public/locales/ar/translation.json +++ b/packages/apps/public/locales/ar/translation.json @@ -371,7 +371,7 @@ "Proxied": "بروكسيد", "Proxied account has no owned proxies": "حساب بروكسي ليس لديه بروكسيات مملوكة", "Proxy overview": "نظرة عامة الوكيل", - "Query Ledger": "الاستعلام عن اللدجر", + "Add Ledger": "الاستعلام عن اللدجر", "RPC calls": "استدعاء إجراء مكالمة عن بُعد", "Random": "عشوائي", "Raw seed": "البذرة المسودة", @@ -1277,4 +1277,4 @@ "{{threshold}}, not passing": "سقف}}، لا يتم تمريره}}", "{{threshold}}, passing": "سقف}}، يتم تمريره}}", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "({{قفل}} (تاريخ إصدار {{أيام}}x رصيد التصويت، مقفل لـ x {{قيمة }}" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/en/app-accounts.json b/packages/apps/public/locales/en/app-accounts.json index 162f0f92de..15bac6737a 100644 --- a/packages/apps/public/locales/en/app-accounts.json +++ b/packages/apps/public/locales/en/app-accounts.json @@ -104,7 +104,7 @@ "Proxied": "Proxied", "Proxied account has no owned proxies": "Proxied account has no owned proxies", "Proxy overview": "Proxy overview", - "Query Ledger": "Query Ledger", + "Add Ledger": "Add Ledger", "Raw seed": "Raw seed", "Reasonable": "Reasonable", "Register identity": "Register identity", @@ -296,4 +296,4 @@ "website": "website", "your current password": "your current password", "your new password": "your new password" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/en/translation.json b/packages/apps/public/locales/en/translation.json index 4a84c0efd5..71d6445bda 100644 --- a/packages/apps/public/locales/en/translation.json +++ b/packages/apps/public/locales/en/translation.json @@ -346,7 +346,7 @@ "Propose tip": "", "Provide judgement": "", "Provide the account QR from the module/external application for scanning. One detected as valid, you will be taken to the next step to add the account to your list.": "", - "Query Ledger": "", + "Add Ledger": "", "RPC calls": "", "Random": "", "Raw seed": "", @@ -1179,4 +1179,4 @@ "{{threshold}}, not passing": "", "{{threshold}}, passing": "", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/es/translation.json b/packages/apps/public/locales/es/translation.json index 2b479de129..7445eb143e 100644 --- a/packages/apps/public/locales/es/translation.json +++ b/packages/apps/public/locales/es/translation.json @@ -308,7 +308,7 @@ "Propose tip": "Proponer gratificación", "Provide judgement": "Juicio proporcionado", "Provide the account QR from the module/external application for scanning. One detected as valid, you will be taken to the next step to add the account to your list.": "Proporcionar el QR de la cuenta del módulo/aplicación externa para el análisis. Una vez detectada como válida, se le llevará al siguiente paso para añadir la cuenta a su lista.", - "Query Ledger": "Consultar el libro de cuentas", + "Add Ledger": "Consultar el libro de cuentas", "RPC calls": "llamadas RPC", "Random": "Aleatorio", "Raw seed": "Semillas en bruto", @@ -1115,4 +1115,4 @@ "{{threshold}}, not passing": "{{threshold}}, no pasará", "{{threshold}}, passing": "{{threshold}}, de aprobación", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "{{value}}x saldo de votos, bloqueado por {{lock}}x sentencia ({{period}} días." -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/id/translation.json b/packages/apps/public/locales/id/translation.json index cdcbae3623..59310982af 100644 --- a/packages/apps/public/locales/id/translation.json +++ b/packages/apps/public/locales/id/translation.json @@ -424,7 +424,7 @@ "Proxied": "Proxy", "Proxied account has no owned proxies": "Akun proxy tidak memiliki proxy", "Proxy overview": "Ringkasan proxy", - "Query Ledger": "Query Ledger", + "Add Ledger": "Add Ledger", "RPC calls": "pemanggilan RPC", "Random": "Acak", "Raw seed": "Benih raw", @@ -1432,4 +1432,4 @@ "{{threshold}}, not passing": "{{threshold}}, tidak melewati", "{{threshold}}, passing": "{{threshold}}, melewati", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "{{value}}x memilih saldo, terkunci untuk {{lock}}x berlaku ({{period}} hari)" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/it/translation.json b/packages/apps/public/locales/it/translation.json index 915127af77..306e99c279 100644 --- a/packages/apps/public/locales/it/translation.json +++ b/packages/apps/public/locales/it/translation.json @@ -416,7 +416,7 @@ "Proxied": "Proxy", "Proxied account has no owned proxies": "L'account scelto non possiede proxy", "Proxy overview": "Riepilogo Proxy", - "Query Ledger": "Connetti il Ledger", + "Add Ledger": "Connetti il Ledger", "RPC calls": "Chiamata RPC", "Random": "Casuale", "Raw seed": "Raw Seed", @@ -1391,4 +1391,4 @@ "{{threshold}}, not passing": "{{threshold}}, respinta", "{{threshold}}, passing": "{{threshold}}, approvato", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "{{value}} x moltiplicatore di voto, fondi bloccati per {{lock}}x = {{period}} giorni" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/ja/translation.json b/packages/apps/public/locales/ja/translation.json index 01383c077f..2187e40906 100644 --- a/packages/apps/public/locales/ja/translation.json +++ b/packages/apps/public/locales/ja/translation.json @@ -186,7 +186,7 @@ "Propose a council motion": "カウンシルモーションを提出する", "Provide judgement": "ジャッジメントを提供する", "Provide the account QR from the module/external application for scanning. One detected as valid, you will be taken to the next step to add the account to your list.": "スキャンするためにモジュール/外部アプリケーションからアカウントのQRを提供します。有効として検出された場合、次のステップに移行しあなたのリストにアカウントが追加されます。", - "Query Ledger": "クエリーレッジャー", + "Add Ledger": "クエリーレッジャー", "RPC calls": "RPCコール", "Raw seed": "生のシード", "Raw storage": "生のストレージ", @@ -564,4 +564,4 @@ "{{relayDispatchQueueSize}} dispatch messages pending": "{{relayDispatchQueueSize}} ディスパッチメッセージペンディング", "{{seconds}} s": "{{seconds}} 秒", "{{step}}. Sign with your ETH address": "{{step}}. ETHアドレスでサインしてください" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/ko/translation.json b/packages/apps/public/locales/ko/translation.json index 14fc82461c..68ec5c3a6e 100644 --- a/packages/apps/public/locales/ko/translation.json +++ b/packages/apps/public/locales/ko/translation.json @@ -104,7 +104,7 @@ "Proxied": "프록시 된", "Proxied account has no owned proxies": "프록시 계정에 소유하고 있는 프록시가 없음", "Proxy overview": "프록시 개요", - "Query Ledger": "Ledger 조회", + "Add Ledger": "Ledger 조회", "Raw seed": "시드 문구", "Reasonable": "적합한", "Register identity": "신원 인증/등록하기", @@ -301,4 +301,4 @@ "website": "website", "your current password": "현재 비밀번호", "your new password": "새로운 비밀번호" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/pt/translation.json b/packages/apps/public/locales/pt/translation.json index 1167de7782..0c8095b034 100644 --- a/packages/apps/public/locales/pt/translation.json +++ b/packages/apps/public/locales/pt/translation.json @@ -308,7 +308,7 @@ "Propose tip": "Propor gorjeta", "Provide judgement": "Fornecer julgamento", "Provide the account QR from the module/external application for scanning. One detected as valid, you will be taken to the next step to add the account to your list.": "Forneça o QR da conta no módulo/aplicativo externo para digitalização. Se for detectado como válido, você será levado para a próxima etapa para adicionar a conta à sua lista.", - "Query Ledger": "Livro de consultas", + "Add Ledger": "Livro de consultas", "RPC calls": "Chamadas RPC", "Random": "Aleatória", "Raw seed": "Semente bruta", @@ -1122,4 +1122,4 @@ "{{threshold}}, not passing": "{{threshold}}, não passando", "{{threshold}}, passing": "{{threshold}}, passando", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "{{value}} x saldo de votos, bloqueado por {{lock}} x promulgação ({{period}} dias)" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/ru/translation.json b/packages/apps/public/locales/ru/translation.json index bd9fd158e4..de85675ae0 100644 --- a/packages/apps/public/locales/ru/translation.json +++ b/packages/apps/public/locales/ru/translation.json @@ -314,7 +314,7 @@ "Propose tip": "Предложить чаевые", "Provide judgement": "Сделать оценку", "Provide the account QR from the module/external application for scanning. One detected as valid, you will be taken to the next step to add the account to your list.": "Предоставьте QR-код аккаунта из модуля/внешнего приложения для сканирования. Когда он будет правильным, Вы перейдете к следующему шагу, чтобы добавить учетную запись в свой список.", - "Query Ledger": "Книга запросов", + "Add Ledger": "Книга запросов", "RPC calls": "RPC вызовы", "Random": "Случайный", "Raw seed": "Исходная секретная фраза", @@ -1133,4 +1133,4 @@ "{{threshold}}, not passing": "{{threshold}}, не проходит", "{{threshold}}, passing": "{{threshold}}, проходит", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "{{value}}x баланс голосования, заблокировано на {{lock}}x ({{period}} дней)" -} \ No newline at end of file +} diff --git a/packages/apps/public/locales/zh/translation.json b/packages/apps/public/locales/zh/translation.json index 0c337f23b1..6673b02500 100644 --- a/packages/apps/public/locales/zh/translation.json +++ b/packages/apps/public/locales/zh/translation.json @@ -413,7 +413,7 @@ "Proxied": "代理", "Proxied account has no owned proxies": "代理帐户没有自己的代理", "Proxy overview": "代理概览", - "Query Ledger": "查询账本", + "Add Ledger": "查询账本", "RPC calls": "RPC 调用", "Random": "随机生成颜色", "Raw seed": "原始种子", @@ -1380,4 +1380,4 @@ "{{threshold}}, not passing": "{{threshold}},没有通过", "{{threshold}}, passing": "{{threshold}}, 通过", "{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)": "{{value}}x投票余额,锁定 {{lock}}x 执行 ({{period}} days)" -} \ No newline at end of file +} diff --git a/packages/page-accounts/src/Accounts/Account.tsx b/packages/page-accounts/src/Accounts/Account.tsx index 63f91e9c26..97cdf50537 100644 --- a/packages/page-accounts/src/Accounts/Account.tsx +++ b/packages/page-accounts/src/Accounts/Account.tsx @@ -190,12 +190,12 @@ function Account ({ account: { address, meta }, className = '', delegation, filt // for now we are always assuming hardwareType === 'ledger' (): void => { getLedger() - .getAddress(true) + .getAddress(true, meta.accountOffset as number || 0, meta.addressOffset as number || 0) .catch((error): void => { console.error(`ledger: ${(error as Error).message}`); }); }, - [] + [meta] ); if (!isVisible) { diff --git a/packages/page-accounts/src/Accounts/index.tsx b/packages/page-accounts/src/Accounts/index.tsx index de425f0ee4..14532c7a36 100644 --- a/packages/page-accounts/src/Accounts/index.tsx +++ b/packages/page-accounts/src/Accounts/index.tsx @@ -9,8 +9,7 @@ import { Delegation, SortedAccount } from '../types'; import BN from 'bn.js'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import styled from 'styled-components'; -import keyring from '@polkadot/ui-keyring'; -import { getLedger, isLedger } from '@polkadot/react-api'; +import { isLedger } from '@polkadot/react-api'; import { useApi, useAccounts, useCall, useFavorites, useIpfs, useLoadingDelay, useToggle } from '@polkadot/react-hooks'; import { FormatBalance } from '@polkadot/react-query'; import { Button, Input, Table } from '@polkadot/react-components'; @@ -19,6 +18,7 @@ import { BN_ZERO } from '@polkadot/util'; import { useTranslation } from '../translate'; import CreateModal from '../modals/Create'; import ImportModal from '../modals/Import'; +import Ledger from '../modals/Ledger'; import Multisig from '../modals/MultisigCreate'; import Proxy from '../modals/ProxiedAdd'; import Qr from '../modals/Qr'; @@ -44,19 +44,6 @@ interface Props { const STORE_FAVS = 'accounts:favorites'; -// query the ledger for the address, adding it to the keyring -async function queryLedger (): Promise { - const ledger = getLedger(); - - try { - const { address } = await ledger.getAddress(); - - keyring.addHardware(address, 'ledger', { name: 'ledger' }); - } catch (error) { - console.error(error); - } -} - function Overview ({ className = '', onStatusChange }: Props): React.ReactElement { const { t } = useTranslation(); const { api } = useApi(); @@ -64,6 +51,7 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen const { isIpfs } = useIpfs(); const [isCreateOpen, toggleCreate] = useToggle(); const [isImportOpen, toggleImport] = useToggle(); + const [isLedgerOpen, toggleLedger] = useToggle(); const [isMultisigOpen, toggleMultisig] = useToggle(); const [isProxyOpen, toggleProxy] = useToggle(); const [isQrOpen, toggleQr] = useToggle(); @@ -181,6 +169,9 @@ function Overview ({ className = '', onStatusChange }: Props): React.ReactElemen onStatusChange={onStatusChange} /> )} + {isLedgerOpen && ( + + )} {isMultisigOpen && (