Skip to content

Commit e27f53c

Browse files
[core-v2.7.0-alpha.1, react-v2.2.6-alpha.1, vue-v2.1.6-alpha.1] : Feature - Add configuration to hide/show sidebar (#1191)
* Add configuration to hide/show sidebar * Remove unused import * Bump versions * Remove redundant check * Update packages/core/src/types.ts Co-authored-by: Aaron <abarnard@protonmail.com> * Clean up validation * Add documentation Co-authored-by: Aaron <abarnard@protonmail.com>
1 parent 8571ab0 commit e27f53c

File tree

13 files changed

+99
-17
lines changed

13 files changed

+99
-17
lines changed

packages/core/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type InitOptions {
2828
wallets: WalletInit[]
2929
chains: Chain[]
3030
appMetadata?: AppMetadata
31+
connect?: ConnectModalOptions
3132
i18n?: i18nOptions
3233
accountCenter?: AccountCenterOptions
3334
apiKey?: string
@@ -85,6 +86,15 @@ type RecommendedInjectedWallets = {
8586
}
8687
```
8788
89+
**`connect`**
90+
An object that allows for customization of the Connect Modal and accepts the type ConnectModalOptions.
91+
92+
```typescript
93+
type ConnectModalOptions = {
94+
showSidebar?: boolean
95+
}
96+
```
97+
8898
**`i18n`**
8999
An object that defines the display text for different locales. Can also be used to override the default text. To override the default text, pass in a object for the `en` locale.
90100

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@web3-onboard/core",
3-
"version": "2.6.0",
3+
"version": "2.7.0-alpha.1",
44
"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.",
55
"keywords": [
66
"Ethereum",

packages/core/src/constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export const APP_INITIAL_STATE: AppState = {
1818
position: 'topRight'
1919
},
2020
notifications: [],
21-
locale: ''
21+
locale: '',
22+
connect : {
23+
showSidebar: true
24+
}
2225
}
2326

2427
export const STORAGE_KEYS = {

packages/core/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {
2626
customNotification,
2727
setLocale,
2828
setPrimaryWallet,
29-
setWalletModules
29+
setWalletModules,
30+
updateConnectModal
3031
} from './store/actions'
3132

3233
const API = {
@@ -87,13 +88,18 @@ function init(options: InitOptions): OnboardAPI {
8788
accountCenter,
8889
apiKey,
8990
notify,
90-
gas
91+
gas,
92+
connect
9193
} = options
9294

9395
initI18N(i18n)
9496
addChains(chainIdToHex(chains))
9597
const { device, svelteInstance } = configuration
9698

99+
if (typeof connect !== undefined) {
100+
updateConnectModal(connect)
101+
}
102+
97103
// update accountCenter
98104
if (typeof accountCenter !== 'undefined') {
99105
let accountCenterUpdate

packages/core/src/store/actions.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import type {
2424
CustomNotification,
2525
UpdateNotification,
2626
CustomNotificationUpdate,
27-
Notify
27+
Notify,
28+
ConnectModalOptions,
29+
UpdateConnectModalAction
2830
} from '../types'
2931

3032
import {
@@ -37,7 +39,8 @@ import {
3739
validateWallet,
3840
validateWalletInit,
3941
validateUpdateBalances,
40-
validateNotify
42+
validateNotify,
43+
validateConnectModalUpdate
4144
} from '../validation'
4245

4346
import {
@@ -53,7 +56,8 @@ import {
5356
SET_LOCALE,
5457
ADD_NOTIFICATION,
5558
REMOVE_NOTIFICATION,
56-
UPDATE_ALL_WALLETS
59+
UPDATE_ALL_WALLETS,
60+
UPDATE_CONNECT_MODAL
5761
} from './constants'
5862

5963
export function addChains(chains: Chain[]): void {
@@ -180,6 +184,23 @@ export function updateAccountCenter(
180184
dispatch(action as UpdateAccountCenterAction)
181185
}
182186

187+
export function updateConnectModal(
188+
update: ConnectModalOptions | Partial<ConnectModalOptions>
189+
): void {
190+
const error = validateConnectModalUpdate(update)
191+
192+
if (error) {
193+
throw error
194+
}
195+
196+
const action = {
197+
type: UPDATE_CONNECT_MODAL,
198+
payload: update
199+
}
200+
201+
dispatch(action as UpdateConnectModalAction)
202+
}
203+
183204
export function updateNotify(update: Partial<Notify>): void {
184205
const error = validateNotify(update)
185206

packages/core/src/store/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const UPDATE_WALLET = 'update_wallet'
55
export const REMOVE_WALLET = 'remove_wallet'
66
export const UPDATE_ACCOUNT = 'update_account'
77
export const UPDATE_ACCOUNT_CENTER = 'update_account_center'
8+
export const UPDATE_CONNECT_MODAL = 'update_connect_modal'
89
export const SET_WALLET_MODULES = 'set_wallet_modules'
910
export const SET_LOCALE = 'set_locale'
1011
export const UPDATE_NOTIFY = 'update_notify'

packages/core/src/store/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import type {
1717
UpdateNotifyAction,
1818
AddNotificationAction,
1919
RemoveNotificationAction,
20-
UpdateAllWalletsAction
20+
UpdateAllWalletsAction,
21+
UpdateConnectModalAction
2122
} from '../types'
2223

2324
import {
@@ -27,6 +28,7 @@ import {
2728
REMOVE_WALLET,
2829
RESET_STORE,
2930
UPDATE_ACCOUNT,
31+
UPDATE_CONNECT_MODAL,
3032
UPDATE_ACCOUNT_CENTER,
3133
UPDATE_NOTIFY,
3234
SET_WALLET_MODULES,
@@ -118,6 +120,18 @@ function reducer(state: AppState, action: Action): AppState {
118120
}
119121
}
120122

123+
case UPDATE_CONNECT_MODAL: {
124+
const update = payload as UpdateConnectModalAction['payload']
125+
126+
return {
127+
...state,
128+
connect: {
129+
...state.connect,
130+
...update
131+
}
132+
}
133+
}
134+
121135
case UPDATE_ACCOUNT_CENTER: {
122136
const update = payload as UpdateAccountCenterAction['payload']
123137

packages/core/src/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export interface InitOptions {
3333
* Define custom copy for the 'en' locale or add locales to i18n your app
3434
*/
3535
i18n?: i18nOptions
36+
/**
37+
* Customize the connect modal
38+
*/
39+
connect?: ConnectModalOptions
3640
/**
3741
* Customize the account center UI
3842
*/
@@ -117,6 +121,7 @@ export interface AppState {
117121
locale: Locale
118122
notify: Notify
119123
notifications: Notification[]
124+
connect: ConnectModalOptions
120125
}
121126

122127
export type Configuration = {
@@ -132,6 +137,10 @@ export type Locale = string
132137
export type i18nOptions = Record<Locale, i18n>
133138
export type i18n = typeof en
134139

140+
export type ConnectModalOptions = {
141+
showSidebar?: boolean
142+
}
143+
135144
export type CommonPositions =
136145
| 'topRight'
137146
| 'bottomRight'
@@ -245,6 +254,7 @@ export type Action =
245254
| AddNotificationAction
246255
| RemoveNotificationAction
247256
| UpdateAllWalletsAction
257+
| UpdateConnectModalAction
248258

249259
export type AddChainsAction = { type: 'add_chains'; payload: Chain[] }
250260
export type AddWalletAction = { type: 'add_wallet'; payload: WalletState }
@@ -274,6 +284,11 @@ export type UpdateAccountCenterAction = {
274284
payload: AccountCenter | Partial<AccountCenter>
275285
}
276286

287+
export type UpdateConnectModalAction = {
288+
type: 'update_connect_modal'
289+
payload: Partial<ConnectModalOptions>
290+
}
291+
277292
export type SetWalletModulesAction = {
278293
type: 'set_wallet_modules'
279294
payload: WalletModule[]

packages/core/src/validation.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import type {
2020
CustomNotification,
2121
CustomNotificationUpdate,
2222
Notify,
23-
PreflightNotificationsOptions
23+
PreflightNotificationsOptions,
24+
ConnectModalOptions
2425
} from './types'
2526

2627
// const chainId = Joi.string().pattern(/^0x[0-9a-fA-F]+$/)
@@ -170,6 +171,10 @@ const accountCenter = Joi.object({
170171
containerElement: Joi.string()
171172
})
172173

174+
const connectModalOptions = Joi.object({
175+
showSidebar: Joi.boolean()
176+
})
177+
173178
const initOptions = Joi.object({
174179
wallets: walletInit,
175180
chains: chains.required(),
@@ -184,7 +189,8 @@ const initOptions = Joi.object({
184189
gas: Joi.object({
185190
get: Joi.function().required(),
186191
stream: Joi.function().required()
187-
})
192+
}),
193+
connect: connectModalOptions
188194
})
189195

190196
const connectOptions = Joi.object({
@@ -318,6 +324,12 @@ export function validateAccountCenterUpdate(
318324
return validate(accountCenter, data)
319325
}
320326

327+
export function validateConnectModalUpdate(
328+
data: ConnectModalOptions | Partial<ConnectModalOptions>
329+
): ValidateReturn {
330+
return validate(connectModalOptions, data)
331+
}
332+
321333
export function validateWalletInit(data: WalletInit[]): ValidateReturn {
322334
return validate(walletInit, data)
323335
}

packages/core/src/views/connect/Index.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
export let autoSelect: ConnectOptions['autoSelect']
3939
4040
const { appMetadata } = configuration
41-
const { walletModules } = state.get()
41+
const { walletModules, connect } = state.get()
4242
4343
let connectionRejected = false
4444
let wallets: WalletWithLoadingIcon[] = []
@@ -365,7 +365,7 @@
365365
{#if !autoSelect.disableModals}
366366
<Modal {close}>
367367
<div class="container relative flex">
368-
{#if windowWidth >= 809}
368+
{#if windowWidth >= 809 && connect.showSidebar}
369369
<Sidebar step={$modalStep$} />
370370
{/if}
371371

0 commit comments

Comments
 (0)