Skip to content

Commit 55be6a8

Browse files
authored
Merge pull request #176 from ethereum/walletsPage
migrate /wallets page
2 parents 696cb76 + 7a757e7 commit 55be6a8

File tree

16 files changed

+563
-116
lines changed

16 files changed

+563
-116
lines changed

src/components/Callout.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useTranslation } from "next-i18next"
2-
import { Flex, type FlexProps } from "@chakra-ui/react"
2+
import { Center, Flex, type FlexProps } from "@chakra-ui/react"
33

44
import type { TranslationKey } from "@/lib/types"
55

@@ -49,16 +49,9 @@ const Callout: React.FC<IProps> = ({
4949
{...rest}
5050
>
5151
{image && (
52-
<Image
53-
src={image}
54-
alt={alt || ""}
55-
mt={-40}
56-
alignSelf="center"
57-
w={263}
58-
h={200}
59-
maxW="263px"
60-
minH="200px"
61-
/>
52+
<Center maxW="263px" minH="200px" mt={-40} alignSelf="center">
53+
<Image src={image} alt={alt || ""} height={200} />
54+
</Center>
6255
)}
6356
<Flex direction="column" justify="space-between" mt={10} h="full">
6457
<div>

src/components/Simulator/NotificationPopover.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const NotificationPopover: React.FC<IProps> = ({
2727
return (
2828
<Popover placement={placement}>
2929
<PopoverTrigger>{children}</PopoverTrigger>
30-
<Portal>
3130
<PopoverContent
3231
bg="background.highlight"
3332
px={4}
@@ -46,7 +45,6 @@ export const NotificationPopover: React.FC<IProps> = ({
4645
</Flex>
4746
<PopoverBody>{content}</PopoverBody>
4847
</PopoverContent>
49-
</Portal>
5048
</Popover>
5149
)
5250
}

src/components/Simulator/WalletHome/AddressPill.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import { FAKE_DEMO_ADDRESS } from "../constants"
66
import { NotificationPopover } from "../NotificationPopover"
77

88
interface IProps extends Omit<FlexProps, "children"> {
9-
children?: Pick<FlexProps, "children">
109
}
11-
export const AddressPill: React.FC<IProps> = ({ children, ...btnProps }) => (
10+
export const AddressPill: React.FC<IProps> = ({ ...btnProps }) => (
1211
<NotificationPopover
1312
title="Example walkthrough"
1413
content="Share your address (public identifier) from your own wallet when finished here"
@@ -27,7 +26,7 @@ export const AddressPill: React.FC<IProps> = ({ children, ...btnProps }) => (
2726
fontSize="xs"
2827
{...btnProps}
2928
>
30-
<Text m={0}>{children ?? FAKE_DEMO_ADDRESS}</Text>
29+
<Text m={0}>{FAKE_DEMO_ADDRESS}</Text>
3130
<Icon as={MdContentCopy} w={4} fontSize="lg" />
3231
</Flex>
3332
</NotificationPopover>

src/components/Simulator/WalletHome/NFTList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
useBreakpointValue,
88
} from "@chakra-ui/react"
99

10-
import GatsbyImage from "../../GatsbyImage"
10+
import { Image } from "@/components/Image"
1111

1212
import type { NFT } from "./interfaces"
1313

@@ -21,8 +21,8 @@ export const NFTList: React.FC<IProps> = ({ nfts, ...flexProps }) => {
2121
{nfts.length ? (
2222
nfts.map(({ title, image }) => (
2323
<Box key={title} w="fit-content">
24-
<GatsbyImage
25-
image={image}
24+
<Image
25+
src={image}
2626
alt=""
2727
objectFit="contain"
2828
maxW={size}

src/components/Simulator/WalletHome/hooks/useNFT.tsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/components/Simulator/WalletHome/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IGatsbyImageData } from "gatsby-plugin-image"
1+
import { StaticImageData } from "next/image"
22
import type { IconProps } from "@chakra-ui/react"
33

44
export interface TokenBalance {
@@ -16,5 +16,5 @@ export interface Contact {
1616

1717
export interface NFT {
1818
title: string
19-
image: IGatsbyImageData
19+
image: StaticImageData
2020
}

src/components/Simulator/index.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useEffect, useMemo, useState } from "react"
2-
import { navigate } from "gatsby"
2+
import { useRouter } from "next/router"
33
import { Flex, type FlexProps, Grid } from "@chakra-ui/react"
44

5-
import { trackCustomEvent } from "../../utils/matomo"
5+
import { trackCustomEvent } from "@/lib/utils/matomo"
66

77
import { PATH_ID_QUERY_PARAM, SIMULATOR_ID } from "./constants"
88
import { Explanation } from "./Explanation"
@@ -16,26 +16,30 @@ import { Phone } from "./Phone"
1616
import { SimulatorModal } from "./SimulatorModal"
1717
import { Template } from "./Template"
1818
import type { PathId, SimulatorData } from "./types"
19-
import { clearUrlParams, getValidPathId } from "./utils"
19+
import { getValidPathId } from "./utils"
2020

2121
interface IProps extends Pick<FlexProps, "children"> {
2222
data: SimulatorData
23-
location: Location
2423
}
25-
export const Simulator: React.FC<IProps> = ({ children, data, location }) => {
24+
export const Simulator: React.FC<IProps> = ({ children, data }) => {
25+
const router = useRouter()
26+
2627
// Track step
2728
const [step, setStep] = useState(0) // 0-indexed to use as array index
2829

2930
// Track pathID
30-
const params = new URLSearchParams(location.search)
31-
const pathIdString = params.get(PATH_ID_QUERY_PARAM)
32-
const pathId = getValidPathId(pathIdString)
31+
const pathId = getValidPathId(router.query.sim as string)
3332
const simulator: SimulatorDetails | null = pathId ? data[pathId] : null
3433
const totalSteps: number = simulator ? simulator.explanations.length : 0
3534

3635
// If pathId present, modal is open, else closed
3736
const isOpen = !!pathId
3837

38+
const clearUrlParams = () => {
39+
const pathWithoutParams = router.asPath.replace(/\?[^\#]*/, "")
40+
router.replace(pathWithoutParams)
41+
}
42+
3943
// When simulator closed: log event, clear URL params and close modal
4044
const onClose = (): void => {
4145
trackCustomEvent({
@@ -44,14 +48,15 @@ export const Simulator: React.FC<IProps> = ({ children, data, location }) => {
4448
eventName: `close-from-step-${step + 1}`,
4549
})
4650
// Clearing URL Params will reset pathId, and close modal
47-
clearUrlParams(location)
51+
clearUrlParams()
4852
}
4953

5054
// Remove URL search param if invalid pathId
5155
useEffect(() => {
5256
setStep(0)
53-
if (!pathId) clearUrlParams(location)
54-
}, [location, pathId])
57+
if (!pathId) clearUrlParams()
58+
// eslint-disable-next-line react-hooks/exhaustive-deps
59+
}, [pathId])
5560

5661
// Navigation helpers
5762
const progressStepper = (): void => {
@@ -70,7 +75,7 @@ export const Simulator: React.FC<IProps> = ({ children, data, location }) => {
7075
eventName: `back-from-step-${step + 1}`,
7176
})
7277
if (step === 0) {
73-
clearUrlParams(location)
78+
clearUrlParams()
7479
return
7580
}
7681
setStep((step) => Math.max(step - 1, 0))
@@ -81,7 +86,7 @@ export const Simulator: React.FC<IProps> = ({ children, data, location }) => {
8186
const params = new URLSearchParams()
8287
params.set(PATH_ID_QUERY_PARAM, id)
8388
const url = `?${params.toString()}#${SIMULATOR_ID}`
84-
navigate(url, { replace: true })
89+
router.replace(url)
8590
}
8691

8792
// Navigation object passed to child components

src/components/Simulator/screens/ConnectWeb3/index.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {
77
} from "react-icons/ri"
88
import { Box, Button, Flex, Icon, Text } from "@chakra-ui/react"
99

10+
import { Image } from "@/components/Image"
11+
1012
import { useEthPrice } from "../../../../hooks/useEthPrice"
11-
import GatsbyImage from "../../../GatsbyImage"
1213
import {
1314
BASE_ANIMATION_DELAY_SEC,
1415
defaultTokenBalances,
@@ -19,17 +20,23 @@ import type { PhoneScreenProps } from "../../interfaces"
1920
import { NotificationPopover } from "../../NotificationPopover"
2021
import { ProgressCta } from "../../ProgressCta"
2122
import { WalletHome } from "../../WalletHome"
22-
import { useNFT } from "../../WalletHome/hooks/useNFT"
2323
import type { TokenBalance } from "../../WalletHome/interfaces"
2424

2525
import { Browser } from "./Browser"
2626
import { EXAMPLE_APP_URL } from "./constants"
2727
import { Slider } from "./Slider"
2828
import { Web3App } from "./Web3App"
2929

30+
import NFTImage from "@/public/deep-panic.png"
31+
3032
export const ConnectWeb3: React.FC<PhoneScreenProps> = ({ nav, ctaLabel }) => {
3133
const { progressStepper, step } = nav
32-
const NFTs = useNFT()
34+
const NFTs = [
35+
{
36+
title: "Cool art",
37+
image: NFTImage,
38+
},
39+
]
3340
const fetchedPrice = useEthPrice()
3441
const ethPrice = fetchedPrice > 1 ? fetchedPrice : FALLBACK_ETH_PRICE
3542
const tokensWithEthBalance = useMemo<Array<TokenBalance>>(
@@ -46,7 +53,12 @@ export const ConnectWeb3: React.FC<PhoneScreenProps> = ({ nav, ctaLabel }) => {
4653
[ethPrice]
4754
)
4855
const [activeTabIndex, setActiveTabIndex] = useState(1)
49-
const nfts = useNFT()
56+
const nfts = [
57+
{
58+
title: "Cool art",
59+
image: NFTImage,
60+
},
61+
]
5062
const fadeInProps = {
5163
initial: { opacity: 0 },
5264
animate: { opacity: 1 },
@@ -129,7 +141,7 @@ export const ConnectWeb3: React.FC<PhoneScreenProps> = ({ nav, ctaLabel }) => {
129141
Your collection (1)
130142
</Text>
131143
<Flex gap={2} mb={6}>
132-
<GatsbyImage image={NFTs[0].image} alt="NFT Image" />
144+
<Image src={NFTs[0].image} width={120} height={120} alt="NFT Image" />
133145
<NotificationPopover
134146
title="Example walkthrough"
135147
content="These are some things you could do as the owner of your NFTs"

src/components/Simulator/screens/CreateAccount/WordSelectorButtons.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const WordSelectorButtons: React.FC<IProps> = ({
3636
return [...acc.slice(0, randIndex), item, ...acc.slice(randIndex)]
3737
}, restRandom)
3838
return pseudoRandom
39-
}, [wordIndices])
39+
// eslint-disable-next-line react-hooks/exhaustive-deps
40+
}, [])
4041

4142
const incrementWordsSelected = useCallback(() => {
4243
setWordsSelected((prev) => prev + 1)

src/components/Simulator/screens/CreateAccount/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState } from "react"
22

3-
import { generateInvalidSafeSeed } from "../../../../utils/generateSeed"
3+
import { generateInvalidSafeSeed } from "@/lib/utils/generateSeed"
4+
45
import type { PhoneScreenProps } from "../../interfaces"
56
import { ProgressCta } from "../../ProgressCta"
67
import { WalletHome } from "../../WalletHome"

0 commit comments

Comments
 (0)