Skip to content

Commit

Permalink
fix: wallet ui wrong position when window size change (#2415)
Browse files Browse the repository at this point in the history
* fix: wallet ui wrong position when window size change

* fix: tokenlist empty
  • Loading branch information
nguyenhoaidanh authored Dec 5, 2023
1 parent 4ae24f8 commit 1d4b84a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/components/SearchModal/CurrencySearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ export function CurrencySearch({
tokenImports?.forEach(removeImportedToken)
}

const onChangeTab = (tab: Tab) => {
if (!debouncedQuery && tab === Tab.All) {
setFetchedTokens(Object.values(defaultTokens))
}
setActiveTab(tab)
}

return (
<ContentWrapper>
<PaddedColumn gap="14px">
Expand Down Expand Up @@ -446,13 +453,13 @@ export function CurrencySearch({
columnGap: '24px',
}}
>
<TabButton data-active={activeTab === Tab.All} onClick={() => setActiveTab(Tab.All)} data-testid="tab-all">
<TabButton data-active={activeTab === Tab.All} onClick={() => onChangeTab(Tab.All)} data-testid="tab-all">
<Text as="span" fontSize={14} fontWeight={500}>
<Trans>All</Trans>
</Text>
</TabButton>

<TabButton data-active={isImportedTab} onClick={() => setActiveTab(Tab.Imported)} data-testid="tab-import">
<TabButton data-active={isImportedTab} onClick={() => onChangeTab(Tab.Imported)} data-testid="tab-import">
<Text as="span" fontSize={14} fontWeight={500}>
<Trans>Imported</Trans>
</Text>
Expand Down
17 changes: 13 additions & 4 deletions src/components/WalletPopup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { isMobile } from 'react-device-detect'
import { createPortal } from 'react-dom'
import { Rnd } from 'react-rnd'
Expand All @@ -21,8 +21,6 @@ const GlobalStyle = createGlobalStyle<{ $pinned: boolean }>`
}
`

const viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)
const viewportHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
const defaultWidth = 410
const defaultHeight = 680

Expand Down Expand Up @@ -61,6 +59,15 @@ const WalletPopup: React.FC<Props> = ({ isModalOpen, onDismissModal, isPinned, s
mixpanelHandler(MIXPANEL_TYPE.WUI_UNPINNED_WALLET)
}

const [key, setKey] = useState(0)
useEffect(() => {
const resizeHandler = () => {
if (isPinned) setKey(Date.now())
}
window.addEventListener('resize', resizeHandler)
return () => window.removeEventListener('resize', resizeHandler)
}, [isPinned])

if (!rootNode) {
return null
}
Expand Down Expand Up @@ -98,7 +105,8 @@ const WalletPopup: React.FC<Props> = ({ isModalOpen, onDismissModal, isPinned, s
</Modal>
)
}

const viewportWidth = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0)
const viewportHeight = Math.max(document.documentElement.clientHeight || 0, window.innerHeight || 0)
const offset = isPinned ? 10 : 0
const left = viewportWidth - offset - defaultWidth
const top = viewportHeight - offset - defaultHeight
Expand All @@ -109,6 +117,7 @@ const WalletPopup: React.FC<Props> = ({ isModalOpen, onDismissModal, isPinned, s
{shouldOpenPopup &&
createPortal(
<Rnd
key={key}
default={{
x: left,
y: top,
Expand Down

0 comments on commit 1d4b84a

Please sign in to comment.