Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
20 changes: 19 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ aliases:
echo "$FILE exist"
circleci step halt
fi

- &generate-lock-file
run:
name: Generate lock file
Expand Down Expand Up @@ -267,6 +267,12 @@ jobs:
working_directory: ~/web3-onboard-monorepo/packages/coinbase
steps:
- node-build-steps
build-dcent:
docker:
- image: cimg/node:16.13.1
working_directory: ~/web3-onboard-monorepo/packages/dcent
steps:
- node-build-steps
build-vue:
docker:
- image: cimg/node:16.13.1
Expand Down Expand Up @@ -377,6 +383,12 @@ jobs:
working_directory: ~/web3-onboard-monorepo/packages/coinbase
steps:
- node-staging-build-steps
build-staging-dcent:
docker:
- image: cimg/node:16.13.1
working_directory: ~/web3-onboard-monorepo/packages/dcent
steps:
- node-staging-build-steps
build-staging-vue:
docker:
- image: cimg/node:16.13.1
Expand Down Expand Up @@ -489,6 +501,12 @@ workflows:
<<: *deploy_production_filters
- build-staging-coinbase:
<<: *deploy_staging_filters
dcent:
jobs:
- build-dcent:
<<: *deploy_production_filters
- build-staging-dcent:
<<: *deploy_staging_filters
vue:
jobs:
- build-vue:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ For full documentation, check out the README.md for each package:
- [Ledger](packages/ledger/README.md)
- [Trezor](packages/trezor/README.md)
- [Keystone](packages/keystone/README.md)

- [D'CENT](packages/dcent/README.md)
**Frameworks**

- [React](packages/react/README.md)
Expand Down
1 change: 1 addition & 0 deletions packages/@types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare module '*.png'
declare module 'window'
declare module '@keystonehq/eth-keyring'
declare module 'eth-dcent-keyring'
declare module 'hdkey'
declare const global: typeof globalThis & { window: CustomWindow }
12 changes: 12 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ const onboard = Onboard({
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.

```
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

When initializing Onboard you define a list of chains/networks that your app supports. If you would like to prompt the user to switch to one of those chains, you can use the `setChain` method on an initialized instance of Onboard:
Expand Down
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.2.10",
"version": "2.2.11",
"scripts": {
"build": "rollup -c",
"dev": "rollup -c -w",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import App from './views/Index.svelte'
import type { InitOptions, OnboardAPI } from './types'
import { APP_INITIAL_STATE } from './constants'
import { internalState } from './internals'
import updateBalances from './updateBalances'

const API = {
connectWallet,
Expand All @@ -27,7 +28,8 @@ const API = {
select: state.select,
actions: {
setWalletModules,
setLocale
setLocale,
updateBalances
}
}
}
Expand Down Expand Up @@ -224,4 +226,4 @@ function mountApp() {
return app
}

export default init
export default init
24 changes: 21 additions & 3 deletions packages/core/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import type {
UpdateAccountAction,
UpdateAccountCenterAction,
UpdateWalletAction,
WalletState
WalletState,
UpdateAllWalletsAction
} from '../types'

import {
validateAccountCenterUpdate,
validateLocale,
validateString,
validateWallet,
validateWalletInit
validateWalletInit,
validateUpdateBalances
} from '../validation'

import {
Expand All @@ -33,7 +35,8 @@ import {
UPDATE_ACCOUNT,
UPDATE_ACCOUNT_CENTER,
SET_WALLET_MODULES,
SET_LOCALE
SET_LOCALE,
UPDATE_ALL_WALLETS
} from './constants'
import { internalState } from '../internals'

Expand Down Expand Up @@ -177,6 +180,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
}

dispatch(action as UpdateAllWalletsAction)
}

// ==== HELPERS ==== //
export function initializeWalletModules(modules: WalletInit[]): WalletModule[] {
const { device } = internalState
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/store/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_ALL_WALLETS = 'update_balance'
17 changes: 14 additions & 3 deletions packages/core/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import type {
AddWalletAction,
UpdateAccountAction,
UpdateAccountCenterAction,
Locale
Locale,
UpdateAllWalletsAction
} from '../types'

import {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -112,6 +122,7 @@ function reducer(state: AppState, action: Action): AppState {
}
}
}

case SET_WALLET_MODULES: {
return {
...state,
Expand Down Expand Up @@ -175,4 +186,4 @@ function get(): AppState {
export const state = {
select,
get
}
}
6 changes: 6 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export type Action =
| UpdateAccountCenterAction
| SetWalletModulesAction
| SetLocaleAction
| UpdateAllWalletsAction

export type AddChainsAction = { type: 'add_chains'; payload: Chain[] }
export type AddWalletAction = { type: 'add_wallet'; payload: WalletState }
Expand Down Expand Up @@ -175,6 +176,11 @@ export type SetLocaleAction = {
payload: string
}

export type UpdateAllWalletsAction = {
type: 'update_balance'
payload: WalletState[]
}

// ==== MISC ==== //
export type ChainStyle = {
icon: string
Expand Down
33 changes: 33 additions & 0 deletions packages/core/src/updateBalances.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { state } from './store'
import { getBalance } from './provider'
import { updateAllWallets } from './store/actions'

async function updateBalances(addresses?: string[]): Promise<void> {
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 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)

return { ...account, balance: updatedBalance }
}

return account
})
)
return { ...wallet, accounts: updatedAccounts }
})
)

updateAllWallets(updatedWallets)
}

export default updateBalances
8 changes: 7 additions & 1 deletion packages/core/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +64,8 @@ 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()
Expand Down Expand Up @@ -209,3 +210,8 @@ export function validateWalletInit(data: WalletInit[]): ValidateReturn {
export function validateLocale(data: string): ValidateReturn {
return validate(locale, data)
}

export function validateUpdateBalances(data:
WalletState[]): ValidateReturn {
return validate(wallets, data)
}
4 changes: 2 additions & 2 deletions packages/core/src/views/account-center/Maximized.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

.wallets-section {
width: 100%;
border-radius: 16px;
border-radius: var(--onboard-border-radius-3, var(--border-radius-3));
}

.p5 {
Expand Down Expand Up @@ -117,7 +117,7 @@

.network-container {
margin: 0 1px 1px 1px;
border-radius: 15px;
border-radius: var(--onboard-border-radius-3, var(--border-radius-3));
color: var(--onboard-gray-500, var(--gray-500));
}

Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/views/connect/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@
connectionRejected = true
if (autoSelect) {
walletToAutoSelect = null

if (autoSelect.disableModals) {
connectWallet$.next({ inProgress: false })
}
}
return
}
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/views/connect/WalletButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
}

button.wallet-button-styling {
border-radius: var(--onboard-wallet-button-border-radius, var(--border-radius-1));
border-radius: var(
--onboard-wallet-button-border-radius,
var(--border-radius-1)
);
box-shadow: var(--onboard-wallet-button-box-shadow, var(--box-shadow-0));
}
</style>
Expand Down
27 changes: 27 additions & 0 deletions packages/dcent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# @web3-onboard/dcent

## Wallet module for connecting D'CENT hardware wallets to web3-onboard

### Install

`npm i @web3-onboard/dcent`

### Usage

```typescript
import Onboard from '@web3-onboard/core'
import dcentModule from '@web3-onboard/dcent'

const dcent = dcentModule()

const onboard = Onboard({
// ... other Onboard options
wallets: [
dcent
//... other wallets
]
})

const connectedWallets = await onboard.connectWallet()
console.log(connectedWallets)
```
Loading