Skip to content

Commit

Permalink
fix: second ledger bug, closes #296
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Dec 16, 2020
1 parent 8670d98 commit 60113cb
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 52 deletions.
2 changes: 2 additions & 0 deletions app/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 7 additions & 5 deletions app/modals/stacking/stacking-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -173,7 +172,7 @@ export const StackingModal: FC<StackingModalProps> = 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) {
Expand Down Expand Up @@ -234,6 +233,7 @@ export const StackingModal: FC<StackingModalProps> = props => {

if (error) {
setHasSubmitted(false);
setStep(StackingModalStep.FailedContractCall);
return;
}

Expand Down Expand Up @@ -316,7 +316,9 @@ export const StackingModal: FC<StackingModalProps> = props => {

[StackingModalStep.FailedContractCall]: () => ({
header: <StackingModalHeader onSelectClose={onClose} />,
body: <FailedBroadcastError>{'Failed to call stacking contract'}</FailedBroadcastError>,
body: (
<StackingFailed walletType={walletType}>Failed to call stacking contract</StackingFailed>
),
footer: (
<StackingModalFooter>
<StackingModalButton mode="tertiary" onClick={onClose}>
Expand Down
19 changes: 0 additions & 19 deletions app/modals/stacking/steps/failed-broadcast-error.tsx

This file was deleted.

36 changes: 36 additions & 0 deletions app/modals/stacking/steps/stacking-failed.tsx
Original file line number Diff line number Diff line change
@@ -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<StackingFailedProps> = ({ children, walletType }) => (
<Flex
flexDirection="column"
alignItems="center"
textAlign="center"
px="extra-loose"
mb="extra-loose"
>
<Box mx="auto" my="extra-loose">
<img src={failedCrossSvg} alt="" />
</Box>
<Text as="h1" textStyle="display.small" display="block">
Unable to verify transaction
</Text>
{children && (
<Text as="p" mt="base" mx="loose" display="block" textStyle="body.large">
{children}
</Text>
)}
{walletType === 'ledger' && (
<Text textStyle="caption" color="ink.600" maxWidth="300px" mt="base">
Make sure you're using the same Ledger device you used to create this wallet
</Text>
)}
</Flex>
);
9 changes: 7 additions & 2 deletions app/modals/transaction/transaction-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -127,7 +132,7 @@ export const TransactionModal: FC<TxModalProps> = ({ 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');
Expand Down
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 2 additions & 4 deletions app/pages/onboarding/04-connect-ledger/connect-ledger.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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,
Expand Down
42 changes: 21 additions & 21 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand All @@ -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==
Expand All @@ -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"
Expand All @@ -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==
Expand All @@ -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==
Expand All @@ -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==
Expand All @@ -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"
Expand All @@ -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==
Expand Down Expand Up @@ -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==
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
globals: {
api: true,
'ts-jest': {
tsConfig: 'tsconfig.tests.json',
tsconfig: 'tsconfig.tests.json',
diagnostics: {
ignoreCodes: [6133, 2304],
},
Expand Down

0 comments on commit 60113cb

Please sign in to comment.