Skip to content

Commit

Permalink
Merge pull request #1357 from galacticcouncil/hydration-migration
Browse files Browse the repository at this point in the history
Show migration banner only for accounts with balance
  • Loading branch information
jvonasek authored Jun 5, 2024
2 parents 1241c67 + fd53226 commit b1cf889
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
22 changes: 21 additions & 1 deletion src/components/Layout/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import { Interpolation, Theme } from "@emotion/react"
import { Web3Connect } from "sections/web3-connect/Web3Connect"
import { ReferralsConnect } from "sections/referrals/ReferralsConnect"
import { useRpcProvider } from "providers/rpcProvider"
import { MigrationWarning } from "sections/migration/components/MigrationWarning"
import {
MIGRATION_TARGET_DOMAIN,
MIGRATION_TRIGGER_DOMAIN,
useMigrationStore,
} from "sections/migration/MigrationProvider.utils"

type Props = {
className?: string
Expand All @@ -28,9 +34,10 @@ export const Page = ({
subHeader,
subHeaderStyle,
}: Props) => {
const { featureFlags } = useRpcProvider()
const { featureFlags, isLoaded } = useRpcProvider()
const ref = useRef<HTMLDivElement>(null)
const location = useLocation()
const { migrationCompleted, setMigrationCompleted } = useMigrationStore()

useEffect(() => {
ref.current?.scrollTo({
Expand All @@ -39,8 +46,21 @@ export const Page = ({
})
}, [location.pathname])

const shouldShowMigrationWarning =
isLoaded && MIGRATION_TARGET_DOMAIN === location.host && !migrationCompleted

return (
<>
{shouldShowMigrationWarning && (
<MigrationWarning
onClick={() =>
(window.location.href = `https://${MIGRATION_TRIGGER_DOMAIN}?from=${MIGRATION_TARGET_DOMAIN}`)
}
onClose={() => {
setMigrationCompleted(new Date().toISOString())
}}
/>
)}
<SPage ref={ref}>
<div
sx={{ flex: "column", height: "100%" }}
Expand Down
24 changes: 1 addition & 23 deletions src/sections/migration/MigrationProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import {
MIGRATION_TARGET_DOMAIN,
MIGRATION_TRIGGER_DOMAIN,
serializeLocalStorage,
useMigrationStore,
} from "sections/migration/MigrationProvider.utils"
import { MigrationWarning } from "sections/migration/components/MigrationWarning"
import { MigrationExportModal } from "./components/MigrationExportModal"
import { MigrationImportModal } from "./components/MigrationImportModal"

export const MigrationProvider: FC<PropsWithChildren> = ({ children }) => {
const { search, host } = useLocation()
const { migrationCompleted, setMigrationCompleted } = useMigrationStore()

const [migrationCanceled, setMigrationCanceled] = useState(false)

Expand Down Expand Up @@ -47,24 +44,5 @@ export const MigrationProvider: FC<PropsWithChildren> = ({ children }) => {
)
}

const shouldShowWarning =
MIGRATION_TARGET_DOMAIN === host &&
!migrationCompleted &&
!migrationCanceled

return (
<>
{shouldShowWarning && (
<MigrationWarning
onClick={() =>
(window.location.href = `https://${MIGRATION_TRIGGER_DOMAIN}?from=${MIGRATION_TARGET_DOMAIN}`)
}
onClose={() => {
setMigrationCompleted(new Date().toISOString())
}}
/>
)}
{children}
</>
)
return <>{children}</>
}
10 changes: 10 additions & 0 deletions src/sections/migration/components/MigrationWarning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { useTranslation } from "react-i18next"
import Star from "assets/icons/Star.svg?react"
import LinkIcon from "assets/icons/LinkIcon.svg?react"
import { Separator } from "components/Separator/Separator"
import { useWalletAssetsTotals } from "sections/wallet/assets/WalletAssets.utils"
import { useAccount } from "sections/web3-connect/Web3Connect.utils"

export type MigrationWarningProps = {
onClick: () => void
Expand All @@ -19,6 +21,14 @@ export const MigrationWarning: React.FC<MigrationWarningProps> = ({
onClose,
}) => {
const { t } = useTranslation()

const { account } = useAccount()
const { balanceTotal, isLoading } = useWalletAssetsTotals({
address: account?.address,
})

if (isLoading || balanceTotal?.isZero()) return null

return (
<SWarningMessageContainer onClick={onClick} variant="pink">
<SSecondaryItem />
Expand Down

0 comments on commit b1cf889

Please sign in to comment.