Skip to content

Commit d7a98de

Browse files
committed
Merge in latest develop
2 parents a6927ee + af5a09f commit d7a98de

File tree

13 files changed

+40
-32
lines changed

13 files changed

+40
-32
lines changed

packages/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
},
8383
"dependencies": {
8484
"@ethereumjs/common": "2.6.2",
85+
"bignumber.js": "^9.0.0",
8586
"ethers": "5.5.4",
8687
"joi": "^17.4.2",
8788
"rxjs": "^7.5.2"

packages/common/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ export default {
4949
output: { quote_style: 1 }
5050
})
5151
],
52-
external: ['joi', 'rxjs', 'ethers', '@ethereumjs/common']
52+
external: ['joi', 'rxjs', 'ethers', '@ethereumjs/common', 'bignumber.js']
5353
}

packages/common/src/elements/AddressTable.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
import type { Account, AccountsList } from '../types'
3-
import { utils } from 'ethers'
3+
import { weiToEth } from '../utils'
44
55
export let accountsListObject: AccountsList | undefined
66
export let accountSelected: Account | undefined = undefined
@@ -120,7 +120,7 @@
120120
>
121121
<td>{account.derivationPath}</td>
122122
<td class="asset-td"
123-
>{utils.formatEther(account.balance.value)}
123+
>{weiToEth(account.balance.value)}
124124
{account.balance.asset}</td
125125
>
126126
</tr>

packages/common/src/hdwallets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type Common from '@ethereumjs/common'
2-
import type { BigNumber } from 'ethers'
32
import type { CustomNetwork, EIP1193Provider, RPCResponse } from './types'
43
import type { TransactionRequest } from '@ethersproject/providers'
4+
import type { BigNumber } from 'ethers'
55

66
/**
77
* Creates the common instance used for signing

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export {
99
bigNumberFieldsToStrings,
1010
getHardwareWalletProvider
1111
} from './hdwallets'
12+
export { weiToEth } from './utils'
1213

1314
export * from './types'

packages/common/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { ethers, BigNumber } from 'ethers'
21
import type { ConnectionInfo } from 'ethers/lib/utils'
32
import type EventEmitter from 'eventemitter3'
43
import type { TypedData as EIP712TypedData } from 'eip-712'
4+
import type BigNumber from 'bignumber.js'
55
export type { TypedData as EIP712TypedData } from 'eip-712'
66

77
/**
@@ -232,7 +232,7 @@ export interface WalletModule {
232232
export type GetInterfaceHelpers = {
233233
chains: Chain[]
234234
appMetadata: AppMetadata | null
235-
BigNumber: typeof ethers.BigNumber
235+
BigNumber: typeof BigNumber
236236
EventEmitter: typeof EventEmitter
237237
}
238238

packages/common/src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type BigNumber from 'bignumber.js'
2+
3+
export function weiToEth(wei: BigNumber): string {
4+
return wei.div(1e18).toString(10)
5+
}

packages/common/src/views/AccountSelect.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import CloseButton from '../elements/CloseButton.svelte'
44
import AddressTable from '../elements/AddressTable.svelte'
55
import TableHeader from '../elements/TableHeader.svelte'
6-
import { utils } from 'ethers'
7-
86
import type { Subject } from 'rxjs'
97
import type {
108
ScanAccountsOptions,
119
SelectAccountOptions,
1210
Account,
1311
AccountsList
1412
} from '../types'
13+
import { weiToEth } from '../utils'
1514
1615
export let selectAccountOptions: SelectAccountOptions
1716
export let accounts$: Subject<Account[]>
@@ -61,7 +60,7 @@
6160
accountsListObject = {
6261
all: allAccounts,
6362
filtered: allAccounts.filter(account => {
64-
return parseFloat(utils.formatEther(account.balance.value)) > 0
63+
return parseFloat(weiToEth(account.balance.value)) > 0
6564
})
6665
}
6766
loadingAccounts = false

packages/core/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -641,14 +641,15 @@ setTimeout(
641641
**`preflightNotifications`**
642642
Notify can be used to deliver standard notifications along with preflight information by passing a `PreflightNotificationsOptions` object to the `preflightNotifications` action. This will return a a promise that resolves to the transaction hash (if `sendTransaction` resolves the transaction hash and is successful), the internal notification id (if no `sendTransaction` function is provided) or return nothing if an error occurs or `sendTransaction` is not provided or doesn't resolve to a string.
643643

644-
Preflight event types include
645-
- `txRequest` : Alert user there is a transaction request awaiting confirmation by their wallet
646-
- `txAwaitingApproval` : A previous transaction is awaiting confirmation
647-
- `txConfirmReminder` : Reminder to confirm a transaction to continue - configurable with the `txApproveReminderTimeout` property; defaults to 15 seconds
648-
- `nsfFail` : The user has insufficient funds for transaction (requires `gasPrice`, `estimateGas`, `balance`, `txDetails.value`)
649-
- `txError` : General transaction error (requires `sendTransaction`)
650-
- `txSendFail` : The user rejected the transaction (requires `sendTransaction`)
651-
- `txUnderpriced` : The gas price for the transaction is too low (requires `sendTransaction`)
644+
Preflight event types include
645+
646+
- `txRequest` : Alert user there is a transaction request awaiting confirmation by their wallet
647+
- `txAwaitingApproval` : A previous transaction is awaiting confirmation
648+
- `txConfirmReminder` : Reminder to confirm a transaction to continue - configurable with the `txApproveReminderTimeout` property; defaults to 15 seconds
649+
- `nsfFail` : The user has insufficient funds for transaction (requires `gasPrice`, `estimateGas`, `balance`, `txDetails.value`)
650+
- `txError` : General transaction error (requires `sendTransaction`)
651+
- `txSendFail` : The user rejected the transaction (requires `sendTransaction`)
652+
- `txUnderpriced` : The gas price for the transaction is too low (requires `sendTransaction`)
652653

653654
```typescript
654655
interface PreflightNotificationsOptions {
@@ -679,8 +680,7 @@ const sendTransaction = () => {
679680
return signer.sendTransaction(txDetails).then(tx => tx.hash)
680681
}
681682

682-
const gasPrice = () =>
683-
ethersProvider.getGasPrice().then(res => res.toString())
683+
const gasPrice = () => ethersProvider.getGasPrice().then(res => res.toString())
684684

685685
const estimateGas = () => {
686686
return ethersProvider.estimateGas(txDetails).then(res => res.toString())
@@ -812,7 +812,7 @@ The Onboard styles can customized via [CSS variables](https://developer.mozilla.
812812
--account-center-app-btn-text-color
813813
--account-center-app-btn-background
814814
--account-center-app-btn-font-family
815-
815+
816816
/* CUSTOMIZE SECTIONS OF THE CONNECT MODAL */
817817
--onboard-connect-content-width
818818
--onboard-connect-content-height

packages/core/src/provider.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fromEventPattern, Observable } from 'rxjs'
22
import { filter, takeUntil, take, share, switchMap } from 'rxjs/operators'
33
import partition from 'lodash.partition'
4-
import { utils, providers } from 'ethers'
4+
import { providers } from 'ethers'
55

66
import type {
77
ChainId,
@@ -14,13 +14,15 @@ import type {
1414
SelectAccountsRequest
1515
} from '@web3-onboard/common'
1616

17+
import { weiToEth } from '@web3-onboard/common'
1718
import { disconnectWallet$ } from './streams'
1819
import type { Account, Address, Balances, Ens, WalletState } from './types'
1920
import { updateAccount, updateWallet } from './store/actions'
2021
import { validEnsChain } from './utils'
2122
import disconnect from './disconnect'
2223
import { state } from './store'
2324
import { getBlocknativeSdk } from './services'
25+
import BigNumber from 'bignumber.js'
2426

2527
export const ethersProviders: {
2628
[key: string]: providers.StaticJsonRpcProvider
@@ -339,14 +341,16 @@ export async function getBalance(
339341
): Promise<Balances | null> {
340342
// chain we don't recognize and don't have a rpcUrl for requests
341343
if (!chain) return null
342-
343-
const provider = getProvider(chain)
344+
345+
const { wallets } = state.get()
344346

345347
try {
346-
const balanceWei = await provider.getBalance(address)
347-
348+
const wallet = wallets.find(wallet => !!wallet.provider)
349+
const provider = wallet.provider
350+
const balanceHex = await provider.request({ method: 'eth_getBalance', params:[address,'latest'] })
351+
const balanceWei = new BigNumber(parseInt(balanceHex, 16))
348352
return balanceWei
349-
? { [chain.token || 'eth']: utils.formatEther(balanceWei) }
353+
? { [chain.token || 'eth']: weiToEth(balanceWei) }
350354
: null
351355
} catch (error) {
352356
console.error(error)

0 commit comments

Comments
 (0)