Skip to content

Commit f3814d7

Browse files
committed
cleanup notify disabled logic
1 parent e869041 commit f3814d7

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

packages/core/src/index.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import disconnectWallet from './disconnect'
44
import setChain from './chain'
55
import { state } from './store'
66
import { reset$ } from './streams'
7-
import { validateInitOptions, validateNotify, validateNotifyOptions } from './validation'
7+
import {
8+
validateInitOptions,
9+
validateNotify,
10+
validateNotifyOptions
11+
} from './validation'
812
import initI18N from './i18n'
913
import App from './views/Index.svelte'
1014
import type { InitOptions, OnboardAPI, Notify } from './types'
@@ -106,11 +110,11 @@ function init(options: InitOptions): OnboardAPI {
106110
if (typeof notify !== 'undefined') {
107111
if ('desktop' in notify || 'mobile' in notify) {
108112
const error = validateNotifyOptions(notify)
109-
113+
110114
if (error) {
111115
throw error
112116
}
113-
117+
114118
if (
115119
(!notify.desktop || (notify.desktop && !notify.desktop.position)) &&
116120
accountCenter &&
@@ -128,6 +132,7 @@ function init(options: InitOptions): OnboardAPI {
128132
notify.mobile.position = accountCenter.mobile.position
129133
}
130134
let notifyUpdate: Partial<Notify>
135+
131136
if (device.type === 'mobile' && notify.mobile) {
132137
notifyUpdate = {
133138
...APP_INITIAL_STATE.notify,
@@ -139,15 +144,34 @@ function init(options: InitOptions): OnboardAPI {
139144
...notify.desktop
140145
}
141146
}
147+
if (!apiKey || !notifyUpdate.enabled) {
148+
notifyUpdate.enabled = false
149+
}
142150
updateNotify(notifyUpdate)
143151
} else {
144152
const error = validateNotify(notify as Notify)
145-
153+
146154
if (error) {
147155
throw error
148156
}
149-
updateNotify(notify as Notify)
157+
const notifyUpdate: Partial<Notify> = {
158+
...APP_INITIAL_STATE.notify,
159+
...notify
160+
}
161+
162+
if (!apiKey || !notifyUpdate.enabled) {
163+
notifyUpdate.enabled = false
164+
}
165+
console.log(notifyUpdate)
166+
updateNotify(notifyUpdate)
167+
}
168+
} else {
169+
const notifyUpdate: Partial<Notify> = APP_INITIAL_STATE.notify
170+
171+
if (!apiKey) {
172+
notifyUpdate.enabled = false
150173
}
174+
updateNotify(notifyUpdate)
151175
}
152176

153177
if (svelteInstance) {

packages/core/src/views/Index.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import AccountCenter from './account-center/Index.svelte'
99
import Notify from './notify/Index.svelte'
1010
import { configuration } from '../configuration'
11+
import type { Observable } from 'rxjs';
12+
import type { Notification } from '../types'
13+
1114
1215
const { device } = configuration
1316
const accountCenter$ = state
@@ -18,9 +21,7 @@
1821
.select('notify')
1922
.pipe(startWith(state.get().notify), shareReplay(1))
2023
21-
const notifications$ = $notify$.enabled
22-
? state.select('notifications').pipe(startWith(state.get().notifications))
23-
: null
24+
const notifications$: Observable<Notification[]> = state.select('notifications').pipe(startWith(state.get().notifications))
2425
2526
const positioningDefaults = {
2627
topLeft: 'top: 0; left: 0;',

0 commit comments

Comments
 (0)