Skip to content

Commit 1d9151c

Browse files
[core-v2.2.9-alpha.3, react-v2.1.7-alpha.4]: A minimal account center feature (#1004)
* Minimized the account center button removing balance, address, and network switch * Remove disconnect all wallets and connect another wallet option on mobile * Remove disconnect all wallets and connect another wallet option on mobile * Version bump * Formatting * Version bump * Added yarn lock to gitignore * Version bump * Yarn lock fix * Delete yarn.lock * Spacing and documentation update * Documentation update * Demo core version package update * fixes * Desktop and Mobile configurations * Refine constant configurations * Refine constant configurations * Remove commented code * Remove empty lines * Packages bump * Documentation update * Cleanup * Conflicts fix * styling fixes * styling fixes * fixes * Change width based on micro state * Remove yarn.lock from demo * Revert yarn.lock changes Co-authored-by: Aaron Barnard <abarnard@protonmail.com>
1 parent 7aee118 commit 1d9151c

File tree

12 files changed

+213
-73
lines changed

12 files changed

+213
-73
lines changed

packages/core/README.md

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,19 @@ To see a list of all of the text values that can be internationalized or replace
9292
Onboard is using the [ICU syntax](https://formatjs.io/docs/core-concepts/icu-syntax/) for formatting under the hood.
9393
9494
**`accountCenter`**
95-
An object that defines whether the account center UI is enabled and it's position on the screen. Currently the account center is disabled for mobile devices, so only desktop options are available.
95+
An object that defines whether the account center UI (default and minimal) is enabled and it's position on the screen. Currently the account center is enabled for both desktop and mobile devices.
9696
9797
```typescript
98-
type AccountCenterOptions = {
99-
desktop: {
100-
position?: AccountCenterPosition // default: 'topRight'
101-
enabled?: AccountCenter['enabled'] // default: true
102-
}
98+
export type AccountCenter = {
99+
enabled: boolean
100+
position?: AccountCenterPosition // default: 'topRight'
101+
expanded?: boolean // default: true
102+
minimal?: boolean // enabled by default for mobile
103103
}
104104

105-
type AccountCenter = {
106-
enabled: boolean
107-
position: AccountCenterPosition
108-
expanded: boolean
105+
export type AccountCenterOptions = {
106+
desktop: Omit<AccountCenter, 'expanded'>
107+
mobile: Omit<AccountCenter, 'expanded'>
109108
}
110109

111110
type AccountCenterPosition =
@@ -175,6 +174,18 @@ const onboard = Onboard({
175174
{ name: 'Coinbase', url: 'https://wallet.coinbase.com/' }
176175
]
177176
},
177+
accountCenter: {
178+
desktop: {
179+
position: 'topRight',
180+
enabled: true,
181+
minimal: true
182+
},
183+
mobile: {
184+
position: 'topRight',
185+
enabled: true,
186+
minimal: true
187+
}
188+
},
178189
i18n: {
179190
en: {
180191
connect: {
@@ -316,6 +327,7 @@ type AccountCenter = {
316327
enabled: boolean
317328
position: AccountCenterPosition
318329
expanded: boolean
330+
minimal: boolean
319331
}
320332

321333
type AccountCenterPosition =
@@ -516,8 +528,10 @@ The Onboard styles can customized via [CSS variables](https://developer.mozilla.
516528
--onboard-spacing-4: 1rem;
517529
--onboard-spacing-5: 0.5rem;
518530

519-
/* SHADOWS */
531+
/* BORDER RADIUS */
520532
--onboard-border-radius-1: 24px;
533+
--onboard-border-radius-2: 20px;
534+
--onboard-border-radius-3: 16px;
521535

522536
/* SHADOWS */
523537
--onboard-shadow-0: none;

packages/core/src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AppState } from './types'
2+
import { getDevice } from './utils'
23

34
export const APP_INITIAL_STATE: AppState = {
45
wallets: [],
@@ -7,7 +8,8 @@ export const APP_INITIAL_STATE: AppState = {
78
accountCenter: {
89
enabled: true,
910
position: 'topRight',
10-
expanded: false
11+
expanded: false,
12+
minimal: getDevice().type === 'mobile'
1113
},
1214
locale: ''
1315
}

packages/core/src/index.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import initI18N from './i18n'
1515

1616
import App from './views/Index.svelte'
1717
import type { InitOptions, OnboardAPI } from './types'
18+
import { APP_INITIAL_STATE } from './constants'
1819
import { getDevice } from './utils'
1920

2021
const API = {
@@ -58,19 +59,26 @@ function init(options: InitOptions): OnboardAPI {
5859
initI18N(i18n)
5960
addChains(chains)
6061

61-
let accountCenterUpdate
62-
6362
const device = getDevice()
64-
65-
if (device.type === 'mobile') {
66-
accountCenterUpdate = {
67-
enabled: false
63+
64+
// update accountCenter
65+
if (typeof accountCenter !== 'undefined') {
66+
let accountCenterUpdate
67+
68+
if (device.type === 'mobile' && accountCenter.mobile) {
69+
accountCenterUpdate = {
70+
...APP_INITIAL_STATE.accountCenter,
71+
...accountCenter.mobile
72+
}
73+
} else if (accountCenter.desktop) {
74+
accountCenterUpdate = {
75+
...APP_INITIAL_STATE.accountCenter,
76+
...accountCenter.desktop
77+
}
6878
}
69-
} else if (typeof accountCenter !== 'undefined' && accountCenter.desktop) {
70-
accountCenterUpdate = accountCenter.desktop
71-
}
7279

73-
accountCenterUpdate && updateAccountCenter(accountCenterUpdate)
80+
updateAccountCenter(accountCenterUpdate)
81+
}
7482

7583
const { svelteInstance } = internalState$.getValue()
7684

@@ -187,7 +195,10 @@ function mountApp() {
187195
--spacing-7: 0.125rem;
188196
189197
/* BORDER RADIUS */
190-
--border-radius-1: 24px;
198+
--border-radius-1: 24px;
199+
--border-radius-2: 20px;
200+
--border-radius-3: 16px;
201+
191202
192203
/* SHADOWS */
193204
--shadow-0: none;

packages/core/src/types.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,16 @@ export type AccountCenterPosition =
113113
| 'bottomLeft'
114114
| 'topLeft'
115115

116-
export type AccountCenterOptions = {
117-
desktop?: {
116+
export type AccountCenter = {
117+
enabled: boolean
118118
position?: AccountCenterPosition
119-
enabled?: AccountCenter['enabled']
120-
}
119+
expanded?: boolean
120+
minimal?: boolean
121121
}
122-
123-
export type AccountCenter = {
124-
enabled: boolean
125-
position: AccountCenterPosition
126-
expanded: boolean
122+
123+
export type AccountCenterOptions = {
124+
desktop: Omit<AccountCenter, 'expanded'>
125+
mobile: Omit<AccountCenter, 'expanded'>
127126
}
128127

129128
// ==== ACTIONS ==== //

packages/core/src/validation.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ const initOptions = Joi.object({
114114
accountCenter: Joi.object({
115115
desktop: Joi.object({
116116
enabled: Joi.boolean(),
117+
minimal: Joi.boolean(),
117118
position: accountCenterPosition
118119
}),
119120
mobile: Joi.object({
120121
enabled: Joi.boolean(),
121-
position: accountCenterPosition
122+
minimal: Joi.boolean(),
123+
position: accountCenterPosition,
122124
})
123125
})
124126
})
@@ -146,7 +148,8 @@ const setChainOptions = Joi.object({
146148
const accountCenter = Joi.object({
147149
enabled: Joi.boolean(),
148150
position: accountCenterPosition,
149-
expanded: Joi.boolean()
151+
expanded: Joi.boolean(),
152+
minimal: Joi.boolean()
150153
})
151154

152155
type ValidateReturn = Joi.ValidationResult | null

packages/core/src/views/account-center/Index.svelte

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type { AccountCenter } from '../../types'
66
import Maximized from './Maximized.svelte'
77
import Minimized from './Minimized.svelte'
8+
import Micro from './Micro.svelte'
89
910
export let settings: AccountCenter
1011
@@ -28,21 +29,31 @@
2829
<style>
2930
.container {
3031
padding: 16px;
31-
max-width: 364px;
32-
min-width: 348px;
3332
font-family: var(--onboard-font-family-normal, var(--font-family-normal));
33+
width: 100%;
34+
}
35+
36+
@media all and (min-width: 428px) {
37+
.container {
38+
max-width: 352px;
39+
}
3440
}
3541
</style>
3642

3743
<svelte:window on:click={minimize} />
3844

3945
<div
4046
class="container flex flex-column absolute"
41-
style={accountCenterPositions[settings.position]}
47+
style="{accountCenterPositions[
48+
settings.position
49+
]} width: {!settings.expanded && settings.minimal ? 'auto' : '100%'}"
4250
>
43-
{#if !settings.expanded}
51+
{#if !settings.expanded && !settings.minimal}
4452
<!-- minimized -->
4553
<Minimized />
54+
{:else if !settings.expanded && settings.minimal}
55+
<!-- micro -->
56+
<Micro />
4657
{:else}
4758
<!-- maximized -->
4859
<Maximized />

packages/core/src/views/account-center/Maximized.svelte

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import { updateAccountCenter } from '../../store/actions'
2121
import blocknative from '../../icons/blocknative'
2222
import DisconnectAllConfirm from './DisconnectAllConfirm.svelte'
23+
import { getDevice } from '../../utils'
2324
2425
function disconnectAllWallets() {
2526
$wallets$.forEach(({ label }) => disconnect({ label }))
@@ -44,12 +45,13 @@
4445
)
4546
4647
const { position } = state.get().accountCenter
48+
const device = getDevice()
4749
</script>
4850

4951
<style>
5052
.outer-container {
5153
background-color: var(--onboard-gray-600, var(--gray-600));
52-
border-radius: 16px;
54+
border-radius: var(--onboard-border-radius-3, var(--border-radius-3));
5355
width: 100%;
5456
filter: drop-shadow(0px 4px 16px rgba(178, 178, 178, 0.2));
5557
}
@@ -228,38 +230,40 @@
228230
/>
229231
{/each}
230232
</div>
231-
232233
<!-- actions -->
233234
<div class="actions flex flex-column items-start">
234-
<!-- connect another wallet -->
235-
<div
236-
on:click={() => connect()}
237-
class="action-container flex items-center pointer"
238-
>
239-
<div class="plus-icon flex items-center justify-center">
240-
{@html plusCircleIcon}
241-
</div>
242-
<span class="action-text"
243-
>{$_('accountCenter.connectAnotherWallet', {
244-
default: en.accountCenter.connectAnotherWallet
245-
})}</span
235+
<!-- Hide for Mobile -->
236+
{#if device.type === 'desktop'}
237+
<!-- connect another wallet -->
238+
<div
239+
on:click={() => connect()}
240+
class="action-container flex items-center pointer"
246241
>
247-
</div>
248-
249-
<!-- disconnect all wallets -->
250-
<div
251-
on:click={() => (disconnectConfirmModal = true)}
252-
class="action-container flex items-center mt pointer"
253-
>
254-
<div class="arrow-forward flex items-center justify-center">
255-
{@html arrowForwardIcon}
242+
<div class="plus-icon flex items-center justify-center">
243+
{@html plusCircleIcon}
244+
</div>
245+
<span class="action-text"
246+
>{$_('accountCenter.connectAnotherWallet', {
247+
default: en.accountCenter.connectAnotherWallet
248+
})}</span
249+
>
256250
</div>
257-
<span class="action-text"
258-
>{$_('accountCenter.disconnectAllWallets', {
259-
default: en.accountCenter.disconnectAllWallets
260-
})}</span
251+
252+
<!-- disconnect all wallets -->
253+
<div
254+
on:click={() => (disconnectConfirmModal = true)}
255+
class="action-container flex items-center mt pointer"
261256
>
262-
</div>
257+
<div class="arrow-forward flex items-center justify-center">
258+
{@html arrowForwardIcon}
259+
</div>
260+
<span class="action-text"
261+
>{$_('accountCenter.disconnectAllWallets', {
262+
default: en.accountCenter.disconnectAllWallets
263+
})}</span
264+
>
265+
</div>
266+
{/if}
263267
</div>
264268
</div>
265269

@@ -414,7 +418,6 @@
414418
default: en.accountCenter.backToApp
415419
})}</button
416420
>
417-
418421
<a
419422
href="https://blocknative.com"
420423
target="_blank"

0 commit comments

Comments
 (0)