Browse Source

Merge pull request #492 from gre/deprecate-account-isSegwit

Deprecate usage of Account#isSegwit field
master
Meriadec Pillet 7 years ago
committed by GitHub
parent
commit
db60d6ae56
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/commands/libcoreSignAndBroadcast.js
  2. 3
      src/components/EnsureDeviceApp/index.js
  3. 3
      src/components/modals/Receive/index.js
  4. 7
      src/helpers/bip32.js
  5. 3
      src/helpers/libcore.js

5
src/commands/libcoreSignAndBroadcast.js

@ -5,6 +5,7 @@ import type { AccountRaw, OperationRaw } from '@ledgerhq/live-common/lib/types'
import Btc from '@ledgerhq/hw-app-btc' import Btc from '@ledgerhq/hw-app-btc'
import { Observable } from 'rxjs' import { Observable } from 'rxjs'
import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies' import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currencies'
import { isSegwitAccount } from 'helpers/bip32'
import withLibcore from 'helpers/withLibcore' import withLibcore from 'helpers/withLibcore'
import { createCommand, Command } from 'helpers/ipc' import { createCommand, Command } from 'helpers/ipc'
@ -158,7 +159,7 @@ export async function doSignAndBroadcast({
const WALLET_IDENTIFIER = await getWalletIdentifier({ const WALLET_IDENTIFIER = await getWalletIdentifier({
hwApp, hwApp,
isSegwit: !!account.isSegwit, isSegwit: isSegwitAccount(account),
currencyId: account.currencyId, currencyId: account.currencyId,
devicePath: deviceId, devicePath: deviceId,
}) })
@ -197,7 +198,7 @@ export async function doSignAndBroadcast({
transaction: builded, transaction: builded,
sigHashType: parseInt(sigHashType, 16), sigHashType: parseInt(sigHashType, 16),
supportsSegwit: !!currency.supportsSegwit, supportsSegwit: !!currency.supportsSegwit,
isSegwit: !!account.isSegwit, isSegwit: isSegwitAccount(account),
hasTimestamp, hasTimestamp,
}) })
}) })

3
src/components/EnsureDeviceApp/index.js

@ -2,6 +2,7 @@
import { PureComponent } from 'react' import { PureComponent } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import logger from 'logger' import logger from 'logger'
import { isSegwitAccount } from 'helpers/bip32'
import type { Account, CryptoCurrency } from '@ledgerhq/live-common/lib/types' import type { Account, CryptoCurrency } from '@ledgerhq/live-common/lib/types'
import type { Device } from 'types/common' import type { Device } from 'types/common'
@ -121,7 +122,7 @@ class EnsureDeviceApp extends PureComponent<Props, State> {
devicePath: deviceSelected.path, devicePath: deviceSelected.path,
currencyId: account.currency.id, currencyId: account.currency.id,
path: account.freshAddressPath, path: account.freshAddressPath,
segwit: !!account.isSegwit, segwit: isSegwitAccount(account),
}) })
.toPromise() .toPromise()
const { freshAddress } = account const { freshAddress } = account

3
src/components/modals/Receive/index.js

@ -7,6 +7,7 @@ import type { Account } from '@ledgerhq/live-common/lib/types'
import type { T, Device } from 'types/common' import type { T, Device } from 'types/common'
import { MODAL_RECEIVE } from 'config/constants' import { MODAL_RECEIVE } from 'config/constants'
import { isSegwitAccount } from 'helpers/bip32'
import getAddress from 'commands/getAddress' import getAddress from 'commands/getAddress'
import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority' import SyncSkipUnderPriority from 'components/SyncSkipUnderPriority'
@ -202,7 +203,7 @@ class ReceiveModal extends PureComponent<Props, State> {
currencyId: account.currency.id, currencyId: account.currency.id,
devicePath: device.path, devicePath: device.path,
path: account.freshAddressPath, path: account.freshAddressPath,
segwit: !!account.isSegwit, segwit: isSegwitAccount(account),
verify: true, verify: true,
}) })
.toPromise() .toPromise()

7
src/helpers/bip32.js

@ -0,0 +1,7 @@
// @flow
import type { Account, AccountRaw } from '@ledgerhq/live-common/lib/types'
export const isSegwitPath = (path: string): boolean => path.startsWith("49'")
export const isSegwitAccount = (account: Account | AccountRaw): boolean =>
isSegwitPath(account.freshAddressPath)

3
src/helpers/libcore.js

@ -8,6 +8,7 @@ import { getCryptoCurrencyById } from '@ledgerhq/live-common/lib/helpers/currenc
import type { AccountRaw, OperationRaw, OperationType } from '@ledgerhq/live-common/lib/types' import type { AccountRaw, OperationRaw, OperationType } from '@ledgerhq/live-common/lib/types'
import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc' import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgercore_doc'
import { isSegwitAccount } from 'helpers/bip32'
import * as accountIdHelper from 'helpers/accountId' import * as accountIdHelper from 'helpers/accountId'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName' import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName'
@ -368,7 +369,7 @@ export async function syncAccount({
const syncedRawAccount = await buildAccountRaw({ const syncedRawAccount = await buildAccountRaw({
njsAccount, njsAccount,
isSegwit: rawAccount.isSegwit === true, isSegwit: isSegwitAccount(rawAccount),
accountIndex: rawAccount.index, accountIndex: rawAccount.index,
wallet: njsWallet, wallet: njsWallet,
currencyId: rawAccount.currencyId, currencyId: rawAccount.currencyId,

Loading…
Cancel
Save