-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSolFeesApp.tsx
More file actions
169 lines (156 loc) · 4.54 KB
/
Copy pathSolFeesApp.tsx
File metadata and controls
169 lines (156 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"use client"
import { Transition } from "@headlessui/react"
import { WalletAdapterNetwork } from "@solana/wallet-adapter-base"
import {
ConnectionProvider,
WalletProvider,
} from "@solana/wallet-adapter-react"
import { WalletModalProvider } from "@solana/wallet-adapter-react-ui"
import { SolflareWalletAdapter } from "@solana/wallet-adapter-wallets"
import { clusterApiUrl } from "@solana/web3.js"
import clx from "classnames"
import { type ReactNode, useLayoutEffect, useMemo, useState } from "react"
import Confetti from "react-confetti"
import { useMeasure } from "react-use"
import { FadeInOutTransition, Spotlight } from "@/components/atoms"
import { About, ErrorDisplay, Progress } from "@/components/molecules"
import { Result, WalletForm } from "@/components/templates"
import { useSolPrice, useTransactions } from "@/hooks"
import { type WalletResult } from "@/types"
const Providers = ({ children }: { children: ReactNode }) => {
const walletEndpoint = useMemo(
() => clusterApiUrl(WalletAdapterNetwork.Mainnet),
[],
)
const wallets = useMemo(() => [new SolflareWalletAdapter()], [])
return (
<ConnectionProvider endpoint={walletEndpoint}>
<WalletProvider wallets={wallets} autoConnect>
<WalletModalProvider>{children}</WalletModalProvider>
</WalletProvider>
</ConnectionProvider>
)
}
const SolFeesApp = () => {
const [address, setAddress] = useState<string | null>(null)
const [timeframe, setTimeframe] = useState<number>(0)
const {
addWallet: addAnotherWallet,
error,
isLoading,
progress,
reset: resetResult,
summary,
state,
wallets,
} = useTransactions(address, timeframe)
const solPrice = useSolPrice()
const addWallet = () => {
addAnotherWallet()
setAddress(null)
}
const reset = () => {
resetResult()
setAddress(null)
setTimeframe(0)
}
const [appReady, setAppReady] = useState(false)
useLayoutEffect(() => {
setAppReady(true)
}, [])
const [measureRef, { width: screenWidth, height: screenHeight }] =
useMeasure<HTMLElement>()
const [isElementLeaving, setIsElementLeaving] = useState(false)
const setElementLeaving = () => setIsElementLeaving(true)
const setElementNotLeaving = () => setIsElementLeaving(false)
let spotlight1Size = screenWidth / 2
let spotlight2Size = screenWidth / 3
spotlight1Size = spotlight1Size > 400 ? 400 : spotlight1Size
spotlight2Size = spotlight2Size > 200 ? 200 : spotlight2Size
return (
<Providers>
<main
ref={measureRef}
className="min-h-screen flex flex-col items-center justify-center px-2"
>
<FadeInOutTransition
show={
(state === "intro" || state === "error") &&
appReady &&
!isElementLeaving
}
beforeLeave={setElementLeaving}
afterLeave={setElementNotLeaving}
>
<ErrorDisplay error={error} />
<WalletForm
reset={reset}
setAddress={setAddress}
setTimeframe={setTimeframe}
wallets={wallets.length}
/>
</FadeInOutTransition>
<FadeInOutTransition
show={
(state === "loading" || state === "resolving") && !isElementLeaving
}
beforeLeave={setElementLeaving}
afterLeave={setElementNotLeaving}
>
<Progress state={state} progress={progress} />
<Spotlight opacity={0.1} size={spotlight1Size} />
<Spotlight opacity={0.2} size={spotlight2Size} />
</FadeInOutTransition>
<Transition
show={state === "done" && !isElementLeaving}
afterEnter={() => window.scrollTo(0, 0)}
beforeLeave={setElementLeaving}
afterLeave={setElementNotLeaving}
enter="transition-transform duration-200 ease-in"
enterFrom="translate-y-full"
enterTo="translate-y-0"
leave="transition-transform duration-200 ease-out"
leaveFrom="translate-y-0"
leaveTo="translate-y-full"
className={clx(
"grow",
"flex",
"flex-col",
"w-full",
"sm:max-w-xl md:max-w-2xl lg:max-w-4xl",
"mx-auto",
"mt-2 sm:mt-4 md:mt-8",
"pt-2 sm:pt-4 md:pt-8",
"px-2 sm:px-4 md:px-8",
"rounded-t-lg",
"bg-white",
"shadow-2xl",
)}
>
<div className="grow">
<Result
addWallet={addWallet}
reset={reset}
summary={summary as WalletResult}
wallets={wallets}
solPrice={solPrice}
isLoading={isLoading}
/>
</div>
<About className="mt-12" />
</Transition>
{state === "done" ? (
<Confetti
gravity={0.5}
height={screenHeight}
numberOfPieces={200}
recycle={false}
run={state === "done"}
width={screenWidth}
/>
) : null}
</main>
</Providers>
)
}
export { SolFeesApp }