Skip to content

Commit

Permalink
port over fixes from canary (#1638)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mholtzman authored Aug 29, 2023
1 parent a025d72 commit 00d0eed
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 15 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- 'develop'
- '0.6.3-build'

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 0 additions & 2 deletions app/notify/App/Notification/MoveToPylon/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const MoveToPylon = () => {
<PylonConfirm>
<PylonConfirmButton
onClick={() => {
link.send('tray:action', 'migrateToPylonConnections')
link.send('tray:action', 'mutePylonMigrationNotice')
link.send('frame:close')
}}
>
Expand Down
10 changes: 9 additions & 1 deletion app/tray/Account/Requests/TransactionRequest/TxFee/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
33 changes: 28 additions & 5 deletions main/chains/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
}
})
})
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 8 additions & 1 deletion main/externalData/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion main/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions main/store/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions main/windows/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
6 changes: 6 additions & 0 deletions test/main/chains/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 00d0eed

Please sign in to comment.