From e3ed2060ef2d78dc2b443403fb52099b08aa293f Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 27 May 2022 10:38:48 -0400 Subject: [PATCH 01/15] async --- packages/core/src/store/actions.ts | 25 ++++- packages/core/src/store/constants.ts | 1 + packages/core/src/store/index.ts | 61 ++++++++--- packages/core/src/streams.ts | 24 ++++- packages/core/src/types.ts | 6 ++ packages/core/src/validation.ts | 6 ++ packages/demo/src/App.svelte | 10 ++ yarn.lock | 151 +++++++++++++++++++++++++++ 8 files changed, 267 insertions(+), 17 deletions(-) diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index ec0c573a1..c211272b6 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -15,7 +15,8 @@ import type { UpdateAccountAction, UpdateAccountCenterAction, UpdateWalletAction, - WalletState + WalletState, + UpdateBalancesAction } from '../types' import { @@ -23,7 +24,8 @@ import { validateLocale, validateString, validateWallet, - validateWalletInit + validateWalletInit, + validateUpdateBalances } from '../validation' import { @@ -35,7 +37,8 @@ import { UPDATE_ACCOUNT, UPDATE_ACCOUNT_CENTER, SET_WALLET_MODULES, - SET_LOCALE + SET_LOCALE, + UPDATE_BALANCES } from './constants' export function addChains(chains: Chain[]): void { @@ -180,3 +183,19 @@ export function setLocale(locale: string): void { dispatch(action as SetLocaleAction) } + +export function updateBalances(addresses?: string[]): void { + + const error = validateUpdateBalances(addresses) + + if (error) { + throw error + } + + const action = { + type: UPDATE_BALANCES, + payload: addresses + } + + dispatch(action as UpdateBalancesAction) +} diff --git a/packages/core/src/store/constants.ts b/packages/core/src/store/constants.ts index 7fe7e89a9..a6efbd50a 100644 --- a/packages/core/src/store/constants.ts +++ b/packages/core/src/store/constants.ts @@ -7,3 +7,4 @@ export const UPDATE_ACCOUNT = 'update_account' export const UPDATE_ACCOUNT_CENTER = 'update_account_center' export const SET_WALLET_MODULES = 'set_wallet_modules' export const SET_LOCALE= 'set_locale' +export const UPDATE_BALANCES = 'update_balance' diff --git a/packages/core/src/store/index.ts b/packages/core/src/store/index.ts index 1dee9ccec..4851a0e15 100644 --- a/packages/core/src/store/index.ts +++ b/packages/core/src/store/index.ts @@ -6,6 +6,8 @@ import type { Chain, WalletModule } from '@web3-onboard/common' import { APP_INITIAL_STATE } from '../constants' import { notNullish } from '../utils' +import { getBalance } from '../provider' + import type { AppState, WalletState, @@ -14,7 +16,8 @@ import type { AddWalletAction, UpdateAccountAction, UpdateAccountCenterAction, - Locale + Locale, + UpdateBalancesAction } from '../types' import { @@ -26,10 +29,11 @@ import { UPDATE_ACCOUNT, UPDATE_ACCOUNT_CENTER, SET_WALLET_MODULES, - SET_LOCALE + SET_LOCALE, + UPDATE_BALANCES } from './constants' -function reducer(state: AppState, action: Action): AppState { +async function reducer(state: AppState, action: Action): Promise { const { type, payload } = action switch (type) { @@ -70,6 +74,37 @@ function reducer(state: AppState, action: Action): AppState { } } + case UPDATE_BALANCES: { + const addresses = payload as UpdateBalancesAction['payload'] + const { wallets, chains } = state + + const updatedWallets = await Promise.all( + wallets.map(async wallet => { + const chain = chains.find(({ id }) => id === wallet.chains[0].id) + + const updatedAccounts = await Promise.all( + wallet.accounts.map(async account => { + // if no addresses then we want to update all address balances + // otherwise check if address is in the supplied addresses array + if (!addresses || addresses.includes(account.address)) { + const updatedBalance = await getBalance(account.address, chain) + return { ...account, balance: updatedBalance } + } + + return account + }) + ) + + return { ...wallet, accounts: updatedAccounts } + }) + ) + + return { + ...state, + wallets: updatedWallets + } + } + case REMOVE_WALLET: { const update = payload as { id: string } return { @@ -141,20 +176,22 @@ const _stateUpdates = new Subject() _stateUpdates.subscribe(_store) -export function dispatch(action: Action): void { - const state = _store.getValue() - _stateUpdates.next(reducer(state, action)) +export async function dispatch(action: Action): Promise { + const state = await _store.getValue() + const nextState = await reducer(state, action) + _stateUpdates.next(nextState) } -function select(): Observable -function select(stateKey: T): Observable -function select( +async function select(): Promise> +async function select(stateKey: T): + Promise> +async function select( stateKey?: keyof AppState -): Observable | Observable { +): Promise | Observable> { if (!stateKey) return _stateUpdates.asObservable() - const validStateKeys = Object.keys(_store.getValue()) - + const validStateKeys = await Object.keys(_store.getValue()) + if (!validStateKeys.includes(String(stateKey))) { throw new Error(`key: ${stateKey} does not exist on this store`) } diff --git a/packages/core/src/streams.ts b/packages/core/src/streams.ts index 1a99383d6..9de076189 100644 --- a/packages/core/src/streams.ts +++ b/packages/core/src/streams.ts @@ -1,6 +1,6 @@ import type { Chain } from '@web3-onboard/common' import { onDestroy, onMount, beforeUpdate, afterUpdate } from 'svelte' -import { Observable, Subject, defer, BehaviorSubject } from 'rxjs' +import { Observable, Subject, defer, BehaviorSubject, empty } from 'rxjs' import { take, takeUntil, @@ -33,10 +33,30 @@ export const switchChainModal$ = new BehaviorSubject(null) + +async function fetchWalletUpdates() { + const walletsA$ = await state.select('wallets') + return walletsA$ +} + +let walt$ + +(async () => { +try { + walt$ = await fetchWalletUpdates() +}catch (e) { + console.log(e) +} +})(); + export const wallets$ = ( - state.select('wallets') as Observable + walt$ as Observable ).pipe(shareReplay(1)) +// export const wallets$ = ( +// state.select('wallets') as Observable +// ).pipe(shareReplay(1)) + // reset logic reset$.pipe(withLatestFrom(wallets$), pluck('1')).subscribe(wallets => { // disconnect all wallets diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index ea00d6269..cc675c9f4 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -136,6 +136,7 @@ export type Action = | UpdateAccountCenterAction | SetWalletModulesAction | SetLocaleAction + | UpdateBalancesAction export type AddChainsAction = { type: 'add_chains'; payload: Chain[] } export type AddWalletAction = { type: 'add_wallet'; payload: WalletState } @@ -175,6 +176,11 @@ export type SetLocaleAction = { payload: string } +export type UpdateBalancesAction = { + type: 'update_balance' + payload: string[] +} + // ==== MISC ==== // export type ChainStyle = { icon: string diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index 85a40942b..a6e4e181d 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -99,6 +99,8 @@ const walletInit = Joi.array().items(Joi.function()).required() const locale = Joi.string() +const addresses = Joi.array().items(Joi.string().pattern(/^0x[a-fA-F0-9]{40}$/)) + const accountCenterPosition = Joi.string().valid( 'topRight', 'bottomRight', @@ -209,3 +211,7 @@ export function validateWalletInit(data: WalletInit[]): ValidateReturn { export function validateLocale(data: string): ValidateReturn { return validate(locale, data) } + +export function validateUpdateBalances(data: string[]): ValidateReturn { + return validate(addresses, data) +} diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index b2788357e..f3adaa7ec 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -177,6 +177,16 @@ }) // Subscribe to wallet updates + // const wallets$ = Promise.resolve([]) + + // async function fetchWalletUpdates() { + // return await onboard.state + // .select('wallets') + // .pipe(share()) /*Ωignore_startΩ*/ + // } + + // wallets$ = fetchWalletUpdates + const wallets$ = onboard.state.select('wallets').pipe(share()) const signTransactionMessage = async provider => { diff --git a/yarn.lock b/yarn.lock index fad265bae..b79564901 100644 --- a/yarn.lock +++ b/yarn.lock @@ -795,6 +795,17 @@ google-protobuf "^3.7.0-rc.2" pbjs "^0.0.5" +"@keystonehq/base-eth-keyring@^0.3.2": + version "0.3.2" + resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.3.2.tgz#71efe1495d4931fab5fd0016c8722fe5d9657da9" + integrity sha512-y/kv8XNRSzqcSl7fvZklBKr4MVir1OJHzqM5vC+3yvzkh3mVtN8vUjAAxHtmVVVyM8rsdqK7aYZ7paexYdpnag== + dependencies: + "@ethereumjs/tx" "3.0.0" + "@keystonehq/bc-ur-registry-eth" "^0.7.7" + ethereumjs-util "^7.0.8" + hdkey "^2.0.1" + uuid "^8.3.2" + "@keystonehq/base-eth-keyring@^0.6.0-alpha.1": version "0.6.0-alpha.1" resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.6.0-alpha.1.tgz#ff19689eb07a54aefdc21394a51c117660f7a0d2" @@ -816,6 +827,25 @@ hdkey "^2.0.1" uuid "^8.3.2" +"@keystonehq/bc-ur-registry-eth@^0.7.7": + version "0.7.7" + resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry-eth/-/bc-ur-registry-eth-0.7.7.tgz#45267510900049050ef860a1e78fde9087b75972" + integrity sha512-2gZf18ogSCLjsn3PxGqwiOMz/G11v7byRnTLv5/wNJGzCqkMf86OKaVbUgsVokq0B5KAZtpCFQxj96rrFhPRiQ== + dependencies: + "@keystonehq/bc-ur-registry" "^0.4.4" + ethereumjs-util "^7.0.8" + hdkey "^2.0.1" + uuid "^8.3.2" + +"@keystonehq/bc-ur-registry@^0.4.4": + version "0.4.4" + resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry/-/bc-ur-registry-0.4.4.tgz#3073fdd4b33cdcbd04526a313a7685891a4b4583" + integrity sha512-SBdKdAZfp3y14GTGrKjfJJHf4iXObjcm4/qKUZ92lj8HVR8mxHHGmHksjE328bJPTAsJPloLix4rTnWg+qgS2w== + dependencies: + "@ngraveio/bc-ur" "^1.1.5" + base58check "^2.0.0" + tslib "^2.3.0" + "@keystonehq/bc-ur-registry@^0.5.0-alpha.5": version "0.5.0-alpha.6" resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry/-/bc-ur-registry-0.5.0-alpha.6.tgz#56868a7deeeaf5315a7fff6c0b42f3d31555a5c2" @@ -825,6 +855,21 @@ base58check "^2.0.0" tslib "^2.3.0" +"@keystonehq/eth-keyring@^0.11.2-alpha.2": + version "0.11.2" + resolved "https://registry.yarnpkg.com/@keystonehq/eth-keyring/-/eth-keyring-0.11.2.tgz#92b2d54b82cb107170a34592fa923bce28051493" + integrity sha512-2fuO/8PdWTcXIyPK0jI1nNG0mj9x3c1wcsob7dUcwiHme5yDMUb1OX9vPfSD0TCiYJYLOzuU6WDL9s6d/lWGOg== + dependencies: + "@ethereumjs/tx" "3.0.0" + "@keystonehq/base-eth-keyring" "^0.3.2" + "@keystonehq/bc-ur-registry-eth" "^0.7.7" + "@keystonehq/sdk" "^0.9.1" + "@metamask/obs-store" "^7.0.0" + bs58check "^2.1.2" + ethereumjs-util "^7.0.8" + hdkey "^2.0.1" + uuid "^8.3.2" + "@keystonehq/eth-keyring@^0.14.0-alpha.10.3": version "0.14.0-alpha.10.3" resolved "https://registry.yarnpkg.com/@keystonehq/eth-keyring/-/eth-keyring-0.14.0-alpha.10.3.tgz#c2959dfe1ebc8e9eb83612f817a5e01535d7c0c8" @@ -854,6 +899,19 @@ rxjs "^6.6.3" typescript "^4.6.2" +"@keystonehq/sdk@^0.9.1": + version "0.9.1" + resolved "https://registry.yarnpkg.com/@keystonehq/sdk/-/sdk-0.9.1.tgz#d1084c967118046257b720fedd8fbe8bb845a1c7" + integrity sha512-tcKDvKQVoe/2tibsjF/19VQhq1vldC+DyhC30lA9XJbbh5tXSoNfqqUVbMvDqxino/vBHZQur6rDSHF8+KBoMw== + dependencies: + "@ngraveio/bc-ur" "^1.0.0" + qrcode.react "^1.0.1" + react "16.13.1" + react-dom "16.13.1" + react-modal "^3.12.1" + react-qr-reader "^2.2.1" + rxjs "^6.6.3" + "@ledgerhq/cryptoassets@^6.25.0": version "6.25.0" resolved "https://registry.yarnpkg.com/@ledgerhq/cryptoassets/-/cryptoassets-6.25.0.tgz#9e9307c69c436c938fafd27d5351526c21a2a114" @@ -2066,6 +2124,99 @@ dependencies: "@walletconnect/window-getters" "^1.0.0" +"@web3-onboard/coinbase@^2.0.0": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@web3-onboard/coinbase/-/coinbase-2.0.2.tgz#31a5b7f4afa04dddb34ddd748753f9f08a9de80a" + integrity sha512-LHEIG88+mwXua5wVQF0Cf3ECAjEede8R1/j+OBn11aIr1lrnKtUcuLnpFbyXnJbsaqRuE7fgJeUpJhVFFvTk2A== + dependencies: + "@coinbase/wallet-sdk" "^3.0.5" + "@web3-onboard/common" "^2.0.7" + +"@web3-onboard/common@^2.0.7", "@web3-onboard/common@^2.0.9": + version "2.0.9" + resolved "https://registry.yarnpkg.com/@web3-onboard/common/-/common-2.0.9.tgz#b53bf12f8a644f55fe8b09c5deb73531c2b90e9c" + integrity sha512-6qTIPAmLAkhcVPtSOyIUzscJ/rq3/xI42kVt8I4ZsUErd32QjhuydIndJJHWrEFAXT/6ZY6tFH2GZix9Fe8YzQ== + dependencies: + "@ethereumjs/common" "2.6.2" + ethers "5.5.4" + joi "^17.4.2" + rxjs "^7.5.2" + +"@web3-onboard/core@^2.2.8": + version "2.2.8" + resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.2.8.tgz#0a2c6aa991ea2ac0a0a471d5ee3bbf84aafd79df" + integrity sha512-nEEQR0/EyMbtMOz2yngyr992ElbYlICm7tZOwKfvq4nknGdnkEVmx74nr80H5M6/9nfZ5gJug2v8i/M3/YxcbQ== + dependencies: + "@web3-onboard/common" "^2.0.7" + bowser "^2.11.0" + ethers "5.5.3" + eventemitter3 "^4.0.7" + joi "17.6.0" + lodash.merge "^4.6.2" + lodash.partition "^4.6.0" + rxjs "^7.5.2" + svelte "^3.46.4" + svelte-i18n "^3.3.13" + +"@web3-onboard/injected-wallets@^2.0.5": + version "2.0.6" + resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.0.6.tgz#17a27cf687dfb57a03c4cddce75bc908bc80fc6b" + integrity sha512-Cpyd5U0GWDI8QZFCOlbDQU89La6ba/4CsXlNyqc8k1puhTSgi0GcL4sAEwkAKyjRc9YotOOzmR/OEvCLoVqLEQ== + dependencies: + "@web3-onboard/common" "^2.0.7" + joi "^17.4.2" + lodash.uniqby "^4.7.0" + +"@web3-onboard/keepkey@^2.0.1": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@web3-onboard/keepkey/-/keepkey-2.0.3.tgz#c7a0e9242385a7ce54d7314cd402caa63751c988" + integrity sha512-q6lSTujDCc22xTejpdT44jna7ZQQBbN4YEywush+iimq9ZBP9AcNqnddxtfqZvG1R3nssPFmpO/i5w0DVpL11A== + dependencies: + "@ethersproject/providers" "^5.5.0" + "@shapeshiftoss/hdwallet-core" "^1.15.2" + "@shapeshiftoss/hdwallet-keepkey-webusb" "^1.15.2" + "@web3-onboard/common" "^2.0.7" + ethereumjs-util "^7.1.3" + +"@web3-onboard/keystone@^2.0.1": + version "2.0.3" + resolved "https://registry.yarnpkg.com/@web3-onboard/keystone/-/keystone-2.0.3.tgz#da34e53f3a982d5954101e1e223c589d79afbd65" + integrity sha512-FWnBMoiJmKb0ZVCCns3OoQEMh2heM8RPkZ/pnEBnKKVZg2YDyefDmr5QqYR6Zlb3x6wgP/uq2brBlbPpoH/SLg== + dependencies: + "@ethereumjs/tx" "^3.4.0" + "@ethersproject/providers" "^5.5.0" + "@keystonehq/eth-keyring" "^0.11.2-alpha.2" + "@web3-onboard/common" "^2.0.7" + +"@web3-onboard/ledger@^2.0.1": + version "2.0.4" + resolved "https://registry.yarnpkg.com/@web3-onboard/ledger/-/ledger-2.0.4.tgz#306952ddce5b17c25de3e9643465083d28281218" + integrity sha512-eRh9C9/+c7Kkgk6TsSMNz1n31X5SLIn8Ip4cnxo8/z2/jS1I/KRpiKsUPXRF2X0EL0A3yhk0aCeiJR9+70sFqQ== + dependencies: + "@ethereumjs/tx" "^3.4.0" + "@ethersproject/providers" "^5.5.0" + "@ledgerhq/hw-app-eth" "^6.19.0" + "@ledgerhq/hw-transport-u2f" "^5.36.0-deprecated" + "@ledgerhq/hw-transport-webusb" "^6.19.0" + "@metamask/eth-sig-util" "^4.0.0" + "@web3-onboard/common" "^2.0.7" + buffer "^6.0.3" + ethereumjs-util "^7.1.3" + +"@web3-onboard/trezor@^2.0.2": + version "2.0.5" + resolved "https://registry.yarnpkg.com/@web3-onboard/trezor/-/trezor-2.0.5.tgz#9d381b05abc7861e2b2ed9283fcb04296f09b33b" + integrity sha512-ES7p7Tub5GoW/AjC8McIWsIOTKXO3NkkLjPS/VcBGslp5HM+KdRn3xmBGlGU6wQ4VGYQh66A8BJzd+27QGB7tA== + dependencies: + "@ethereumjs/tx" "^3.4.0" + "@ethersproject/providers" "^5.5.0" + "@web3-onboard/common" "^2.0.7" + buffer "^6.0.3" + eth-crypto "^2.1.0" + ethereumjs-util "^7.1.3" + hdkey "^2.0.1" + trezor-connect "^8.2.6" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" From d175daada1a7eec3283046f4404ab09d3c83ae7f Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Wed, 1 Jun 2022 20:58:22 -0400 Subject: [PATCH 02/15] updatedBalances --- packages/core/src/store/actions.ts | 25 ++---------- packages/core/src/store/index.ts | 63 ++++++----------------------- packages/core/src/updateBalances.ts | 0 3 files changed, 16 insertions(+), 72 deletions(-) create mode 100644 packages/core/src/updateBalances.ts diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index c211272b6..ec0c573a1 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -15,8 +15,7 @@ import type { UpdateAccountAction, UpdateAccountCenterAction, UpdateWalletAction, - WalletState, - UpdateBalancesAction + WalletState } from '../types' import { @@ -24,8 +23,7 @@ import { validateLocale, validateString, validateWallet, - validateWalletInit, - validateUpdateBalances + validateWalletInit } from '../validation' import { @@ -37,8 +35,7 @@ import { UPDATE_ACCOUNT, UPDATE_ACCOUNT_CENTER, SET_WALLET_MODULES, - SET_LOCALE, - UPDATE_BALANCES + SET_LOCALE } from './constants' export function addChains(chains: Chain[]): void { @@ -183,19 +180,3 @@ export function setLocale(locale: string): void { dispatch(action as SetLocaleAction) } - -export function updateBalances(addresses?: string[]): void { - - const error = validateUpdateBalances(addresses) - - if (error) { - throw error - } - - const action = { - type: UPDATE_BALANCES, - payload: addresses - } - - dispatch(action as UpdateBalancesAction) -} diff --git a/packages/core/src/store/index.ts b/packages/core/src/store/index.ts index 4851a0e15..8c5967bd2 100644 --- a/packages/core/src/store/index.ts +++ b/packages/core/src/store/index.ts @@ -6,8 +6,6 @@ import type { Chain, WalletModule } from '@web3-onboard/common' import { APP_INITIAL_STATE } from '../constants' import { notNullish } from '../utils' -import { getBalance } from '../provider' - import type { AppState, WalletState, @@ -16,8 +14,7 @@ import type { AddWalletAction, UpdateAccountAction, UpdateAccountCenterAction, - Locale, - UpdateBalancesAction + Locale } from '../types' import { @@ -29,11 +26,10 @@ import { UPDATE_ACCOUNT, UPDATE_ACCOUNT_CENTER, SET_WALLET_MODULES, - SET_LOCALE, - UPDATE_BALANCES + SET_LOCALE } from './constants' -async function reducer(state: AppState, action: Action): Promise { +function reducer(state: AppState, action: Action): AppState { const { type, payload } = action switch (type) { @@ -74,37 +70,6 @@ async function reducer(state: AppState, action: Action): Promise { } } - case UPDATE_BALANCES: { - const addresses = payload as UpdateBalancesAction['payload'] - const { wallets, chains } = state - - const updatedWallets = await Promise.all( - wallets.map(async wallet => { - const chain = chains.find(({ id }) => id === wallet.chains[0].id) - - const updatedAccounts = await Promise.all( - wallet.accounts.map(async account => { - // if no addresses then we want to update all address balances - // otherwise check if address is in the supplied addresses array - if (!addresses || addresses.includes(account.address)) { - const updatedBalance = await getBalance(account.address, chain) - return { ...account, balance: updatedBalance } - } - - return account - }) - ) - - return { ...wallet, accounts: updatedAccounts } - }) - ) - - return { - ...state, - wallets: updatedWallets - } - } - case REMOVE_WALLET: { const update = payload as { id: string } return { @@ -176,22 +141,20 @@ const _stateUpdates = new Subject() _stateUpdates.subscribe(_store) -export async function dispatch(action: Action): Promise { - const state = await _store.getValue() - const nextState = await reducer(state, action) - _stateUpdates.next(nextState) +export function dispatch(action: Action): void { + const state = _store.getValue() + _stateUpdates.next(reducer(state, action)) } -async function select(): Promise> -async function select(stateKey: T): - Promise> -async function select( +function select(): Observable +function select(stateKey: T): Observable +function select( stateKey?: keyof AppState -): Promise | Observable> { +): Observable | Observable { if (!stateKey) return _stateUpdates.asObservable() - const validStateKeys = await Object.keys(_store.getValue()) - + const validStateKeys = Object.keys(_store.getValue()) + if (!validStateKeys.includes(String(stateKey))) { throw new Error(`key: ${stateKey} does not exist on this store`) } @@ -212,4 +175,4 @@ function get(): AppState { export const state = { select, get -} +} \ No newline at end of file diff --git a/packages/core/src/updateBalances.ts b/packages/core/src/updateBalances.ts new file mode 100644 index 000000000..e69de29bb From 276b1ecb92f0bd0c21b062e41a202123a0ff6e33 Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Thu, 2 Jun 2022 17:46:48 -0400 Subject: [PATCH 03/15] update_balance --- packages/core/src/index.ts | 7 +++-- packages/core/src/store/actions.ts | 27 ++++++++++++++++-- packages/core/src/store/constants.ts | 3 +- packages/core/src/store/index.ts | 15 ++++++++-- packages/core/src/streams.ts | 24 ++-------------- packages/core/src/types.ts | 10 +++++-- packages/core/src/updateBalances.ts | 41 ++++++++++++++++++++++++++++ packages/core/src/validation.ts | 11 ++++++-- packages/demo/src/App.svelte | 3 ++ 9 files changed, 107 insertions(+), 34 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index a87e3fb05..7b1db168c 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,7 +7,7 @@ import { addChains, setWalletModules, updateAccountCenter, - setLocale + setLocale, } from './store/actions' import { reset$, internalState$ } from './streams' import { validateInitOptions } from './validation' @@ -18,6 +18,8 @@ import type { InitOptions, OnboardAPI } from './types' import { APP_INITIAL_STATE } from './constants' import { getDevice } from './utils' +import updateBalances from './updateBalances' + const API = { connectWallet, disconnectWallet, @@ -27,7 +29,8 @@ const API = { select: state.select, actions: { setWalletModules, - setLocale + setLocale, + updateBalances } } } diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index ec0c573a1..57158c56f 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -15,7 +15,8 @@ import type { UpdateAccountAction, UpdateAccountCenterAction, UpdateWalletAction, - WalletState + WalletState, + UpdateAllWalletsAction } from '../types' import { @@ -23,7 +24,8 @@ import { validateLocale, validateString, validateWallet, - validateWalletInit + validateWalletInit, + validateUpdateBalances } from '../validation' import { @@ -35,7 +37,8 @@ import { UPDATE_ACCOUNT, UPDATE_ACCOUNT_CENTER, SET_WALLET_MODULES, - SET_LOCALE + SET_LOCALE, + UPDATE_ALL_WALLETS } from './constants' export function addChains(chains: Chain[]): void { @@ -180,3 +183,21 @@ export function setLocale(locale: string): void { dispatch(action as SetLocaleAction) } + +export function updateAllWallets(wallets: WalletState[]): void { + const error = validateUpdateBalances(wallets) + + if (error) { + throw error + } + + const action = { + type: UPDATE_ALL_WALLETS, + payload: wallets + } + + console.log(4, wallets) + + dispatch(action as UpdateAllWalletsAction) + +} \ No newline at end of file diff --git a/packages/core/src/store/constants.ts b/packages/core/src/store/constants.ts index a6efbd50a..5b0188276 100644 --- a/packages/core/src/store/constants.ts +++ b/packages/core/src/store/constants.ts @@ -7,4 +7,5 @@ export const UPDATE_ACCOUNT = 'update_account' export const UPDATE_ACCOUNT_CENTER = 'update_account_center' export const SET_WALLET_MODULES = 'set_wallet_modules' export const SET_LOCALE= 'set_locale' -export const UPDATE_BALANCES = 'update_balance' +// export const UPDATE_BALANCES = 'update_balance' +export const UPDATE_ALL_WALLETS = 'update_balance' diff --git a/packages/core/src/store/index.ts b/packages/core/src/store/index.ts index 8c5967bd2..d7e45f45a 100644 --- a/packages/core/src/store/index.ts +++ b/packages/core/src/store/index.ts @@ -14,7 +14,8 @@ import type { AddWalletAction, UpdateAccountAction, UpdateAccountCenterAction, - Locale + Locale, + UpdateAllWalletsAction } from '../types' import { @@ -26,7 +27,8 @@ import { UPDATE_ACCOUNT, UPDATE_ACCOUNT_CENTER, SET_WALLET_MODULES, - SET_LOCALE + SET_LOCALE, + UPDATE_ALL_WALLETS } from './constants' function reducer(state: AppState, action: Action): AppState { @@ -102,6 +104,14 @@ function reducer(state: AppState, action: Action): AppState { } } + case UPDATE_ALL_WALLETS : { + const updatedWallets = payload as UpdateAllWalletsAction['payload'] + return { + ...state, + wallets: updatedWallets + } + } + case UPDATE_ACCOUNT_CENTER: { const update = payload as UpdateAccountCenterAction['payload'] return { @@ -112,6 +122,7 @@ function reducer(state: AppState, action: Action): AppState { } } } + case SET_WALLET_MODULES: { return { ...state, diff --git a/packages/core/src/streams.ts b/packages/core/src/streams.ts index 9de076189..61f428bc3 100644 --- a/packages/core/src/streams.ts +++ b/packages/core/src/streams.ts @@ -1,6 +1,6 @@ import type { Chain } from '@web3-onboard/common' import { onDestroy, onMount, beforeUpdate, afterUpdate } from 'svelte' -import { Observable, Subject, defer, BehaviorSubject, empty } from 'rxjs' +import { Observable, Subject, defer, BehaviorSubject } from 'rxjs' import { take, takeUntil, @@ -33,29 +33,11 @@ export const switchChainModal$ = new BehaviorSubject(null) - -async function fetchWalletUpdates() { - const walletsA$ = await state.select('wallets') - return walletsA$ -} - -let walt$ - -(async () => { -try { - walt$ = await fetchWalletUpdates() -}catch (e) { - console.log(e) -} -})(); - export const wallets$ = ( - walt$ as Observable + state.select('wallets') as Observable ).pipe(shareReplay(1)) -// export const wallets$ = ( -// state.select('wallets') as Observable -// ).pipe(shareReplay(1)) + // reset logic reset$.pipe(withLatestFrom(wallets$), pluck('1')).subscribe(wallets => { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index cc675c9f4..9bef2b325 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -136,7 +136,7 @@ export type Action = | UpdateAccountCenterAction | SetWalletModulesAction | SetLocaleAction - | UpdateBalancesAction + | UpdateAllWalletsAction export type AddChainsAction = { type: 'add_chains'; payload: Chain[] } export type AddWalletAction = { type: 'add_wallet'; payload: WalletState } @@ -176,11 +176,15 @@ export type SetLocaleAction = { payload: string } -export type UpdateBalancesAction = { +export type UpdateAllWalletsAction = { type: 'update_balance' - payload: string[] + payload: WalletState[] + // payload: AppState['wallets'] + // payload?: string[] } + + // ==== MISC ==== // export type ChainStyle = { icon: string diff --git a/packages/core/src/updateBalances.ts b/packages/core/src/updateBalances.ts index e69de29bb..4dde7a187 100644 --- a/packages/core/src/updateBalances.ts +++ b/packages/core/src/updateBalances.ts @@ -0,0 +1,41 @@ +import { state } from './store' +import type { AppState, WalletState } from './types' +import { getBalance } from './provider' + +async function updateBalances(addresses?: string[]): Promise { + const { wallets, chains } = state.get() + + const updatedWallets = await Promise.all( + wallets.map(async wallet => { + const chain = chains.find(({ id }) => id === wallet.chains[0].id) + + const updatedAccounts = await Promise.all( + wallet.accounts.map(async account => { + // if no addresses then we want to update all address balances + // otherwise check if address is in addresses array + if (!addresses || addresses.includes(account.address)) { + + const updatedBalance = await getBalance(account.address, chain) + + console.log(1, updatedBalance) + + return { ...account, balance: updatedBalance } + } + + return account + }) + ) + console.log(2, updatedAccounts) + return { ...wallet, accounts: updatedAccounts } + }) + ) + + console.log(3, updatedWallets) + return { + ...state, + wallets: updatedWallets + } + +} + +export default updateBalances \ No newline at end of file diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index a6e4e181d..b323857a2 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -65,6 +65,9 @@ const wallet = Joi.object({ chains: Joi.array().items(connectedChain) }) +const wallets = Joi.array().items(wallet) + + const recommendedWallet = Joi.object({ name: Joi.string().required(), url: Joi.string().uri().required() @@ -212,6 +215,10 @@ export function validateLocale(data: string): ValidateReturn { return validate(locale, data) } -export function validateUpdateBalances(data: string[]): ValidateReturn { - return validate(addresses, data) +export function validateUpdateBalances(data: +WalletState[]): ValidateReturn { + return validate(wallets, data) } +// export function validateUpdateBalances(data?: string[]): ValidateReturn { +// return validate(addresses, data) +// } diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index f3adaa7ec..8e73c0565 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -356,6 +356,9 @@ > Disconnect Wallet + {/each} {/if} From 230c024794635cf8c97dffeff4e6becad50b2bb7 Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 3 Jun 2022 18:00:25 -0400 Subject: [PATCH 04/15] update balances --- packages/core/README.md | 8 ++++++++ packages/core/package.json | 2 +- packages/core/src/index.ts | 23 +++++++++++++++-------- packages/core/src/store/actions.ts | 4 +--- packages/core/src/store/constants.ts | 1 - packages/core/src/types.ts | 2 -- packages/core/src/updateBalances.ts | 16 ++++------------ packages/core/src/validation.ts | 6 ++---- packages/demo/package.json | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/core/README.md b/packages/core/README.md index f8b17bc92..1c3031096 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -414,6 +414,14 @@ const onboard = Onboard({ // then after a user action, you may decide to only display hardware wallets on the next call to onboard.connectWallet onboard.state.actions.setWalletModules([ledger, trezor]) + +//or you may decide to get updated balances after a user action using the `updatedBalances` function +onboard.state.actions.updateBalances() // update all balances for all connected addresses +onboard.state.actions.updateBalances(['0xfdadfadsadsadsadasdsa']) // update balance for one address +onboard.state.actions.updateBalances([ + '0xfdadfadsadsadsadasdsa', + '0xfdsafdsfdsfdsfds' +]) // update balance for two addresses ``` ## Setting the User's Chain/Network diff --git a/packages/core/package.json b/packages/core/package.json index 94e49f2d8..a07819db8 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/core", - "version": "2.2.10", + "version": "2.2.10-alpha.1", "scripts": { "build": "rollup -c", "dev": "rollup -c -w", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index c9ba7b0a0..44f93e179 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -9,17 +9,20 @@ import { updateAccountCenter, setLocale, } from './store/actions' -import { reset$ } from './streams' +import { reset$, internalState$ } from './streams' import { validateInitOptions } from './validation' import initI18N from './i18n' import App from './views/Index.svelte' import type { InitOptions, OnboardAPI } from './types' import { APP_INITIAL_STATE } from './constants' -import { internalState } from './internals' +import { getDevice } from './utils' import updateBalances from './updateBalances' + + + const API = { connectWallet, disconnectWallet, @@ -62,8 +65,8 @@ function init(options: InitOptions): OnboardAPI { initI18N(i18n) addChains(chains) - const { device, svelteInstance } = internalState - + const device = getDevice() + // update accountCenter if (typeof accountCenter !== 'undefined') { let accountCenterUpdate @@ -81,7 +84,9 @@ function init(options: InitOptions): OnboardAPI { } updateAccountCenter(accountCenterUpdate) - } + } + + const { svelteInstance } = internalState$.getValue() if (svelteInstance) { // if already initialized, need to cleanup old instance @@ -91,9 +96,11 @@ function init(options: InitOptions): OnboardAPI { const app = svelteInstance || mountApp() - // update metadata and app internal state - internalState.appMetadata = appMetadata - internalState.svelteInstance = app + internalState$.next({ + appMetadata, + svelteInstance: app, + device + }) setWalletModules(wallets) diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index 18f220abd..b1f791ef6 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -182,7 +182,7 @@ export function setLocale(locale: string): void { export function updateAllWallets(wallets: WalletState[]): void { const error = validateUpdateBalances(wallets) - + if (error) { throw error } @@ -192,8 +192,6 @@ export function updateAllWallets(wallets: WalletState[]): void { payload: wallets } - console.log(4, wallets) - dispatch(action as UpdateAllWalletsAction) } diff --git a/packages/core/src/store/constants.ts b/packages/core/src/store/constants.ts index 5b0188276..b54afcef3 100644 --- a/packages/core/src/store/constants.ts +++ b/packages/core/src/store/constants.ts @@ -7,5 +7,4 @@ export const UPDATE_ACCOUNT = 'update_account' export const UPDATE_ACCOUNT_CENTER = 'update_account_center' export const SET_WALLET_MODULES = 'set_wallet_modules' export const SET_LOCALE= 'set_locale' -// export const UPDATE_BALANCES = 'update_balance' export const UPDATE_ALL_WALLETS = 'update_balance' diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 7fecd4901..35a9afc36 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -179,8 +179,6 @@ export type SetLocaleAction = { export type UpdateAllWalletsAction = { type: 'update_balance' payload: WalletState[] - // payload: AppState['wallets'] - // payload?: string[] } diff --git a/packages/core/src/updateBalances.ts b/packages/core/src/updateBalances.ts index 4dde7a187..642a3cfd3 100644 --- a/packages/core/src/updateBalances.ts +++ b/packages/core/src/updateBalances.ts @@ -1,8 +1,8 @@ import { state } from './store' -import type { AppState, WalletState } from './types' import { getBalance } from './provider' +import { updateAllWallets } from './store/actions' -async function updateBalances(addresses?: string[]): Promise { +async function updateBalances(addresses?: string[]): Promise { const { wallets, chains } = state.get() const updatedWallets = await Promise.all( @@ -11,31 +11,23 @@ async function updateBalances(addresses?: string[]): Promise { const updatedAccounts = await Promise.all( wallet.accounts.map(async account => { - // if no addresses then we want to update all address balances + // if no provided addresses, we want to update all balances // otherwise check if address is in addresses array if (!addresses || addresses.includes(account.address)) { const updatedBalance = await getBalance(account.address, chain) - console.log(1, updatedBalance) - return { ...account, balance: updatedBalance } } return account }) ) - console.log(2, updatedAccounts) return { ...wallet, accounts: updatedAccounts } }) ) - console.log(3, updatedWallets) - return { - ...state, - wallets: updatedWallets - } - + updateAllWallets(updatedWallets) } export default updateBalances \ No newline at end of file diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index b323857a2..bba0ac788 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -102,7 +102,8 @@ const walletInit = Joi.array().items(Joi.function()).required() const locale = Joi.string() -const addresses = Joi.array().items(Joi.string().pattern(/^0x[a-fA-F0-9]{40}$/)) +// const addresses = +//Joi.array().items(Joi.string().pattern(/^0x[a-fA-F0-9]{40}$/)) const accountCenterPosition = Joi.string().valid( 'topRight', @@ -219,6 +220,3 @@ export function validateUpdateBalances(data: WalletState[]): ValidateReturn { return validate(wallets, data) } -// export function validateUpdateBalances(data?: string[]): ValidateReturn { -// return validate(addresses, data) -// } diff --git a/packages/demo/package.json b/packages/demo/package.json index eea185090..ccbfbde1c 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@web3-onboard/coinbase": "^2.0.3", - "@web3-onboard/core": "^2.2.9", + "@web3-onboard/core": "^2.2.10-alpha.1", "@web3-onboard/fortmatic": "^2.0.2", "@web3-onboard/gnosis": "^2.0.1", "@web3-onboard/injected-wallets": "^2.0.7", From 967a7a5ab276e29bed42794458f7d05a3c88bca1 Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 3 Jun 2022 18:16:01 -0400 Subject: [PATCH 05/15] merge develop --- packages/core/package.json | 2 +- packages/core/src/index.ts | 28 +++---- packages/react/package.json | 4 +- yarn.lock | 151 ------------------------------------ 4 files changed, 13 insertions(+), 172 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index a07819db8..ed04ffe73 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/core", - "version": "2.2.10-alpha.1", + "version": "2.2.11-alpha.1", "scripts": { "build": "rollup -c", "dev": "rollup -c -w", diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 44f93e179..20405eafb 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -7,22 +7,18 @@ import { addChains, setWalletModules, updateAccountCenter, - setLocale, + setLocale } from './store/actions' -import { reset$, internalState$ } from './streams' +import { reset$ } from './streams' import { validateInitOptions } from './validation' import initI18N from './i18n' import App from './views/Index.svelte' import type { InitOptions, OnboardAPI } from './types' import { APP_INITIAL_STATE } from './constants' -import { getDevice } from './utils' - +import { internalState } from './internals' import updateBalances from './updateBalances' - - - const API = { connectWallet, disconnectWallet, @@ -65,8 +61,8 @@ function init(options: InitOptions): OnboardAPI { initI18N(i18n) addChains(chains) - const device = getDevice() - + const { device, svelteInstance } = internalState + // update accountCenter if (typeof accountCenter !== 'undefined') { let accountCenterUpdate @@ -84,9 +80,7 @@ function init(options: InitOptions): OnboardAPI { } updateAccountCenter(accountCenterUpdate) - } - - const { svelteInstance } = internalState$.getValue() + } if (svelteInstance) { // if already initialized, need to cleanup old instance @@ -96,11 +90,9 @@ function init(options: InitOptions): OnboardAPI { const app = svelteInstance || mountApp() - internalState$.next({ - appMetadata, - svelteInstance: app, - device - }) + // update metadata and app internal state + internalState.appMetadata = appMetadata + internalState.svelteInstance = app setWalletModules(wallets) @@ -234,4 +226,4 @@ function mountApp() { return app } -export default init +export default init \ No newline at end of file diff --git a/packages/react/package.json b/packages/react/package.json index df20c5b95..a6f51f962 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/react", - "version": "2.1.7", + "version": "2.1.8-alpha.1", "description": "Collection of React Hooks for web3-onboard", "module": "dist/index.js", "browser": "dist/index.js", @@ -21,7 +21,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/core": "^2.2.9", + "@web3-onboard/core": "^2.2.11-alpha.1", "@web3-onboard/common": "^2.1.0" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index b79564901..fad265bae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -795,17 +795,6 @@ google-protobuf "^3.7.0-rc.2" pbjs "^0.0.5" -"@keystonehq/base-eth-keyring@^0.3.2": - version "0.3.2" - resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.3.2.tgz#71efe1495d4931fab5fd0016c8722fe5d9657da9" - integrity sha512-y/kv8XNRSzqcSl7fvZklBKr4MVir1OJHzqM5vC+3yvzkh3mVtN8vUjAAxHtmVVVyM8rsdqK7aYZ7paexYdpnag== - dependencies: - "@ethereumjs/tx" "3.0.0" - "@keystonehq/bc-ur-registry-eth" "^0.7.7" - ethereumjs-util "^7.0.8" - hdkey "^2.0.1" - uuid "^8.3.2" - "@keystonehq/base-eth-keyring@^0.6.0-alpha.1": version "0.6.0-alpha.1" resolved "https://registry.yarnpkg.com/@keystonehq/base-eth-keyring/-/base-eth-keyring-0.6.0-alpha.1.tgz#ff19689eb07a54aefdc21394a51c117660f7a0d2" @@ -827,25 +816,6 @@ hdkey "^2.0.1" uuid "^8.3.2" -"@keystonehq/bc-ur-registry-eth@^0.7.7": - version "0.7.7" - resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry-eth/-/bc-ur-registry-eth-0.7.7.tgz#45267510900049050ef860a1e78fde9087b75972" - integrity sha512-2gZf18ogSCLjsn3PxGqwiOMz/G11v7byRnTLv5/wNJGzCqkMf86OKaVbUgsVokq0B5KAZtpCFQxj96rrFhPRiQ== - dependencies: - "@keystonehq/bc-ur-registry" "^0.4.4" - ethereumjs-util "^7.0.8" - hdkey "^2.0.1" - uuid "^8.3.2" - -"@keystonehq/bc-ur-registry@^0.4.4": - version "0.4.4" - resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry/-/bc-ur-registry-0.4.4.tgz#3073fdd4b33cdcbd04526a313a7685891a4b4583" - integrity sha512-SBdKdAZfp3y14GTGrKjfJJHf4iXObjcm4/qKUZ92lj8HVR8mxHHGmHksjE328bJPTAsJPloLix4rTnWg+qgS2w== - dependencies: - "@ngraveio/bc-ur" "^1.1.5" - base58check "^2.0.0" - tslib "^2.3.0" - "@keystonehq/bc-ur-registry@^0.5.0-alpha.5": version "0.5.0-alpha.6" resolved "https://registry.yarnpkg.com/@keystonehq/bc-ur-registry/-/bc-ur-registry-0.5.0-alpha.6.tgz#56868a7deeeaf5315a7fff6c0b42f3d31555a5c2" @@ -855,21 +825,6 @@ base58check "^2.0.0" tslib "^2.3.0" -"@keystonehq/eth-keyring@^0.11.2-alpha.2": - version "0.11.2" - resolved "https://registry.yarnpkg.com/@keystonehq/eth-keyring/-/eth-keyring-0.11.2.tgz#92b2d54b82cb107170a34592fa923bce28051493" - integrity sha512-2fuO/8PdWTcXIyPK0jI1nNG0mj9x3c1wcsob7dUcwiHme5yDMUb1OX9vPfSD0TCiYJYLOzuU6WDL9s6d/lWGOg== - dependencies: - "@ethereumjs/tx" "3.0.0" - "@keystonehq/base-eth-keyring" "^0.3.2" - "@keystonehq/bc-ur-registry-eth" "^0.7.7" - "@keystonehq/sdk" "^0.9.1" - "@metamask/obs-store" "^7.0.0" - bs58check "^2.1.2" - ethereumjs-util "^7.0.8" - hdkey "^2.0.1" - uuid "^8.3.2" - "@keystonehq/eth-keyring@^0.14.0-alpha.10.3": version "0.14.0-alpha.10.3" resolved "https://registry.yarnpkg.com/@keystonehq/eth-keyring/-/eth-keyring-0.14.0-alpha.10.3.tgz#c2959dfe1ebc8e9eb83612f817a5e01535d7c0c8" @@ -899,19 +854,6 @@ rxjs "^6.6.3" typescript "^4.6.2" -"@keystonehq/sdk@^0.9.1": - version "0.9.1" - resolved "https://registry.yarnpkg.com/@keystonehq/sdk/-/sdk-0.9.1.tgz#d1084c967118046257b720fedd8fbe8bb845a1c7" - integrity sha512-tcKDvKQVoe/2tibsjF/19VQhq1vldC+DyhC30lA9XJbbh5tXSoNfqqUVbMvDqxino/vBHZQur6rDSHF8+KBoMw== - dependencies: - "@ngraveio/bc-ur" "^1.0.0" - qrcode.react "^1.0.1" - react "16.13.1" - react-dom "16.13.1" - react-modal "^3.12.1" - react-qr-reader "^2.2.1" - rxjs "^6.6.3" - "@ledgerhq/cryptoassets@^6.25.0": version "6.25.0" resolved "https://registry.yarnpkg.com/@ledgerhq/cryptoassets/-/cryptoassets-6.25.0.tgz#9e9307c69c436c938fafd27d5351526c21a2a114" @@ -2124,99 +2066,6 @@ dependencies: "@walletconnect/window-getters" "^1.0.0" -"@web3-onboard/coinbase@^2.0.0": - version "2.0.2" - resolved "https://registry.yarnpkg.com/@web3-onboard/coinbase/-/coinbase-2.0.2.tgz#31a5b7f4afa04dddb34ddd748753f9f08a9de80a" - integrity sha512-LHEIG88+mwXua5wVQF0Cf3ECAjEede8R1/j+OBn11aIr1lrnKtUcuLnpFbyXnJbsaqRuE7fgJeUpJhVFFvTk2A== - dependencies: - "@coinbase/wallet-sdk" "^3.0.5" - "@web3-onboard/common" "^2.0.7" - -"@web3-onboard/common@^2.0.7", "@web3-onboard/common@^2.0.9": - version "2.0.9" - resolved "https://registry.yarnpkg.com/@web3-onboard/common/-/common-2.0.9.tgz#b53bf12f8a644f55fe8b09c5deb73531c2b90e9c" - integrity sha512-6qTIPAmLAkhcVPtSOyIUzscJ/rq3/xI42kVt8I4ZsUErd32QjhuydIndJJHWrEFAXT/6ZY6tFH2GZix9Fe8YzQ== - dependencies: - "@ethereumjs/common" "2.6.2" - ethers "5.5.4" - joi "^17.4.2" - rxjs "^7.5.2" - -"@web3-onboard/core@^2.2.8": - version "2.2.8" - resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.2.8.tgz#0a2c6aa991ea2ac0a0a471d5ee3bbf84aafd79df" - integrity sha512-nEEQR0/EyMbtMOz2yngyr992ElbYlICm7tZOwKfvq4nknGdnkEVmx74nr80H5M6/9nfZ5gJug2v8i/M3/YxcbQ== - dependencies: - "@web3-onboard/common" "^2.0.7" - bowser "^2.11.0" - ethers "5.5.3" - eventemitter3 "^4.0.7" - joi "17.6.0" - lodash.merge "^4.6.2" - lodash.partition "^4.6.0" - rxjs "^7.5.2" - svelte "^3.46.4" - svelte-i18n "^3.3.13" - -"@web3-onboard/injected-wallets@^2.0.5": - version "2.0.6" - resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.0.6.tgz#17a27cf687dfb57a03c4cddce75bc908bc80fc6b" - integrity sha512-Cpyd5U0GWDI8QZFCOlbDQU89La6ba/4CsXlNyqc8k1puhTSgi0GcL4sAEwkAKyjRc9YotOOzmR/OEvCLoVqLEQ== - dependencies: - "@web3-onboard/common" "^2.0.7" - joi "^17.4.2" - lodash.uniqby "^4.7.0" - -"@web3-onboard/keepkey@^2.0.1": - version "2.0.3" - resolved "https://registry.yarnpkg.com/@web3-onboard/keepkey/-/keepkey-2.0.3.tgz#c7a0e9242385a7ce54d7314cd402caa63751c988" - integrity sha512-q6lSTujDCc22xTejpdT44jna7ZQQBbN4YEywush+iimq9ZBP9AcNqnddxtfqZvG1R3nssPFmpO/i5w0DVpL11A== - dependencies: - "@ethersproject/providers" "^5.5.0" - "@shapeshiftoss/hdwallet-core" "^1.15.2" - "@shapeshiftoss/hdwallet-keepkey-webusb" "^1.15.2" - "@web3-onboard/common" "^2.0.7" - ethereumjs-util "^7.1.3" - -"@web3-onboard/keystone@^2.0.1": - version "2.0.3" - resolved "https://registry.yarnpkg.com/@web3-onboard/keystone/-/keystone-2.0.3.tgz#da34e53f3a982d5954101e1e223c589d79afbd65" - integrity sha512-FWnBMoiJmKb0ZVCCns3OoQEMh2heM8RPkZ/pnEBnKKVZg2YDyefDmr5QqYR6Zlb3x6wgP/uq2brBlbPpoH/SLg== - dependencies: - "@ethereumjs/tx" "^3.4.0" - "@ethersproject/providers" "^5.5.0" - "@keystonehq/eth-keyring" "^0.11.2-alpha.2" - "@web3-onboard/common" "^2.0.7" - -"@web3-onboard/ledger@^2.0.1": - version "2.0.4" - resolved "https://registry.yarnpkg.com/@web3-onboard/ledger/-/ledger-2.0.4.tgz#306952ddce5b17c25de3e9643465083d28281218" - integrity sha512-eRh9C9/+c7Kkgk6TsSMNz1n31X5SLIn8Ip4cnxo8/z2/jS1I/KRpiKsUPXRF2X0EL0A3yhk0aCeiJR9+70sFqQ== - dependencies: - "@ethereumjs/tx" "^3.4.0" - "@ethersproject/providers" "^5.5.0" - "@ledgerhq/hw-app-eth" "^6.19.0" - "@ledgerhq/hw-transport-u2f" "^5.36.0-deprecated" - "@ledgerhq/hw-transport-webusb" "^6.19.0" - "@metamask/eth-sig-util" "^4.0.0" - "@web3-onboard/common" "^2.0.7" - buffer "^6.0.3" - ethereumjs-util "^7.1.3" - -"@web3-onboard/trezor@^2.0.2": - version "2.0.5" - resolved "https://registry.yarnpkg.com/@web3-onboard/trezor/-/trezor-2.0.5.tgz#9d381b05abc7861e2b2ed9283fcb04296f09b33b" - integrity sha512-ES7p7Tub5GoW/AjC8McIWsIOTKXO3NkkLjPS/VcBGslp5HM+KdRn3xmBGlGU6wQ4VGYQh66A8BJzd+27QGB7tA== - dependencies: - "@ethereumjs/tx" "^3.4.0" - "@ethersproject/providers" "^5.5.0" - "@web3-onboard/common" "^2.0.7" - buffer "^6.0.3" - eth-crypto "^2.1.0" - ethereumjs-util "^7.1.3" - hdkey "^2.0.1" - trezor-connect "^8.2.6" - "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" From 992a4cd173b57fac5816ff72c596ceaf5a89303c Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 3 Jun 2022 18:29:22 -0400 Subject: [PATCH 06/15] cleanup --- packages/core/src/streams.ts | 2 -- packages/core/src/validation.ts | 1 - packages/demo/src/App.svelte | 10 ---------- 3 files changed, 13 deletions(-) diff --git a/packages/core/src/streams.ts b/packages/core/src/streams.ts index 7f72b1f37..a09ea6c13 100644 --- a/packages/core/src/streams.ts +++ b/packages/core/src/streams.ts @@ -31,8 +31,6 @@ export const wallets$ = ( state.select('wallets') as Observable ).pipe(shareReplay(1)) - - // reset logic reset$.pipe(withLatestFrom(wallets$), pluck('1')).subscribe(wallets => { // disconnect all wallets diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index bba0ac788..00176316d 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -67,7 +67,6 @@ const wallet = Joi.object({ const wallets = Joi.array().items(wallet) - const recommendedWallet = Joi.object({ name: Joi.string().required(), url: Joi.string().uri().required() diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 7694af8e8..4f866b9d7 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -177,16 +177,6 @@ }) // Subscribe to wallet updates - // const wallets$ = Promise.resolve([]) - - // async function fetchWalletUpdates() { - // return await onboard.state - // .select('wallets') - // .pipe(share()) /*Ωignore_startΩ*/ - // } - - // wallets$ = fetchWalletUpdates - const wallets$ = onboard.state.select('wallets').pipe(share()) const signTransactionMessage = async provider => { From fd1d2b25cea917b9d9cf7e0242934524363237ea Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 3 Jun 2022 18:31:03 -0400 Subject: [PATCH 07/15] cleanup --- packages/core/src/types.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 35a9afc36..2ede5aecf 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -181,8 +181,6 @@ export type UpdateAllWalletsAction = { payload: WalletState[] } - - // ==== MISC ==== // export type ChainStyle = { icon: string From f8a162deafd5f00de48ac08295bc651cd4f33cbb Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 3 Jun 2022 18:34:16 -0400 Subject: [PATCH 08/15] cleanup --- packages/core/src/store/actions.ts | 1 - packages/core/src/updateBalances.ts | 2 +- packages/demo/package.json | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/core/src/store/actions.ts b/packages/core/src/store/actions.ts index b1f791ef6..db6b4cf0f 100644 --- a/packages/core/src/store/actions.ts +++ b/packages/core/src/store/actions.ts @@ -193,7 +193,6 @@ export function updateAllWallets(wallets: WalletState[]): void { } dispatch(action as UpdateAllWalletsAction) - } // ==== HELPERS ==== // diff --git a/packages/core/src/updateBalances.ts b/packages/core/src/updateBalances.ts index 642a3cfd3..b2a82ec14 100644 --- a/packages/core/src/updateBalances.ts +++ b/packages/core/src/updateBalances.ts @@ -27,7 +27,7 @@ async function updateBalances(addresses?: string[]): Promise { }) ) - updateAllWallets(updatedWallets) + updateAllWallets(updatedWallets) } export default updateBalances \ No newline at end of file diff --git a/packages/demo/package.json b/packages/demo/package.json index ccbfbde1c..eea185090 100644 --- a/packages/demo/package.json +++ b/packages/demo/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@web3-onboard/coinbase": "^2.0.3", - "@web3-onboard/core": "^2.2.10-alpha.1", + "@web3-onboard/core": "^2.2.9", "@web3-onboard/fortmatic": "^2.0.2", "@web3-onboard/gnosis": "^2.0.1", "@web3-onboard/injected-wallets": "^2.0.7", From 2b6fed59485da2ba9229d2d3d44b9af647997ec3 Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Fri, 3 Jun 2022 18:50:59 -0400 Subject: [PATCH 09/15] Readme update --- packages/core/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/core/README.md b/packages/core/README.md index 1c3031096..a6f43fcc9 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -414,8 +414,12 @@ const onboard = Onboard({ // then after a user action, you may decide to only display hardware wallets on the next call to onboard.connectWallet onboard.state.actions.setWalletModules([ledger, trezor]) +``` + +**updatedBalances** +You may decide to get updated balances for connected wallets after a user action by calling the `updatedBalances` function, which expects a conditional array of addresses. -//or you may decide to get updated balances after a user action using the `updatedBalances` function +``` onboard.state.actions.updateBalances() // update all balances for all connected addresses onboard.state.actions.updateBalances(['0xfdadfadsadsadsadasdsa']) // update balance for one address onboard.state.actions.updateBalances([ From 7661c29df4d3c7b196d197e1c01e51e020d77bdb Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Sun, 5 Jun 2022 00:03:00 -0400 Subject: [PATCH 10/15] Readme update --- packages/demo/src/App.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/demo/src/App.svelte b/packages/demo/src/App.svelte index 4f866b9d7..8b1dcb596 100644 --- a/packages/demo/src/App.svelte +++ b/packages/demo/src/App.svelte @@ -272,6 +272,9 @@ + {/if} {#if $wallets$} @@ -346,9 +349,6 @@ > Disconnect Wallet - {/each} {/if} From 05034a476a16afd2ec3d223a4be2b5f62b2b70cd Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Mon, 6 Jun 2022 13:00:20 -0400 Subject: [PATCH 11/15] cleanup --- packages/core/src/validation.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/core/src/validation.ts b/packages/core/src/validation.ts index 00176316d..5fa2111ac 100644 --- a/packages/core/src/validation.ts +++ b/packages/core/src/validation.ts @@ -13,7 +13,6 @@ import type { const chainId = Joi.string().pattern(/^0x[0-9a-fA-F]+$/) const chainNamespace = Joi.string().valid('evm') const unknownObject = Joi.object().unknown() -// const address = Joi.string().regex(/^0x[a-fA-F0-9]{40}$/) const chain = Joi.object({ namespace: chainNamespace, @@ -101,9 +100,6 @@ const walletInit = Joi.array().items(Joi.function()).required() const locale = Joi.string() -// const addresses = -//Joi.array().items(Joi.string().pattern(/^0x[a-fA-F0-9]{40}$/)) - const accountCenterPosition = Joi.string().valid( 'topRight', 'bottomRight', @@ -218,4 +214,4 @@ export function validateLocale(data: string): ValidateReturn { export function validateUpdateBalances(data: WalletState[]): ValidateReturn { return validate(wallets, data) -} +} \ No newline at end of file From a8cd5dcadb33f0e1183c44936dfabc055f837e8d Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Mon, 6 Jun 2022 18:50:47 -0400 Subject: [PATCH 12/15] package bump --- packages/react/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/package.json b/packages/react/package.json index a6f51f962..1b63774a3 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/react", - "version": "2.1.8-alpha.1", + "version": "2.1.7-alpha.2", "description": "Collection of React Hooks for web3-onboard", "module": "dist/index.js", "browser": "dist/index.js", From f776d34036f287867f6eb3279cecaf24140eaf9f Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Mon, 6 Jun 2022 18:55:51 -0400 Subject: [PATCH 13/15] package bump and merge develop --- packages/react/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react/package.json b/packages/react/package.json index 1b63774a3..9520f6398 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -21,7 +21,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/core": "^2.2.11-alpha.1", + "@web3-onboard/core": "^2.2.10-alpha.1", "@web3-onboard/common": "^2.1.0" }, "peerDependencies": { From ff02a59ea03269d367c83d48b9d869bd45acede2 Mon Sep 17 00:00:00 2001 From: Mahmud Adeleye Date: Mon, 6 Jun 2022 21:18:28 -0400 Subject: [PATCH 14/15] package bump --- packages/react/package.json | 4 ++-- yarn.lock | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/packages/react/package.json b/packages/react/package.json index 9520f6398..7f41ef8e8 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/react", - "version": "2.1.7-alpha.2", + "version": "2.1.8-alpha.2", "description": "Collection of React Hooks for web3-onboard", "module": "dist/index.js", "browser": "dist/index.js", @@ -21,7 +21,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/core": "^2.2.10-alpha.1", + "@web3-onboard/core": "^2.2.11-alpha.1", "@web3-onboard/common": "^2.1.0" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index 67f99341a..cc8d055ce 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2074,6 +2074,31 @@ dependencies: "@walletconnect/window-getters" "^1.0.0" +"@web3-onboard/core@^2.2.10-alpha.1", "@web3-onboard/core@^2.2.9": + version "2.2.10" + resolved "https://registry.yarnpkg.com/@web3-onboard/core/-/core-2.2.10.tgz#61dcc912062548db38d67e228637a27c59122080" + integrity sha512-sQF14OkT+4ibefXPQ7ueZW7DcKbbCzQXZW64FZ+ETEpgKCYjVarqpcMlp5YB4jv49cWWqM8qXRoskaqz01PktQ== + dependencies: + "@web3-onboard/common" "^2.1.0" + bowser "^2.11.0" + ethers "5.5.3" + eventemitter3 "^4.0.7" + joi "17.6.0" + lodash.merge "^4.6.2" + lodash.partition "^4.6.0" + rxjs "^7.5.2" + svelte "^3.46.4" + svelte-i18n "^3.3.13" + +"@web3-onboard/injected-wallets@^2.0.7": + version "2.0.7" + resolved "https://registry.yarnpkg.com/@web3-onboard/injected-wallets/-/injected-wallets-2.0.7.tgz#d0f29adbf96b95b45bffb495fdd0c56821378e3d" + integrity sha512-jP7e6jpM2y/m88AxT40m3Nzc378gEympUXaKU1BESq1DWWJSkjNsaYKdp/2ADTajHUqoPB99jwiAPB0DNs2dLg== + dependencies: + "@web3-onboard/common" "^2.0.7" + joi "^17.4.2" + lodash.uniqby "^4.7.0" + "@webassemblyjs/ast@1.11.1": version "1.11.1" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.11.1.tgz#2bfd767eae1a6996f432ff7e8d7fc75679c0b6a7" From 89769606a4363ee0e11c1fd765e83dba0eab0721 Mon Sep 17 00:00:00 2001 From: Mahmud <104795334+mahmud-bn@users.noreply.github.com> Date: Tue, 7 Jun 2022 09:42:16 -0600 Subject: [PATCH 15/15] core version bump --- packages/core/package.json | 2 +- packages/react/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index ed04ffe73..4de695732 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@web3-onboard/core", - "version": "2.2.11-alpha.1", + "version": "2.2.11-alpha.2", "scripts": { "build": "rollup -c", "dev": "rollup -c -w", diff --git a/packages/react/package.json b/packages/react/package.json index 93a752015..d4368d35e 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -23,7 +23,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@web3-onboard/core": "^2.2.11-alpha.1", + "@web3-onboard/core": "^2.2.11-alpha.2", "@web3-onboard/common": "^2.1.0-alpha.1", "use-sync-external-store": "1.0.0" },