Skip to content

Commit

Permalink
refactor: move session change outside of cb wiring
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed May 7, 2024
1 parent 410fb91 commit 18e322b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
31 changes: 20 additions & 11 deletions packages/dapp-toolkit/src/connect-button/connect-button-client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
delay,
filter,
first,
fromEvent,
Expand Down Expand Up @@ -95,17 +96,6 @@ export const ConnectButtonClient = (input: {

connectButtonElement.enableMobile = enableMobile

if (transport?.sessionChange$)
subscriptions.add(
transport.sessionChange$.subscribe(() => {
setTimeout(() => {
connectButtonElement.showPopoverMenu = true
connectButtonElement.showLinking = true
connectButtonElement.pristine = false
}, 1000)
}),
)

const onConnect$ = fromEvent(connectButtonElement, 'onConnect').pipe(
tap(() => {
onConnect((value) => subjects.onConnect.next(value))
Expand Down Expand Up @@ -216,6 +206,15 @@ export const ConnectButtonClient = (input: {
tap((value) => (connectButtonElement.theme = value)),
)

const showLinking$ = subjects.showLinking.pipe(
delay(1000),
tap((value) => {
connectButtonElement.showPopoverMenu = value
connectButtonElement.showLinking = value
connectButtonElement.pristine = false
}),
)

return merge(
onConnect$,
status$,
Expand All @@ -238,6 +237,7 @@ export const ConnectButtonClient = (input: {
onShowPopover$,
dAppName$,
onLinkClick$,
showLinking$,
)
}),
)
Expand Down Expand Up @@ -277,6 +277,15 @@ export const ConnectButtonClient = (input: {
.subscribe(),
)

if (transport?.sessionChange$)
subscriptions.add(
transport.sessionChange$
.pipe(filter((session) => session.status === 'Active'))
.subscribe(() => {
subjects.showLinking.next(true)
}),
)

const connectButtonApi = {
status$: subjects.status.asObservable(),
onConnect$: subjects.onConnect.asObservable(),
Expand Down
1 change: 1 addition & 0 deletions packages/dapp-toolkit/src/connect-button/subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export const ConnectButtonSubjects = () => ({
type: 'account' | 'transaction' | 'setupGuide' | 'showQrCode'
data: string
}>(),
showLinking: new BehaviorSubject<boolean>(false),
})

0 comments on commit 18e322b

Please sign in to comment.