Skip to content
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.1-alpha.1",
"version": "2.5.0-alpha.1",
"description": "Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized 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.",
"keywords": [
"Ethereum",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ export let configuration: Configuration = {
svelteInstance: null,
appMetadata: null,
apiKey: null,
device: getDevice()
device: getDevice(),
initialWalletInit: []
}

export function updateConfiguration(update: Partial<Configuration>): void {
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/connect.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { firstValueFrom } from 'rxjs'
import { filter, withLatestFrom, pluck } from 'rxjs/operators'
import { configuration } from './configuration'
import { state } from './store'
import { setWalletModules } from './store/actions'
import { connectWallet$, wallets$ } from './streams'
import type { ConnectOptions, ConnectOptionsString, WalletState } from './types'
import { wait } from './utils'
import { validateConnectOptions } from './validation'

async function connect(
Expand All @@ -28,6 +31,16 @@ async function connect(
autoSelect: { label: '', disableModals: false }
}

// if auto selecting, wait until next event loop
if (autoSelect && (typeof autoSelect === 'string' || autoSelect.label)) {
await wait(50)
}

// first time calling connect, so initialize and set wallet modules
if (!state.get().walletModules.length) {
setWalletModules(configuration.initialWalletInit)
}

connectWallet$.next({
autoSelect:
typeof autoSelect === 'string'
Expand Down
17 changes: 9 additions & 8 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { configuration, updateConfiguration } from './configuration'

import {
addChains,
setWalletModules,
updateAccountCenter,
updateNotify,
customNotification,
setLocale,
setPrimaryWallet
setPrimaryWallet,
setWalletModules
} from './store/actions'

import updateBalances from './update-balances'
Expand Down Expand Up @@ -168,7 +168,6 @@ function init(options: InitOptions): OnboardAPI {
if (!apiKey || !notifyUpdate.enabled) {
notifyUpdate.enabled = false
}
console.log(notifyUpdate)
updateNotify(notifyUpdate)
}
} else {
Expand All @@ -191,11 +190,10 @@ function init(options: InitOptions): OnboardAPI {
updateConfiguration({
appMetadata,
svelteInstance: app,
apiKey
apiKey,
initialWalletInit: wallets
})

setWalletModules(wallets)

return API
}

Expand Down Expand Up @@ -317,10 +315,13 @@ function mountApp() {
</style>
`

const containerElementQuery = state.get().accountCenter.containerElement || 'body'
const containerElementQuery =
state.get().accountCenter.containerElement || 'body'
const containerElement = document.querySelector(containerElementQuery)
if (!containerElement) {
throw new Error(`Element with query ${state.get().accountCenter} does not exist.`)
throw new Error(
`Element with query ${state.get().accountCenter} does not exist.`
)
}

containerElement.appendChild(onboard)
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export function removeWallet(id: string): void {
}

export function setPrimaryWallet(wallet: WalletState, address?: string): void {
console.log({ address })
const error =
validateWallet(wallet) || (address && validateString(address, 'address'))

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export type Configuration = {
appMetadata: AppMetadata | null
device: Device | DeviceNotBrowser
apiKey: string
initialWalletInit: WalletInit[]
}

export type Locale = string
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ export function shortenEns(ens: string): string {

export async function copyWalletAddress(text: string): Promise<void> {
try {
const copy = await navigator.clipboard.writeText(text);
return copy
const copy = await navigator.clipboard.writeText(text)
return copy
} catch (err) {
console.error('Failed to copy: ', err)
}
Expand Down Expand Up @@ -242,3 +242,6 @@ export const defaultNotifyEventStyles: Record<string, NotifyEventStyles> = {
eventIcon: info
}
}

export const wait = (time: number) =>
new Promise(resolve => setTimeout(resolve, time))