Skip to content

Commit af5a09f

Browse files
authored
[common-v2.1.7-alpha.1, core-v2.6.0-alpha.1, react-v2.2.5-alpha.1, vue-2.1.5-alpha.1, demo-v2.0.6]: Enhancement - Convert Wei to Eth (#1137)
* weitoeth * weitoeth * weitoeth * weitoeth * common-utils * BigNumber replacement * BigNumber replacement * replace balanceWei * pr-fix * pr-fix * edits * edits * merge develop
1 parent 9b285dc commit af5a09f

File tree

15 files changed

+45
-37
lines changed

15 files changed

+45
-37
lines changed

packages/common/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/common",
3-
"version": "2.1.7-alpha.3",
3+
"version": "2.1.7-alpha.4",
44
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardised spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.",
55
"keywords": [
66
"Ethereum",
@@ -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/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"typescript": "^4.5.5"
8484
},
8585
"dependencies": {
86-
"@web3-onboard/common": "^2.1.7-alpha.3",
86+
"@web3-onboard/common": "^2.1.7-alpha.4",
8787
"bignumber.js": "^9.0.0",
8888
"bnc-sdk": "^4.4.1",
8989
"bowser": "^2.11.0",

0 commit comments

Comments
 (0)