Skip to content

Commit

Permalink
beta.19 (#878)
Browse files Browse the repository at this point in the history
* Only update balances if account exists (#841)

* Display and copy checksummed addresses (#880)

* Upgrade GridPlus SDK to v1.3.5 (#845)

* Fix lattice tests

* Add restart button to unhandled error dialog (#881)

* Move shared transaction code into resources (#882)

* Update Trezor firmware check

* Force Fantom chains to use legacy (pre- EIP-1559) gas mechanism (#884)
  • Loading branch information
mholtzman authored Jun 3, 2022
1 parent 2df1380 commit 2eb8f02
Show file tree
Hide file tree
Showing 30 changed files with 348 additions and 259 deletions.
59 changes: 0 additions & 59 deletions @types/gridplus-sdk/index.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/App/Panel/Main/Account/Gas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ class Gas extends React.Component {
}
}

export default Restore.connect(Gas)
export default Restore.connect(Gas)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import Restore from 'react-restore'
import BigNumber from 'bignumber.js'

import { usesBaseFee } from '../../../../../../../../main/transaction'
import { usesBaseFee } from '../../../../../../../../resources/domain/transaction'

const FEE_WARNING_THRESHOLD_USD = 50

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Restore from 'react-restore'
import svg from '../../../../../../../../../resources/svg'
import link from '../../../../../../../../../resources/link'
import { gweiToWei, gweiToWeiHex } from '../../../../../../../../../resources/utils'
import { usesBaseFee } from '../../../../../../../../../main/transaction'
import { usesBaseFee } from '../../../../../../../../../resources/domain/transaction'

import BigNumber from 'bignumber.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'
import Restore from 'react-restore'
import { getAddress } from '@ethersproject/address'

import link from '../../../../../../../../resources/link'
import svg from '../../../../../../../../resources/svg'

Expand All @@ -17,6 +19,7 @@ class TxRecipient extends React.Component {
}
render () {
const req = this.props.req
const address = req.data.to ? getAddress(req.data.to) : ''
const ensName = (req.recipient && req.recipient.length < 25) ? req.recipient : ''

return (
Expand All @@ -26,15 +29,15 @@ class TxRecipient extends React.Component {
Recipient
</div>
<div className='_txRecipientFull' onClick={() => {
this.copyAddress(req.data.to)
this.copyAddress(address)
}}>
{this.state.copied ? 'Address Copied' : req.data.to}
{this.state.copied ? 'Address Copied' : address}
</div>
{req.data.to ? (
{address ? (
<div className='_txRecipientSlice _txRecipientValue'>
{ensName
? <span>{ensName}</span>
: <span>{req.data.to.substring(0, 6)}{svg.octicon('kebab-horizontal', { height: 15 })}{req.data.to.substr(req.data.to.length - 4)}</span>
: <span>{address.substring(0, 6)}{svg.octicon('kebab-horizontal', { height: 15 })}{address.substring(address.length - 4)}</span>
}
{req.decodedData && req.decodedData.contractName ? (
<span className={'_txRecipientContract'}>{(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react'
import Restore from 'react-restore'
import utils from 'web3-utils'
import BigNumber from 'bignumber.js'
import { getAddress } from '@ethersproject/address'

import { usesBaseFee } from '../../../../../../../main/transaction'

import { usesBaseFee } from '../../../../../../../resources/domain/transaction'
import { ApprovalType } from '../../../../../../../resources/constants'
import svg from '../../../../../../../resources/svg'
import link from '../../../../../../../resources/link'
Expand Down Expand Up @@ -147,7 +147,7 @@ class TransactionRequest extends React.Component {

const status = req.status
const mode = req.mode
const toAddress = req.data && req.data.to ? req.data.to : ''
const toAddress = req.data && req.data.to ? getAddress(req.data.to) : ''
let requestClass = 'signerRequest'
if (mode === 'monitor') requestClass += ' signerRequestMonitor'
const success = (req.status === 'confirming' || req.status === 'confirmed')
Expand Down Expand Up @@ -435,7 +435,7 @@ class TransactionRequest extends React.Component {
<span className='monitorValue0x'>{'0x'}</span>
{toAddress.substring(2, 5)}
{svg.octicon('kebab-horizontal', { height: 14 })}
{toAddress.substr(toAddress.length - 3)}
{toAddress.substring(toAddress.length - 3)}
</span>
<span className='monitorSub'>{'ON'} </span>
<span className='monitorSub monitorSubHighlight'>
Expand Down
8 changes: 4 additions & 4 deletions app/App/Panel/Main/Account/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react'
import Restore from 'react-restore'
import { getAddress } from '@ethersproject/address'

import svg from '../../../../../resources/svg'
import link from '../../../../../resources/link'
Expand All @@ -13,7 +14,6 @@ import Inventory from './Inventory'
import Launcher from './Launcher'
import Permissions from './Permissions'
import Requests from './Requests'
import SignerModule from './Signer'
import SignerStatus from './SignerStatus'
import Verify from './Verify'
import Settings from './Settings'
Expand Down Expand Up @@ -576,11 +576,11 @@ class Account extends React.Component {
}

onScroll () {
this.setState({ addressHover: false})
this.setState({ addressHover: false })
}

copyAddress () {
link.send('tray:clipboardData', this.props.id)
link.send('tray:clipboardData', getAddress(this.props.id))
this.setState({ copied: true })
setTimeout(_ => this.setState({ copied: false }), 1000)
}
Expand Down Expand Up @@ -848,7 +848,7 @@ class Account extends React.Component {
// if (this.state.accountHighlight === 'active') currentIndex = this.state.highlightIndex

const { address, ensName, active } = this.store('main.accounts', this.props.id)
const formattedAddress = address || '0x'
const formattedAddress = getAddress(address)

let requests = this.store('main.accounts', this.props.id, 'requests') || {}
requests = Object.keys(requests).filter(r => requests[r].mode === 'normal')
Expand Down
2 changes: 1 addition & 1 deletion app/App/Panel/Notify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import svg from '../../../../resources/svg'
import link from '../../../../resources/link'

import BigNumber from 'bignumber.js'
import { usesBaseFee } from '../../../../main/transaction'
import { usesBaseFee } from '../../../../resources/domain/transaction'

import frameIcon from './FrameIcon.png'

Expand Down
2 changes: 1 addition & 1 deletion main/accounts/Account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import signers from '../../signers'
import windows from '../../windows'
import store from '../../store'
import { Aragon } from '../aragon'
import { TransactionData } from '../../transaction'
import { TransactionData } from '../../../resources/domain/transaction'
import { capitalize } from '../../../resources/utils'
import { getType as getSignerType, Type as SignerType } from '../../signers/Signer'

Expand Down
4 changes: 2 additions & 2 deletions main/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@


import EventEmitter from 'events'
import fetch from 'node-fetch'
import log from 'electron-log'
import { shell, Notification } from 'electron'
import { addHexPrefix, intToHex} from 'ethereumjs-util'
Expand All @@ -10,7 +9,8 @@ import store from '../store'
import ExternalDataScanner, { DataScanner } from '../externalData'
import { getType as getSignerType } from '../signers/Signer'
import FrameAccount from './Account'
import { usesBaseFee, signerCompatibility, maxFee, TransactionData, SignerCompatibility } from '../transaction'
import { usesBaseFee, TransactionData } from '../../resources/domain/transaction'
import { signerCompatibility, maxFee, SignerCompatibility } from '../transaction'
import { weiIntToEthInt, hexToInt } from '../../resources/utils'

import {
Expand Down
2 changes: 1 addition & 1 deletion main/accounts/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Version } from 'eth-sig-util'
import type { DecodedCallData } from '../contracts'
import type { Chain } from '../chains'
import type { TransactionData } from '../transaction'
import type { TransactionData } from '../../resources/domain/transaction'

export enum ReplacementType {
Speed = 'speed',
Expand Down
9 changes: 8 additions & 1 deletion main/chains/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const { default: BlockMonitor } = require('./blocks')
const { default: chainConfig } = require('./config')
const { default: GasCalculator } = require('../transaction/gasCalculator')

// these chain IDs are known to not support EIP-1559 and will be forced
// not to use that mechanism
// TODO: create a more general chain config that can use the block number
// and ethereumjs/common to determine the state of various EIPs
const legacyChains = [250, 4002]

class ChainConnection extends EventEmitter {
constructor (type, chainId) {
super()
Expand Down Expand Up @@ -55,13 +61,14 @@ class ChainConnection extends EventEmitter {

_createBlockMonitor (provider) {
const monitor = new BlockMonitor(provider)
const allowEip1559 = !legacyChains.includes(parseInt(this.chainId))

monitor.on('data', async block => {
let feeMarket = null

const gasCalculator = new GasCalculator(provider)

if ('baseFeePerGas' in block) {
if (allowEip1559 && 'baseFeePerGas' in block) {
try {
// only consider this an EIP-1559 block if fee market can be loaded
feeMarket = await gasCalculator.getFeePerGas()
Expand Down
21 changes: 17 additions & 4 deletions main/externalData/balances/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ export default function (store: Store) {
workerController = new BalancesWorkerController()

workerController.once('close', handleClose)
workerController.on('chainBalances', handleChainBalanceUpdate)
workerController.on('tokenBalances', handleTokenBalanceUpdate)
workerController.on('chainBalances', (address, balances) => {
handleUpdate(address, handleChainBalanceUpdate.bind(null, balances))
})

workerController.on('tokenBalances', (address, balances) => {
handleUpdate(address, handleTokenBalanceUpdate.bind(null, balances))
})
}

function restart () {
Expand Down Expand Up @@ -133,7 +138,15 @@ export default function (store: Store) {
workerController?.scanForTokenBalances(address, trackedTokens, chains)
}

function handleChainBalanceUpdate (address: Address, balances: CurrencyBalance[]) {
function handleUpdate (address: Address, updateFn: (address: Address) => void) {
// because updates come from another process its possible to receive updates after an account
// has been removed but before we stop the scan, so check to make sure the account exists
if (store('main.accounts', address)) {
updateFn(address)
}
}

function handleChainBalanceUpdate (balances: CurrencyBalance[], address: Address) {
const currentChainBalances = storeApi.getCurrencyBalances(address)

balances
Expand All @@ -154,7 +167,7 @@ export default function (store: Store) {
})
}

function handleTokenBalanceUpdate (address: Address, balances: TokenBalance[]) {
function handleTokenBalanceUpdate (balances: TokenBalance[], address: Address) {
// only update balances if any have changed
const currentTokenBalances = storeApi.getTokenBalances(address)
const changedBalances = balances.filter(newBalance => {
Expand Down
22 changes: 12 additions & 10 deletions main/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { app, ipcMain, protocol, shell, dialog, clipboard, globalShortcut, BrowserWindow } = require('electron')
const { app, ipcMain, protocol, shell, clipboard, globalShortcut, BrowserWindow } = require('electron')

app.commandLine.appendSwitch('enable-accelerated-2d-canvas', true)
app.commandLine.appendSwitch('enable-gpu-rasterization', true)
Expand Down Expand Up @@ -95,28 +95,30 @@ require('./rpc')
// const clients = require('./clients')
const signers = require('./signers').default
const persist = require('./store/persist')
const { default: showUnhandledExceptionDialog } = require('./windows/dialog/unhandledException')

log.info('Chrome: v' + process.versions.chrome)
log.info('Electron: v' + process.versions.electron)
log.info('Node: v' + process.versions.node)

process.on('uncaughtException', (e) => {
// prevent showing the exit dialog more than once
let closing = false

process.on('uncaughtException', e => {
Sentry.captureException(e)

log.error('uncaughtException', e)

if (e.code === 'EPIPE') {
log.error('uncaught EPIPE error', e)
return
}

if (e.code === 'EADDRINUSE') {
dialog.showErrorBox('Frame is already running', 'Frame is already running or another application is using port 1248.')
} else {
dialog.showErrorBox('An error occured, Frame will quit', e.message)
}
log.error('uncaughtException')
log.error(e)
if (!closing) {
closing = true

app.quit()
showUnhandledExceptionDialog(e.message, e.code)
}
})

const externalWhitelist = [
Expand Down
3 changes: 2 additions & 1 deletion main/provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import packageFile from '../../package.json'
import accounts, { AccountRequest, TransactionRequest, SignTypedDataRequest, SwitchChainRequest, AddChainRequest, AddTokenRequest } from '../accounts'
import Chains, { Chain } from '../chains'
import { getType as getSignerType, Type as SignerType } from '../signers/Signer'
import { populate as populateTransaction, usesBaseFee, maxFee, TransactionData } from '../transaction'
import { TransactionData, usesBaseFee } from '../../resources/domain/transaction'
import { populate as populateTransaction, maxFee } from '../transaction'
import FrameAccount from '../accounts/Account'
import { capitalize, arraysMatch } from '../../resources/utils'
import { ApprovalType } from '../../resources/constants'
Expand Down
7 changes: 4 additions & 3 deletions main/signers/Signer/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import log from 'electron-log'
import EventEmitter from 'stream'
import { addHexPrefix } from 'ethereumjs-util'

import { TransactionData } from '../../transaction'
import { TransactionData } from '../../../resources/domain/transaction'
import { deriveHDAccounts } from './derive'
import crypt from '../../crypt'
import { TypedData } from 'eth-sig-util'
Expand Down Expand Up @@ -62,7 +63,7 @@ export default class Signer extends EventEmitter {
}

getCoinbase (cb: Callback<string>) {
cb(null, this.addresses[0])
cb(null, this.addresses[0].toString())
}

verifyAddress (index: number, current: string, display: boolean, cb: Callback<boolean>) {
Expand All @@ -77,7 +78,7 @@ export default class Signer extends EventEmitter {
name: this.name || this.type + ' signer',
type: this.type,
model: this.model,
addresses: this.addresses,
addresses: this.addresses.map(addr => addHexPrefix(addr.toString())),
status: this.status,
appVersion: this.appVersion || { major: 0, minor: 0, patch: 0 }
}
Expand Down
Loading

0 comments on commit 2eb8f02

Please sign in to comment.