From 00d0eed848dd0b48390d8613b7fbe9d91893409c Mon Sep 17 00:00:00 2001 From: Matt Holtzman Date: Tue, 29 Aug 2023 19:09:07 -0400 Subject: [PATCH] port over fixes from canary (#1638) * properly populate legacy transactions when serializing * dont migrate to pylon connections if user chooses to use custom presets * Chain reconnect (#1634) * reset chain connections on resume event * remove console log * remove settimeout * add safety check * fix power monitor in tests * try 0.6.7 draft release * try to move test mocks back * use pylon preset as default for base goerli * subscribe to rates for custom tokens as well * remove temp builds from build file --- .github/workflows/build.yml | 1 - .../App/Notification/MoveToPylon/index.jsx | 2 -- .../TransactionRequest/TxFee/index.js | 10 +++++- main/chains/index.js | 33 ++++++++++++++++--- main/externalData/assets/index.ts | 9 ++++- main/provider/index.ts | 2 +- main/store/state/index.ts | 4 +-- main/windows/index.ts | 7 ++-- test/main/chains/index.test.js | 6 ++++ 9 files changed, 59 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbb519c4d..5b37a8e4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,6 @@ on: push: branches: - 'develop' - - '0.6.3-build' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/app/notify/App/Notification/MoveToPylon/index.jsx b/app/notify/App/Notification/MoveToPylon/index.jsx index e23be9c5d..d06257b1c 100644 --- a/app/notify/App/Notification/MoveToPylon/index.jsx +++ b/app/notify/App/Notification/MoveToPylon/index.jsx @@ -28,8 +28,6 @@ const MoveToPylon = () => { { - link.send('tray:action', 'migrateToPylonConnections') - link.send('tray:action', 'mutePylonMigrationNotice') link.send('frame:close') }} > diff --git a/app/tray/Account/Requests/TransactionRequest/TxFee/index.js b/app/tray/Account/Requests/TransactionRequest/TxFee/index.js index 1816eb3a4..8ae3adbc5 100644 --- a/app/tray/Account/Requests/TransactionRequest/TxFee/index.js +++ b/app/tray/Account/Requests/TransactionRequest/TxFee/index.js @@ -67,7 +67,15 @@ class TxFee extends React.Component { } getOptimismFee = (l2Price, l2Limit, rawTx) => { - const serializedTransaction = utils.serializeTransaction(Object.assign({}, rawTx, { type: 2 })) + const { maxFeePerGas, maxPriorityFeePerGas, gasPrice, data, gasLimit, nonce, to, value } = rawTx + const chainId = parseInt(rawTx.chainId, 16) + const txData = { chainId, data, gasLimit, nonce, to, value } + + const tx = !!maxFeePerGas + ? { ...txData, maxFeePerGas, maxPriorityFeePerGas, type: 2 } + : { ...txData, gasPrice, type: 0 } + + const serializedTransaction = utils.serializeTransaction(tx) // Get current Ethereum gas price const ethBaseFee = this.store('main.networksMeta.ethereum', 1, 'gas.price.fees.nextBaseFee') diff --git a/main/chains/index.js b/main/chains/index.js index 8d3eb3c06..a1b09b0f6 100644 --- a/main/chains/index.js +++ b/main/chains/index.js @@ -1,5 +1,5 @@ // status = Network Mismatch, Not Connected, Connected, Standby, Syncing - +const { powerMonitor } = require('electron') const EventEmitter = require('events') const { addHexPrefix } = require('@ethereumjs/util') const { Hardfork } = require('@ethereumjs/common') @@ -436,15 +436,21 @@ class Chains extends EventEmitter { super() this.connections = {} - store.observer(() => { + const removeConnection = (chainId, type = 'ethereum') => { + if (type in this.connections && chainId in this.connections[type]) { + this.connections[type][chainId].removeAllListeners() + this.connections[type][chainId].close(false) + delete this.connections[type][chainId] + } + } + + const updateConnections = () => { const networks = store('main.networks') Object.keys(this.connections).forEach((type) => { Object.keys(this.connections[type]).forEach((chainId) => { if (!networks[type][chainId]) { - this.connections[type][chainId].removeAllListeners() - this.connections[type][chainId].close(false) - delete this.connections[type][chainId] + removeConnection(chainId, type) } }) }) @@ -482,7 +488,24 @@ class Chains extends EventEmitter { } }) }) + } + + powerMonitor.on('resume', () => { + const activeConnections = Object.keys(this.connections) + .map((type) => Object.keys(this.connections[type]).map((chainId) => `${type}:${chainId}`)) + .flat() + + log.info('System resuming, resetting active connections', { chains: activeConnections }) + + activeConnections.forEach((id) => { + const [type, chainId] = id.split(':') + removeConnection(chainId, type) + }) + + updateConnections() }) + + store.observer(updateConnections, 'chains:connections') } send(payload, res, targetChain) { diff --git a/main/externalData/assets/index.ts b/main/externalData/assets/index.ts index 636782aa2..b3da49efb 100644 --- a/main/externalData/assets/index.ts +++ b/main/externalData/assets/index.ts @@ -18,6 +18,7 @@ export default function rates(pylon: Pylon, store: Store) { const storeApi = { getKnownTokens: (address?: Address) => ((address && store('main.tokens.known', address)) || []) as Token[], + getCustomTokens: () => (store('main.tokens.custom') || []) as Token[], setNativeCurrencyData: (chainId: number, currencyData: NativeCurrency) => store.setNativeCurrencyData('ethereum', chainId, currencyData), setNativeCurrencyRate: (chainId: number, rate: Rate) => @@ -67,7 +68,13 @@ export default function rates(pylon: Pylon, store: Store) { function updateSubscription(chains: number[], address?: Address) { const subscribedCurrencies = chains.map((chainId) => ({ type: AssetType.NativeCurrency, chainId })) const knownTokens = storeApi.getKnownTokens(address).filter((token) => chains.includes(token.chainId)) - const subscribedTokens = knownTokens.map((token) => ({ + const customTokens = storeApi + .getCustomTokens() + .filter( + (token) => !knownTokens.some((kt) => kt.address === token.address && kt.chainId === token.chainId) + ) + + const subscribedTokens = [...knownTokens, ...customTokens].map((token) => ({ type: AssetType.Token, chainId: token.chainId, address: token.address diff --git a/main/provider/index.ts b/main/provider/index.ts index b5b4f7a5b..0356b03d7 100644 --- a/main/provider/index.ts +++ b/main/provider/index.ts @@ -497,7 +497,7 @@ export class Provider extends EventEmitter { const populatedTransaction = populateTransaction(tx, chainConfig, gas) const checkedTransaction = checkExistingNonceGas(populatedTransaction) - log.verbose('Succesfully populated transaction', checkedTransaction) + log.verbose('Successfully populated transaction', checkedTransaction) cb(null, { tx: checkedTransaction, approvals }) } catch (error) { diff --git a/main/store/state/index.ts b/main/store/state/index.ts index 4dcd2b9ec..3ff26e05f 100644 --- a/main/store/state/index.ts +++ b/main/store/state/index.ts @@ -432,12 +432,12 @@ const mainState: M = { connection: { primary: { on: true, - current: 'custom', + current: 'pylon', status: 'loading', connected: false, type: '', network: '', - custom: 'https://goerli.base.org' + custom: '' }, secondary: { on: false, diff --git a/main/windows/index.ts b/main/windows/index.ts index 00fecccab..a382ace55 100644 --- a/main/windows/index.ts +++ b/main/windows/index.ts @@ -526,8 +526,11 @@ class Notify { const cleanupHandler = () => windows.notify?.off('close', closeHandler) const closeHandler = () => { - store.mutePylonMigrationNotice() - store.migrateToPylonConnections() + if (!store('main.mute.migrateToPylon')) { + store.migrateToPylonConnections() + store.mutePylonMigrationNotice() + } + if (!store('main.mute.onboardingWindow')) { store.setNotify({ showing: false }) store.setOnboard({ showing: true }) diff --git a/test/main/chains/index.test.js b/test/main/chains/index.test.js index fbb16c381..8b65d7ff3 100644 --- a/test/main/chains/index.test.js +++ b/test/main/chains/index.test.js @@ -7,6 +7,12 @@ import { gweiToHex } from '../../util' log.transports.console.level = false +jest.mock('electron', () => ({ + powerMonitor: { + on: jest.fn() + } +})) + class MockConnection extends EventEmitter { constructor(chainId) { super()