Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: computations warning #578

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading