Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core-v2.4.0-alpha.6, react-v2.2.3-alpha.4, vue v2.1.3-alpha.4] : Update - Refactor updateBalance within notification trigger #1129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/core",
"version": "2.4.0-alpha.5",
"version": "2.4.0-alpha.6",
"repository": "blocknative/web3-onboard",
"scripts": {
"build": "rollup -c",
Expand Down
36 changes: 5 additions & 31 deletions packages/core/src/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
import { validateTransactionHandlerReturn } from './validation'
import { state } from './store'
import { addNotification } from './store/actions'
import updateBalances from './updateBalances'
import updateBalances from './update-balances'

export function handleTransactionUpdates(
transaction: EthereumTransactionData
Expand All @@ -25,6 +25,10 @@ export function handleTransactionUpdates(
throw invalid
}

if (transaction.eventCode === 'txConfirmed') {
updateBalances([transaction.watchedAddress, transaction.counterparty])
}

const notification = transactionEventToNotification(transaction, customized)

addNotification(notification)
Expand All @@ -48,10 +52,6 @@ export function transactionEventToNotification(

const type: NotificationType = eventToType(eventCode)

if (type === 'success') {
updateWalletBalance(transaction)
}

const key = `${id || hash}-${
(typeof customization === 'object' && customization.eventCode) || eventCode
}`
Expand Down Expand Up @@ -167,29 +167,3 @@ export function typeToDismissTimeout(type: string): number {
}
}

const updateWalletBalance = (
transaction: Pick<EthereumTransactionData, 'to' | 'from'>
) => {
let walletsToUpdate: string[] = []
state.get().wallets.forEach(wallet => {
if (
wallet.accounts.some(
e => e.address.toLowerCase() === transaction.to.toLowerCase()
)
) {
walletsToUpdate = [...walletsToUpdate, transaction.to]
}
if (
wallet.accounts.some(
e => e.address.toLowerCase() === transaction.from.toLowerCase()
)
) {
walletsToUpdate = [...walletsToUpdate, transaction.from]
}
})

// Pause to allow provider endpoint time to update
setTimeout(() => {
updateBalances(walletsToUpdate)
}, 500)
}
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"dependencies": {
"@web3-onboard/coinbase": "^2.0.7",
"@web3-onboard/core": "^2.3.2",
"@web3-onboard/core": "^2.4.0-alpha.6",
"@web3-onboard/dcent": "^2.0.4",
"@web3-onboard/fortmatic": "^2.0.6",
"@web3-onboard/gnosis": "^2.0.5",
Expand Down
4 changes: 2 additions & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/react",
"version": "2.2.3-alpha.3",
"version": "2.2.3-alpha.4",
"description": "Collection of React Hooks for web3-onboard",
"repository": "blocknative/web3-onboard",
"module": "dist/index.js",
Expand All @@ -24,7 +24,7 @@
"typescript": "^4.5.5"
},
"dependencies": {
"@web3-onboard/core": "^2.4.0-alpha.5",
"@web3-onboard/core": "^2.4.0-alpha.6",
"@web3-onboard/common": "^2.1.4",
"use-sync-external-store": "1.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@web3-onboard/vue",
"version": "2.1.3-alpha.3",
"version": "2.1.3-alpha.4",
"description": "Vue Composable for web3-onboard",
"repository": "blocknative/web3-onboard",
"module": "dist/index.js",
Expand All @@ -25,7 +25,7 @@
"@vueuse/core": "^8.4.2",
"@vueuse/rxjs": "^8.2.0",
"@web3-onboard/common": "^2.1.4",
"@web3-onboard/core": "^2.4.0-alpha.5",
"@web3-onboard/core": "^2.4.0-alpha.6",
"vue-demi": "^0.12.4"
},
"peerDependencies": {
Expand Down