Skip to content

Commit

Permalink
[WIP] - Fix legacy ledger send/migration (#2520)
Browse files Browse the repository at this point in the history
* instantiate the account class properly

* Remove debug

* Fix remaining defects
  • Loading branch information
comountainclimber authored Sep 11, 2023
1 parent 8dcb411 commit 4aee134
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
4 changes: 3 additions & 1 deletion app/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { validatePassphraseLength } from '../core/wallet'
import { legacySignWithLedger } from '../ledger/neonLedger'
import { signWithLedger } from '../ledger/n3NeonLedger'

const N2 = require('@cityofzion/neon-js-legacy-latest')

type WifLoginProps = {
wif: string,
}
Expand Down Expand Up @@ -195,7 +197,7 @@ export const ledgerLoginActions = createActions(
AccountType,
> => {
const { chain } = await getSettings()
const wlt = chain === 'neo3' ? n3Wallet : wallet
const wlt = chain === 'neo3' ? n3Wallet : N2.wallet
const publicKeyEncoded = wlt.getPublicKeyEncoded(publicKey)
const walletAccount = new wlt.Account(publicKeyEncoded)
const hasInternetConnectivity = await checkForInternetConnectivity()
Expand Down
7 changes: 4 additions & 3 deletions app/modules/migration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import { keyBy } from 'lodash-es'
import { api } from '@cityofzion/neon-js-legacy'

import { getNode, getRPCEndpoint } from '../actions/nodeStorageActions'
import { addPendingTransaction } from '../actions/pendingTransactionActions'
Expand Down Expand Up @@ -57,7 +58,7 @@ export const performMigration = ({
isHardwareSend ? migrationAddress : wif,
)
const FROM_ACCOUNT = new N2.wallet.Account(
isHardwareSend ? fromAddress : wif,
isHardwareSend ? publicKey : wif,
)

let endpoint = await getNode(net)
Expand Down Expand Up @@ -207,7 +208,7 @@ export const performMigration = ({

if (isHardwareSend) {
if (script === '') {
c = await N2.api.sendAsset(c).catch(e => {
c = await api.sendAsset(c).catch(e => {
console.error({ e })
if (e.message === 'this.str.substr is not a function') {
return null
Expand All @@ -231,7 +232,7 @@ export const performMigration = ({
return reject()
})
} else {
c = await N2.api.doInvoke(c).catch(e => {
c = await api.doInvoke(c).catch(e => {
console.error({ e })
if (e.message === 'this.str.substr is not a function') {
return null
Expand Down
25 changes: 8 additions & 17 deletions app/modules/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,13 @@ const makeRequest = (
config: Object,
script: string,
) => {
// NOTE: We purposefully mutate the contents of config
// because neon-js will also mutate this same object by reference
// eslint-disable-next-line no-param-reassign
config.intents = buildIntents(sendEntries)
// eslint-disable-next-line
const apiProvider = new N2.api.neoCli.instance(config.url)
config.api = apiProvider
if (script === '') {
if (config.net === 'TestNet') {
// eslint-disable-next-line

return N2.api.sendAsset(config)
}
return N2.api.sendAsset(config)
}
// eslint-disable-next-line no-param-reassign
config.script = script
// eslint-disable-next-line no-param-reassign
config.gas = 0
return api.doInvoke(config)
config.gas = !script ? 0 : undefined
return script ? api.doInvoke(config) : api.sendAsset(config)
}

export const generateBalanceInfo = (
Expand Down Expand Up @@ -458,12 +445,16 @@ export const sendTransaction = ({
)
}

const ledgerAccount = new N2.wallet.Account(publicKey)

const config = {
net,
tokensBalanceMap,
address: fromAddress,
publicKey,
privateKey: new wallet.Account(wif).privateKey,
privateKey: isHardwareSend
? null
: new wallet.Account(wif).privateKey,
signingFunction: isHardwareSend ? signingFunction : null,
fees,
url,
Expand All @@ -472,7 +463,7 @@ export const sendTransaction = ({
intents: undefined,
script: undefined,
gas: undefined,
account: new wallet.Account(wif),
account: isHardwareSend ? ledgerAccount : new wallet.Account(wif),
}

if (net === 'MainNet') {
Expand Down

0 comments on commit 4aee134

Please sign in to comment.