From 0bdeaa1bc0ce1a8c8f69091fe9a67c5766e99a0b Mon Sep 17 00:00:00 2001 From: Adam Sobotka Date: Tue, 1 Nov 2022 12:48:46 +0100 Subject: [PATCH] inamiddleofthings --- .env.example | 1 - .gitignore | 1 + src/App.tsx | 27 ++++++++++++-------- src/components/Account.tsx | 28 +++++++++++++++------ src/components/Balance.tsx | 14 +++++++++++ src/components/index.ts | 2 ++ src/components/useSoulBound.ts | 45 ---------------------------------- src/main.tsx | 1 - 8 files changed, 54 insertions(+), 65 deletions(-) delete mode 100644 .env.example create mode 100644 src/components/Balance.tsx delete mode 100644 src/components/useSoulBound.ts diff --git a/.env.example b/.env.example deleted file mode 100644 index 7e3b967..0000000 --- a/.env.example +++ /dev/null @@ -1 +0,0 @@ -VITE_ALCHEMY_API_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index d451ff1..c2245bb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules dist dist-ssr *.local +.env \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 3907b55..080fcf5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,7 @@ import { useAccount, useSignMessage } from "wagmi"; import { useEffect, useState } from "react"; -import { Account, Connect } from "./components"; +import { Balance, Connect } from "./components"; +import { BalanceType } from "./components"; import { verifyMessage } from "ethers/lib/utils"; import { SignMessageArgs } from "@wagmi/core"; @@ -10,6 +11,7 @@ export function App() { const [isEligible, setIsEligible] = useState(false); const [isFetching, setIsFetching] = useState("none"); const [network, setNetwork] = useState("goerli"); + const [balances, setBalances] = useState([]); const baseUrl = "https://faucet-api.ethbrno.cz"; const getEligibilityData = async () => { @@ -21,6 +23,8 @@ export function App() { mode: "cors", }); const res = await apiResponse.json(); + //console.log(res); + setBalances(res?.balances); if (res?.tokenId) setIsEligible(true); else setIsEligible(false); } catch (error) { @@ -133,15 +137,18 @@ export function App() { )} - {} -

- If you own a Soulbound token you can ask for up to 200 ETH for - either Goerli and Sepolia testnets. This should be enough not only - for a development purposes, but also for prepaid gas transactions - for your testing users. These tokens have no real monetary value. - Every request grants you 50 ETH and there is a request cooldown - for 5 hours to avoid misuse. -

+ {!isEligible + ? ( +

+ If you own a Soulbound token you can ask for up to 200 ETH for + either Goerli and Sepolia testnets. This should be enough not + only for a development purposes, but also for prepaid gas + transactions for your testing users. These tokens have no real + monetary value. Every request grants you 50 ETH and there is a + request cooldown for 5 hours to avoid misuse. +

+ ) + : } {!isConnecting || isConnected ? (
diff --git a/src/components/Account.tsx b/src/components/Account.tsx index 3b7828a..55987a1 100644 --- a/src/components/Account.tsx +++ b/src/components/Account.tsx @@ -1,13 +1,25 @@ -import { useAccount, useEnsName } from 'wagmi' +import { useAccount, useBalance, useEnsName } from "wagmi"; export function Account() { - const { address } = useAccount() - const { data: ensNameData } = useEnsName({ address }) + const { address } = useAccount(); + const { data: ensNameData } = useEnsName({ address }); + + const { data, isError, isLoading } = useBalance({ + addressOrName: address, + }); + + if (isLoading) return
Fetching balanceā€¦
; + if (isError) return
Error fetching balance
; return ( -
- {ensNameData ?? address} - {ensNameData ? ` (${address})` : null} -
- ) + <> +
+ {ensNameData ?? address} + {ensNameData ? ` (${address})` : null} +
+
+ Balance: {data?.formatted} {data?.symbol} +
+ + ); } diff --git a/src/components/Balance.tsx b/src/components/Balance.tsx new file mode 100644 index 0000000..a1e5bb7 --- /dev/null +++ b/src/components/Balance.tsx @@ -0,0 +1,14 @@ +export interface BalanceType { + balance: number; + network: string; + quota: Object; +} + +export function Balance(props: BalanceType[]) { + console.log(props); + return ( + <> + Balance + + ); +} diff --git a/src/components/index.ts b/src/components/index.ts index d7fbb2b..feb6da7 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -1,3 +1,5 @@ export { Account } from './Account' export { Connect } from './Connect' +export { Balance } from './Balance' +export type { BalanceType } from './Balance' export { NetworkSwitcher } from './NetworkSwitcher' diff --git a/src/components/useSoulBound.ts b/src/components/useSoulBound.ts deleted file mode 100644 index 248771c..0000000 --- a/src/components/useSoulBound.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { useState, useEffect } from 'react'; - - -export type SoulApiResponse = { - status: Number; - statusText: String; - data: any; - error: any; - loading: Boolean; - isEligible: Boolean; -}; - -const baseUrl = "https://faucet-api.ethbrno.cz/lookup?addr=" - -export const useApiGet = (addr: string): SoulApiResponse => { - const [status, setStatus] = useState(0); - const [statusText, setStatusText] = useState(''); - const [data, setData] = useState(); - const [error, setError] = useState(); - const [loading, setLoading] = useState(false); - const [isEligible, setIsEligible] = useState(false); - - const getAPIData = async () => { - setLoading(true); - try { - const apiResponse = await fetch(baseUrl + addr); - const json = await apiResponse.json(); - setStatus(apiResponse.status); - setStatusText(apiResponse.statusText); - setData(json); - } catch (error) { - setError(error); - } - //console.log(data.tokenId) - if (data?.tokenId) setIsEligible(true); - setLoading(false); - - }; - - useEffect(() => { - getAPIData(); - }, []); - - return { status, statusText, data, error, loading, isEligible }; -}; \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index 767b301..188c298 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -10,7 +10,6 @@ import { } from "wagmi"; import { CoinbaseWalletConnector } from "wagmi/connectors/coinbaseWallet"; import { InjectedConnector } from "wagmi/connectors/injected"; -import { MetaMaskConnector } from "wagmi/connectors/metaMask"; import { WalletConnectConnector } from "wagmi/connectors/walletConnect"; import { alchemyProvider } from "wagmi/providers/alchemy";