From 60113cba703076f2f48ed0f80a1979e95f1667b2 Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Wed, 2 Dec 2020 16:21:02 +0100 Subject: [PATCH] fix: second ledger bug, closes #296 --- app/constants/index.ts | 2 + app/modals/stacking/stacking-modal.tsx | 12 +++--- .../stacking/steps/failed-broadcast-error.tsx | 19 --------- app/modals/stacking/steps/stacking-failed.tsx | 36 ++++++++++++++++ app/modals/transaction/transaction-modal.tsx | 9 +++- app/package.json | 1 + .../04-connect-ledger/connect-ledger.tsx | 6 +-- app/yarn.lock | 42 +++++++++---------- jest.config.js | 2 +- 9 files changed, 77 insertions(+), 52 deletions(-) delete mode 100644 app/modals/stacking/steps/failed-broadcast-error.tsx create mode 100644 app/modals/stacking/steps/stacking-failed.tsx diff --git a/app/constants/index.ts b/app/constants/index.ts index b1d4f7bd9..b9c31d3bf 100644 --- a/app/constants/index.ts +++ b/app/constants/index.ts @@ -4,6 +4,8 @@ type Environments = 'development' | 'testing' | 'production'; export const STX_DECIMAL_PRECISION = 6; +export const STX_DERIVATION_PATH = `m/44'/5757'/0'/0/0` as const; + export const ENV = (process.env.NODE_ENV ?? 'production') as Environments; export const BUY_STX_URL = 'https://coinmarketcap.com/currencies/blockstack/markets'; diff --git a/app/modals/stacking/stacking-modal.tsx b/app/modals/stacking/stacking-modal.tsx index 01969054a..b55378ee1 100644 --- a/app/modals/stacking/stacking-modal.tsx +++ b/app/modals/stacking/stacking-modal.tsx @@ -2,7 +2,6 @@ import React, { FC, useState, useCallback } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { Modal } from '@blockstack/ui'; import { useHistory } from 'react-router-dom'; -// import log from 'electron-log'; import BlockstackApp, { LedgerError, ResponseSign } from '@zondax/ledger-blockstack'; import { useHotkeys } from 'react-hotkeys-hook'; import { BigNumber } from 'bignumber.js'; @@ -11,7 +10,7 @@ import { StacksMainnet, StacksTestnet } from '@stacks/network'; import BN from 'bn.js'; import { RootState } from '@store/index'; -import { NETWORK } from '@constants/index'; +import { NETWORK, STX_DERIVATION_PATH } from '@constants/index'; import routes from '@constants/routes.json'; import { selectPublicKey, @@ -42,7 +41,7 @@ import { } from './stacking-modal-layout'; import { DecryptWalletForm } from './steps/decrypt-wallet-form'; import { SignTxWithLedger } from './steps/sign-tx-with-ledger'; -import { FailedBroadcastError } from './steps/failed-broadcast-error'; +import { StackingFailed } from './steps/stacking-failed'; enum StackingModalStep { DecryptWalletAndSend, @@ -173,7 +172,7 @@ export const StackingModal: FC = props => { amountMicroStx: new BN(amountToStack.toString()), }); const resp: ResponseSign = await blockstackApp.sign( - `m/44'/5757'/0'/0/0`, + STX_DERIVATION_PATH, modifiedFeeTx.serialize() ); if (resp.returnCode !== LedgerError.NoErrors) { @@ -234,6 +233,7 @@ export const StackingModal: FC = props => { if (error) { setHasSubmitted(false); + setStep(StackingModalStep.FailedContractCall); return; } @@ -316,7 +316,9 @@ export const StackingModal: FC = props => { [StackingModalStep.FailedContractCall]: () => ({ header: , - body: {'Failed to call stacking contract'}, + body: ( + Failed to call stacking contract + ), footer: ( diff --git a/app/modals/stacking/steps/failed-broadcast-error.tsx b/app/modals/stacking/steps/failed-broadcast-error.tsx deleted file mode 100644 index 658beacd7..000000000 --- a/app/modals/stacking/steps/failed-broadcast-error.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import React, { FC } from 'react'; -import { Flex, Box, Text } from '@blockstack/ui'; - -import failedCrossSvg from '../../../assets/images/failed-cross.svg'; - -export const FailedBroadcastError: FC = ({ children }) => ( - - - - - - Your transaction failed to verify - - - {children || - 'Please make sure you are signing your transaction with the same Ledger or Secret Key used to set up your wallet.'} - - -); diff --git a/app/modals/stacking/steps/stacking-failed.tsx b/app/modals/stacking/steps/stacking-failed.tsx new file mode 100644 index 000000000..b89b5ef54 --- /dev/null +++ b/app/modals/stacking/steps/stacking-failed.tsx @@ -0,0 +1,36 @@ +import React, { FC } from 'react'; +import { Flex, Box, Text } from '@blockstack/ui'; + +import { WalletType } from '../../../types/wallet-type'; +import failedCrossSvg from '../../../assets/images/failed-cross.svg'; + +interface StackingFailedProps { + walletType: WalletType; +} + +export const StackingFailed: FC = ({ children, walletType }) => ( + + + + + + Unable to verify transaction + + {children && ( + + {children} + + )} + {walletType === 'ledger' && ( + + Make sure you're using the same Ledger device you used to create this wallet + + )} + +); diff --git a/app/modals/transaction/transaction-modal.tsx b/app/modals/transaction/transaction-modal.tsx index 782686d0b..e4c6dbc5f 100644 --- a/app/modals/transaction/transaction-modal.tsx +++ b/app/modals/transaction/transaction-modal.tsx @@ -19,7 +19,12 @@ import { useHotkeys } from 'react-hotkeys-hook'; import { safeAwait } from '@utils/safe-await'; import { Api } from '@api/api'; -import { STX_DECIMAL_PRECISION, STX_TRANSFER_TX_SIZE_BYTES } from '@constants/index'; +import { + STX_DECIMAL_PRECISION, + STX_DERIVATION_PATH, + STX_TRANSFER_TX_SIZE_BYTES, +} from '@constants/index'; + import { RootState } from '@store/index'; import routes from '@constants/routes.json'; import { LedgerConnectStep } from '@hooks/use-ledger'; @@ -127,7 +132,7 @@ export const TransactionModal: FC = ({ balance, address }) => { ...options, publicKey: publicKey.toString('hex'), }); - const resp = await blockstackApp.sign(`m/44'/5757'/0'/0/0`, unsignedTx.serialize()); + const resp = await blockstackApp.sign(STX_DERIVATION_PATH, unsignedTx.serialize()); if (resp.returnCode !== LedgerError.NoErrors) { throw new Error('Ledger responded with errors'); diff --git a/app/package.json b/app/package.json index dbbbf4d04..a173ffcd3 100644 --- a/app/package.json +++ b/app/package.json @@ -16,6 +16,7 @@ "dependencies": { "@ledgerhq/hw-transport-node-hid": "5.23.2", "@stacks/keychain": "1.0.0-beta.13", + "@stacks/stacking": "^1.0.0-beta.17", "@stacks/transactions": "1.0.0-beta.13", "bitcoinjs-lib": "5.2.0", "blockstack": "21.1.1" diff --git a/app/pages/onboarding/04-connect-ledger/connect-ledger.tsx b/app/pages/onboarding/04-connect-ledger/connect-ledger.tsx index 14818dd70..bbeb8c073 100644 --- a/app/pages/onboarding/04-connect-ledger/connect-ledger.tsx +++ b/app/pages/onboarding/04-connect-ledger/connect-ledger.tsx @@ -1,9 +1,9 @@ import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; -import BlockstackApp, { LedgerError } from '@zondax/ledger-blockstack'; - import { useDispatch } from 'react-redux'; +import BlockstackApp, { LedgerError } from '@zondax/ledger-blockstack'; +import { STX_DERIVATION_PATH } from '@constants/index'; import routes from '@constants/routes.json'; import { Onboarding, @@ -20,8 +20,6 @@ import { ErrorLabel } from '@components/error-label'; import { ErrorText } from '@components/error-text'; import { useBackButton } from '@hooks/use-back-url'; -const STX_DERIVATION_PATH = `m/44'/5757'/0'/0/0`; - export enum LedgerConnectStep { Disconnected, ConnectedAppClosed, diff --git a/app/yarn.lock b/app/yarn.lock index 25cd51a22..bf38d719c 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -118,7 +118,7 @@ jsontokens "^3.0.0" query-string "^6.13.1" -"@stacks/common@^1.0.0-beta.10", "@stacks/common@^1.0.0-beta.17": +"@stacks/common@^1.0.0-beta.13", "@stacks/common@^1.0.0-beta.17": version "1.0.0-beta.17" resolved "https://registry.yarnpkg.com/@stacks/common/-/common-1.0.0-beta.17.tgz#46ea11aeba821644bc00ed9abc8d996238a6aeb2" integrity sha512-5jgwzeaX5cw92rQHiQCT4ojjNFnKdDkQmfTE5EGe2skqivoyEIbLBzErhV5XpHQo+w8s0Zb9GPZFy2LhrbPRhQ== @@ -141,7 +141,7 @@ "@stacks/connect-ui" "^2.17.0" jsontokens "^3.0.0" -"@stacks/encryption@^1.0.0-beta.10", "@stacks/encryption@^1.0.0-beta.17": +"@stacks/encryption@^1.0.0-beta.13", "@stacks/encryption@^1.0.0-beta.17": version "1.0.0-beta.17" resolved "https://registry.yarnpkg.com/@stacks/encryption/-/encryption-1.0.0-beta.17.tgz#b21f706a426e76c04fdce857ce7d74e29b730a5c" integrity sha512-pDws33pn/dGW1Yt5z9arPQyLYR9jFA5fxRy/PUxY28N/r3Ifkqf6n6nwZOlVTJL8hQzDIM17L0r8CJOjL6F7qQ== @@ -155,16 +155,16 @@ ripemd160-min "^0.0.6" sha.js "^2.4.11" -"@stacks/keychain@1.0.0-beta.10": - version "1.0.0-beta.10" - resolved "https://registry.yarnpkg.com/@stacks/keychain/-/keychain-1.0.0-beta.10.tgz#d6a88e2e9fce87cd4789af553970d89195f223e7" - integrity sha512-qBCbf7fgB7xNM7a5PUIy3TwKgSCz2QkzBDaun1dDFwR8joRB2Kv9fXm+M2JGqcTfVKc2CwHVkYmBVz9HCoYRHw== +"@stacks/keychain@1.0.0-beta.13": + version "1.0.0-beta.13" + resolved "https://registry.yarnpkg.com/@stacks/keychain/-/keychain-1.0.0-beta.13.tgz#a6f2b48961f960ac205ed007bcf657cdb6ba8a6f" + integrity sha512-AtndoM60bvUA826UfN4cuLS6OuKMBBzNUTC2ICeWg2KyaXuy/QAIIXQzfzctudzmTMMdWdVZI1/FmubUPZ151A== dependencies: "@blockstack/rpc-client" "^0.3.0-alpha.11" - "@stacks/common" "^1.0.0-beta.10" - "@stacks/encryption" "^1.0.0-beta.10" - "@stacks/storage" "^1.0.0-beta.10" - "@stacks/transactions" "^1.0.0-beta.10" + "@stacks/common" "^1.0.0-beta.13" + "@stacks/encryption" "^1.0.0-beta.13" + "@stacks/storage" "^1.0.0-beta.13" + "@stacks/transactions" "^1.0.0-beta.13" bip32 "^2.0.4" bip39 "^3.0.2" bitcoinjs-lib "^5.1.6" @@ -175,7 +175,7 @@ triplesec "^3.0.27" zone-file "^1.0.0" -"@stacks/network@^1.0.0-beta.10", "@stacks/network@^1.0.0-beta.17": +"@stacks/network@^1.0.0-beta.13", "@stacks/network@^1.0.0-beta.17": version "1.0.0-beta.17" resolved "https://registry.yarnpkg.com/@stacks/network/-/network-1.0.0-beta.17.tgz#440d10191bb9ec8f4e1b2ce2ae08a77b2a55f128" integrity sha512-8cOPN685hLRzb2eFPfqzTMuNpuF2NmpXRLV2Cxr7u81KdrLQL+Z8d583KWbw2bM12Azxz1D4WckeSisO0xTghg== @@ -195,7 +195,7 @@ schema-inspector "^1.7.0" zone-file "^1.0.0" -"@stacks/stacking@1.0.0-beta.17": +"@stacks/stacking@^1.0.0-beta.17": version "1.0.0-beta.17" resolved "https://registry.yarnpkg.com/@stacks/stacking/-/stacking-1.0.0-beta.17.tgz#bf4b627c4eb028d8f247be8168ca904776a3124f" integrity sha512-cecGSkcIA+wNVoRMdUduiBCS8j8k4uqpBABeUXafIicki0TmoA1bEB2TYmbbaZ2N28KGMR2rRZshHx1xVmFSLg== @@ -209,7 +209,7 @@ c32check "^1.1.1" url-join "^4.0.1" -"@stacks/storage@^1.0.0-beta.10": +"@stacks/storage@^1.0.0-beta.13": version "1.0.0-beta.17" resolved "https://registry.yarnpkg.com/@stacks/storage/-/storage-1.0.0-beta.17.tgz#93e1aed0d49113063f143250eed3eefb756edf8b" integrity sha512-8dynss8NGNd6U9cXTkAyAN43KmF369Gzd5Th24O9CPA2hBELGJj47Trk/Y9W1ge6y6FranlLuQs5u6Iga96Qog== @@ -218,13 +218,13 @@ "@stacks/common" "^1.0.0-beta.17" "@stacks/encryption" "^1.0.0-beta.17" -"@stacks/transactions@1.0.0-beta.10": - version "1.0.0-beta.10" - resolved "https://registry.yarnpkg.com/@stacks/transactions/-/transactions-1.0.0-beta.10.tgz#9589413d6400eaa95cc889a88c615376241ed448" - integrity sha512-eC5QnHVfSKZmFLIX+7/9RMBTEl02bca3Ux4dYJHv0Z3r52ToQbaR4VNGJzATU0nRYHFR6Dryu0qln/QkBYC70g== +"@stacks/transactions@1.0.0-beta.13": + version "1.0.0-beta.13" + resolved "https://registry.yarnpkg.com/@stacks/transactions/-/transactions-1.0.0-beta.13.tgz#5da06033197a69d3c0dd8436be9e7a235e296ae6" + integrity sha512-gMQxULFgxpsku/7hvxsoenfQ510v6GNzWtlm7JRgO6O/khE6qb+N0qz5j3pK/72r7NJi0oaNxIC+KDia8m0YiA== dependencies: - "@stacks/common" "^1.0.0-beta.10" - "@stacks/network" "^1.0.0-beta.10" + "@stacks/common" "^1.0.0-beta.13" + "@stacks/network" "^1.0.0-beta.13" "@types/bn.js" "^4.11.6" "@types/elliptic" "^6.4.12" "@types/randombytes" "^2.0.0" @@ -239,7 +239,7 @@ sha.js "^2.4.11" smart-buffer "^4.1.0" -"@stacks/transactions@^1.0.0-beta.10", "@stacks/transactions@^1.0.0-beta.17": +"@stacks/transactions@^1.0.0-beta.13", "@stacks/transactions@^1.0.0-beta.17": version "1.0.0-beta.17" resolved "https://registry.yarnpkg.com/@stacks/transactions/-/transactions-1.0.0-beta.17.tgz#ae0d5b31772e4c377451a644e965084b86d025eb" integrity sha512-D/2O/eYPu96bLcQ8pcGiqDnUWyOsAruN9m1zwPBUivXw7SYmtBPiorPSMCYwsmaJuhu4S6kyJLAa4z+0i7VVQQ== @@ -546,7 +546,7 @@ bitcoin-ops@^1.3.0, bitcoin-ops@^1.4.0: resolved "https://registry.yarnpkg.com/bitcoin-ops/-/bitcoin-ops-1.4.1.tgz#e45de620398e22fd4ca6023de43974ff42240278" integrity sha512-pef6gxZFztEhaE9RY9HmWVmiIHqCb2OyS4HPKkpc6CIiiOa3Qmuoylxc5P2EkU3w+5eTSifI9SEZC88idAIGow== -bitcoinjs-lib@^5.1.10, bitcoinjs-lib@^5.1.6, bitcoinjs-lib@^5.2.0: +bitcoinjs-lib@5.2.0, bitcoinjs-lib@^5.1.10, bitcoinjs-lib@^5.1.6, bitcoinjs-lib@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-5.2.0.tgz#caf8b5efb04274ded1b67e0706960b93afb9d332" integrity sha512-5DcLxGUDejgNBYcieMIUfjORtUeNWl828VWLHJGVKZCb4zIS1oOySTUr0LGmcqJBQgTBz3bGbRQla4FgrdQEIQ== diff --git a/jest.config.js b/jest.config.js index ca1430afb..a7e696f26 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,7 +19,7 @@ module.exports = { globals: { api: true, 'ts-jest': { - tsConfig: 'tsconfig.tests.json', + tsconfig: 'tsconfig.tests.json', diagnostics: { ignoreCodes: [6133, 2304], },