Browse Source

better default naming

master
Gaëtan Renaudeau 7 years ago
parent
commit
e5a4b4a5de
  1. 5
      src/bridge/EthereumJSBridge.js
  2. 5
      src/bridge/RippleJSBridge.js
  3. 10
      src/helpers/accountName.js
  4. 14
      src/helpers/libcore.js

5
src/bridge/EthereumJSBridge.js

@ -12,6 +12,7 @@ import type { Tx } from 'api/Ethereum'
import { getDerivations } from 'helpers/derivations' import { getDerivations } from 'helpers/derivations'
import getAddressCommand from 'commands/getAddress' import getAddressCommand from 'commands/getAddress'
import signTransactionCommand from 'commands/signTransaction' import signTransactionCommand from 'commands/signTransaction'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from 'helpers/accountName'
import type { EditProps, WalletBridge } from './types' import type { EditProps, WalletBridge } from './types'
// TODO in future it would be neat to support eip55 // TODO in future it would be neat to support eip55
@ -192,7 +193,7 @@ const EthereumBridge: WalletBridge<Transaction> = {
xpub: '', xpub: '',
freshAddress, freshAddress,
freshAddressPath, freshAddressPath,
name: 'New Account', name: getNewAccountPlaceholderName(currency, index),
balance, balance,
blockHeight: currentBlock.height, blockHeight: currentBlock.height,
index, index,
@ -215,7 +216,7 @@ const EthereumBridge: WalletBridge<Transaction> = {
xpub: '', xpub: '',
freshAddress, freshAddress,
freshAddressPath, freshAddressPath,
name: `Account ${index}`, name: getAccountPlaceholderName(currency, index, !isStandard),
balance, balance,
blockHeight: currentBlock.height, blockHeight: currentBlock.height,
index, index,

5
src/bridge/RippleJSBridge.js

@ -16,6 +16,7 @@ import {
} from 'api/Ripple' } from 'api/Ripple'
import FeesRippleKind from 'components/FeesField/RippleKind' import FeesRippleKind from 'components/FeesField/RippleKind'
import AdvancedOptionsRippleKind from 'components/AdvancedOptions/RippleKind' import AdvancedOptionsRippleKind from 'components/AdvancedOptions/RippleKind'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from 'helpers/accountName'
import type { WalletBridge, EditProps } from './types' import type { WalletBridge, EditProps } from './types'
type Transaction = { type Transaction = {
@ -279,7 +280,7 @@ const RippleJSBridge: WalletBridge<Transaction> = {
next({ next({
id: accountId, id: accountId,
xpub: '', xpub: '',
name: 'New Account', name: getNewAccountPlaceholderName(currency, index),
freshAddress, freshAddress,
freshAddressPath, freshAddressPath,
balance: 0, balance: 0,
@ -310,7 +311,7 @@ const RippleJSBridge: WalletBridge<Transaction> = {
const account: $Exact<Account> = { const account: $Exact<Account> = {
id: accountId, id: accountId,
xpub: '', xpub: '',
name: `Account ${index}`, name: getAccountPlaceholderName(currency, index),
freshAddress, freshAddress,
freshAddressPath, freshAddressPath,
balance, balance,

10
src/helpers/accountName.js

@ -0,0 +1,10 @@
// @flow
import type { CryptoCurrency } from '@ledgerhq/live-common/lib/types'
export const getAccountPlaceholderName = (
c: CryptoCurrency,
index: number,
isLegacy: boolean = false,
) => `${c.name} ${index}${isLegacy ? ' (legacy)' : ''}`
export const getNewAccountPlaceholderName = (_c: CryptoCurrency, _index: number) => `New Account`

14
src/helpers/libcore.js

@ -10,6 +10,8 @@ import type { NJSAccount, NJSOperation } from '@ledgerhq/ledger-core/src/ledgerc
import * as accountIdHelper from 'helpers/accountId' import * as accountIdHelper from 'helpers/accountId'
import { getAccountPlaceholderName, getNewAccountPlaceholderName } from './accountName'
type Props = { type Props = {
core: *, core: *,
devicePath: string, devicePath: string,
@ -255,10 +257,14 @@ async function buildAccountRaw({
const operations = ops.map(op => buildOperationRaw({ core, op, xpub })) const operations = ops.map(op => buildOperationRaw({ core, op, xpub }))
const currency = getCryptoCurrencyById(currencyId) const currency = getCryptoCurrencyById(currencyId)
let name = operations.length === 0 ? `New Account` : `Account ${accountIndex}` const name =
if (currency.supportsSegwit && !isSegwit) { operations.length === 0
name += ' (legacy)' ? getNewAccountPlaceholderName(currency, accountIndex)
} : getAccountPlaceholderName(
currency,
accountIndex,
(currency.supportsSegwit && !isSegwit) || false,
)
const rawAccount: AccountRaw = { const rawAccount: AccountRaw = {
id: accountIdHelper.encode({ id: accountIdHelper.encode({

Loading…
Cancel
Save