@ -16,11 +16,9 @@ import { getDerivations } from 'helpers/derivations'
import getAddressCommand from 'commands/getAddress'
import signTransactionCommand from 'commands/signTransaction'
import { getAccountPlaceholderName , getNewAccountPlaceholderName } from 'helpers/accountName'
import { NotEnoughBalance } from 'config/errors'
import { NotEnoughBalance , ETHAddressNonEIP } from 'config/errors'
import type { EditProps , WalletBridge } from './types'
// TODO in future it would be neat to support eip55
type Transaction = {
recipient : string ,
amount : BigNumber ,
@ -99,6 +97,16 @@ const txToOps = (account: Account) => (tx: Tx): Operation[] => {
}
function isRecipientValid ( currency , recipient ) {
if ( ! recipient . match ( /^0x[0-9a-fA-F]{40}$/ ) ) return false
// To handle non-eip55 addresses we stop validation here if we detect
// address is either full upper or full lower.
// see https://github.com/LedgerHQ/ledger-live-desktop/issues/1397
const slice = recipient . substr ( 2 )
const isFullUpper = slice === slice . toUpperCase ( )
const isFullLower = slice === slice . toLowerCase ( )
if ( isFullUpper || isFullLower ) return true
try {
return eip55 . verify ( recipient )
} catch ( error ) {
@ -106,6 +114,18 @@ function isRecipientValid(currency, recipient) {
}
}
// Returns a warning if we detect a non-eip address
function getRecipientWarning ( currency , recipient ) {
if ( ! recipient . match ( /^0x[0-9a-fA-F]{40}$/ ) ) return null
const slice = recipient . substr ( 2 )
const isFullUpper = slice === slice . toUpperCase ( )
const isFullLower = slice === slice . toLowerCase ( )
if ( isFullUpper || isFullLower ) {
return new ETHAddressNonEIP ( )
}
return null
}
function mergeOps ( existing : Operation [ ] , newFetched : Operation [ ] ) {
const ids = newFetched . map ( o => o . id )
const all = newFetched . concat ( existing . filter ( o => ! ids . includes ( o . id ) ) )
@ -376,6 +396,8 @@ const EthereumBridge: WalletBridge<Transaction> = {
pullMoreOperations : ( ) => Promise . resolve ( a => a ) , // NOT IMPLEMENTED
isRecipientValid : ( currency , recipient ) => Promise . resolve ( isRecipientValid ( currency , recipient ) ) ,
getRecipientWarning : ( currency , recipient ) =>
Promise . resolve ( getRecipientWarning ( currency , recipient ) ) ,
createTransaction : ( ) => ( {
amount : BigNumber ( 0 ) ,