Skip to content

Commit

Permalink
fix: allow late render for connect button
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Jun 20, 2024
1 parent f34c1eb commit edcceb4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions examples/simple-dapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const content = document.getElementById('app')!
content.innerHTML = `
<button id="reset">Reset</button>
<button id="sendTx">Send Tx</button>
<button id="removeCb">Remove Connect Button</button>
<button id="addCb">Add Connect Button</button>
<div class="mt-25"><button id="one-time-request">Send one time request</button></div>
Expand All @@ -40,6 +42,8 @@ content.innerHTML = `
const resetButton = document.getElementById('reset')!
const sendTxButton = document.getElementById('sendTx')!
const sessions = document.getElementById('sessions')!
const removeCb = document.getElementById('removeCb')!
const addCb = document.getElementById('addCb')!
const requests = document.getElementById('requests')!
const logs = document.getElementById('logs')!
const state = document.getElementById('state')!
Expand All @@ -62,6 +66,15 @@ ${logs.innerHTML}`
logs.innerHTML = logEntry
})

removeCb.onclick = () => {
document.querySelector('radix-connect-button')?.remove()
}

addCb.onclick = () => {
const connectButton = document.createElement('radix-connect-button')
const header = document.querySelector('header')!
header.appendChild(connectButton)
}
const dAppToolkit = RadixDappToolkit({
dAppDefinitionAddress,
networkId,
Expand Down
1 change: 1 addition & 0 deletions packages/connect-button/src/components/connect-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class ConnectButton extends LitElement {

connectedCallback(): void {
super.connectedCallback()
window.dispatchEvent(new Event('onConnectButtonRender'))
this.dispatchEvent(
new CustomEvent('onRender', {
bubbles: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,12 @@ export const ConnectButtonModule = (

subscriptions.add(
merge(
fromEvent(document, 'onRender'),
fromEvent(window, 'onConnectButtonRender'),
of(getConnectButtonElement()).pipe(filter((e) => !!e)),
)
.pipe(
map(() => getConnectButtonElement()),
filter((element): element is ConnectButton => !!element),
first(),
switchMap((connectButtonElement) => {
logger?.debug({ event: `connectButtonDiscovered` })

Expand Down

0 comments on commit edcceb4

Please sign in to comment.