Skip to content

Commit

Permalink
fix: computations warning
Browse files Browse the repository at this point in the history
  • Loading branch information
isordo committed Sep 6, 2023
1 parent 079c3b2 commit deb1e9c
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions packages/beacon-ui/src/ui/alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const openAlert = async (config: AlertConfig): Promise<string> => {
// Shadow root
const shadowRootEl = document.createElement('div')
if (document.getElementById('beacon-alert-wrapper')) {
(document.getElementById('beacon-alert-wrapper') as HTMLElement).remove()
;(document.getElementById('beacon-alert-wrapper') as HTMLElement).remove()
}
shadowRootEl.setAttribute('id', 'beacon-alert-wrapper')
shadowRootEl.style.height = '0px'
Expand Down Expand Up @@ -335,40 +335,44 @@ const openAlert = async (config: AlertConfig): Promise<string> => {
const [isMobile, setIsMobile] = createSignal(_isMobileOS)
const [windowWidth, setWindowWidth] = createSignal(window.innerWidth)

const debounce = (fun: Function, delay: number) => {
let timerId: NodeJS.Timeout
const AlertResize = () => {
const debounce = (fun: Function, delay: number) => {
let timerId: NodeJS.Timeout

return (...args: any[]) => {
clearTimeout(timerId)
timerId = setTimeout(() => fun(...args), delay)
return (...args: any[]) => {
clearTimeout(timerId)
timerId = setTimeout(() => fun(...args), delay)
}
}
}

const debouncedSetWindowWidth = debounce(setWindowWidth, 200)
const debouncedSetWindowWidth = debounce(setWindowWidth, 200)

const updateIsMobile = (isMobileWidth: boolean) => {
// to avoid unwanted side effects (because of the OR condition), I always reset the value without checking the previous state
setWalletList(createWalletList())
setIsMobile(isMobileWidth || _isMobileOS)
}
const updateIsMobile = (isMobileWidth: boolean) => {
// to avoid unwanted side effects (because of the OR condition), I always reset the value without checking the previous state
setWalletList(createWalletList())
setIsMobile(isMobileWidth || _isMobileOS)
}

createEffect(() => {
updateIsMobile(windowWidth() <= 800)
})
createEffect(() => {
updateIsMobile(windowWidth() <= 800)
})

// Update the windowWidth signal when the window resizes
createEffect(() => {
const handleResize = () => {
debouncedSetWindowWidth(window.innerWidth)
}
// Update the windowWidth signal when the window resizes
createEffect(() => {
const handleResize = () => {
debouncedSetWindowWidth(window.innerWidth)
}

window.addEventListener('resize', handleResize)
window.addEventListener('resize', handleResize)

// Unsubscribe from the event when the component unmounts
onCleanup(() => {
window.removeEventListener('resize', handleResize)
// Unsubscribe from the event when the component unmounts
onCleanup(() => {
window.removeEventListener('resize', handleResize)
})
})
})

return <></>
}

const handleClickShowMoreContent = () => {
analytics()?.track('click', 'ui', 'show more wallets')
Expand Down Expand Up @@ -463,7 +467,7 @@ const openAlert = async (config: AlertConfig): Promise<string> => {
}
}
setIsLoading(false)
} else if (wallet?.types.includes('ios') && _isMobileOS) {
} else if (wallet?.types.includes('ios') && _isMobileOS) {
setCodeQR('')

if (config.pairingPayload) {
Expand Down Expand Up @@ -570,6 +574,7 @@ const openAlert = async (config: AlertConfig): Promise<string> => {
dispose = render(
() => (
<div class={`theme__${colorMode}`}>
<AlertResize />
{config.pairingPayload && (
<Alert
loading={isLoading()}
Expand Down

0 comments on commit deb1e9c

Please sign in to comment.