Skip to content

Commit e2e0943

Browse files
committed
refactor: useContractAddress() is not concerned with the network anymore
1 parent 2c8c071 commit e2e0943

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

web/src/consts/coingecko.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// https://apiguide.coingecko.com/getting-started/10-min-tutorial-guide/1-get-data-by-id-or-address
2+
export const CoinIds = {
3+
ETH: "coingecko:ethereum",
4+
PNK: "coingecko:kleros",
5+
};

web/src/hooks/useCoinPrice.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useQuery } from "@tanstack/react-query";
22

33
const fetchCoinPrices = async (...coinIds) => {
4-
const response = await fetch(`https://coins.llama.fi/prices/current/${coinIds.join(",")}`);
4+
const response = await fetch(`https://coins.llama.fi/prices/current/${coinIds.join(",")}?searchWidth=1h`);
55
const data = await response.json();
66
return data.coins;
77
};

web/src/hooks/useContractAddress.tsx

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,13 @@ export const useContractAddress = <TAbi extends Abi>(
1515
};
1616

1717
export const usePNKAddress = () => {
18-
return `ethereum:${useContractAddress<typeof pinakionV2ABI>(getPinakionV2)?.address}`;
18+
return useContractAddress<typeof pinakionV2ABI>(getPinakionV2)?.address;
1919
};
2020

2121
export const useWETHAddress = () => {
22-
return `ethereum:${useContractAddress<typeof wethABI>(getWeth)?.address}`;
22+
return useContractAddress<typeof wethABI>(getWeth)?.address;
2323
};
2424

2525
export const usePNKFaucetAddress = () => {
2626
return useContractAddress<typeof pnkFaucetABI>(getPnkFaucet)?.address;
2727
};
28-
29-
export const useWETHMainnetAddress = () => {
30-
return "ethereum:0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
31-
};
32-
33-
export const usePNKMainnetAddress = () => {
34-
return "ethereum:0x93ed3fbe21207ec2e8f2d3c3de6e058cb73bc04d";
35-
};

web/src/pages/Courts/CourtDetails/Stats.tsx

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import styled from "styled-components";
33
import { useParams } from "react-router-dom";
44
import { useCourtDetails, CourtDetailsQuery } from "queries/useCourtDetails";
55
import { useCoinPrice } from "hooks/useCoinPrice";
6-
import { usePNKMainnetAddress, useWETHMainnetAddress } from "hooks/useContractAddress";
76
import { formatETH, formatPNK, formatUnitsWei, formatUSD, isUndefined } from "utils/index";
87
import { calculateSubtextRender } from "utils/calculateSubtextRender";
8+
import { CoinIds } from "consts/coingecko";
99
import StatDisplay, { IStatDisplay } from "components/StatDisplay";
1010
import { StyledSkeleton } from "components/StyledSkeleton";
1111
import BalanceIcon from "svgs/icons/law-balance.svg";
@@ -96,14 +96,13 @@ const stats: IStat[] = [
9696
const Stats = () => {
9797
const { id } = useParams();
9898
const { data } = useCourtDetails(id);
99-
const coinIdToAddress = [usePNKMainnetAddress(), useWETHMainnetAddress()];
100-
const { prices: pricesData } = useCoinPrice(coinIdToAddress);
99+
const coinIds = [CoinIds.PNK, CoinIds.ETH];
100+
const { prices: pricesData } = useCoinPrice(coinIds);
101101

102102
return (
103103
<StyledCard>
104104
{stats.map(({ title, coinId, getText, getSubtext, color, icon }, i) => {
105-
const coinPrice = !isUndefined(pricesData) ? pricesData[coinIdToAddress[coinId!]]?.price : undefined;
106-
105+
const coinPrice = !isUndefined(pricesData) ? pricesData[coinIds[coinId!]]?.price : undefined;
107106
return (
108107
<StatDisplay
109108
key={i}

web/src/pages/Dashboard/JurorInfo/JurorRewards.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { useAccount } from "wagmi";
55
import TokenRewards from "./TokenRewards";
66
import WithHelpTooltip from "../WithHelpTooltip";
77
import { isUndefined } from "utils/index";
8+
import { CoinIds } from "consts/coingecko";
89
import { useUserQuery, UserQuery } from "queries/useUser";
910
import { useCoinPrice } from "hooks/useCoinPrice";
10-
import { usePNKMainnetAddress, useWETHMainnetAddress } from "hooks/useContractAddress";
1111

1212
interface IReward {
1313
token: "ETH" | "PNK";
@@ -54,8 +54,8 @@ const calculateTotalReward = (coinId: number, data: UserQuery): bigint => {
5454
const Coherency: React.FC = () => {
5555
const { address } = useAccount();
5656
const { data } = useUserQuery(address?.toLowerCase());
57-
const coinIdToAddress = [usePNKMainnetAddress(), useWETHMainnetAddress()];
58-
const { prices: pricesData } = useCoinPrice(coinIdToAddress);
57+
const coinIds = [CoinIds.PNK, CoinIds.ETH];
58+
const { prices: pricesData } = useCoinPrice(coinIds);
5959

6060
return (
6161
<>
@@ -64,7 +64,7 @@ const Coherency: React.FC = () => {
6464
<label> Juror Rewards </label>
6565
</WithHelpTooltip>
6666
{rewards.map(({ token, coinId, getValue, getAmount }) => {
67-
const coinPrice = !isUndefined(pricesData) ? pricesData[coinIdToAddress[coinId]]?.price : undefined;
67+
const coinPrice = !isUndefined(pricesData) ? pricesData[coinIds[coinId]]?.price : undefined;
6868
const totalReward = data && calculateTotalReward(coinId, data);
6969
return (
7070
<TokenRewards

web/src/pages/Home/CourtOverview/Stats.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import JurorIcon from "svgs/icons/user.svg";
1010
import BalanceIcon from "svgs/icons/law-balance.svg";
1111
import { formatETH, formatPNK, formatUnitsWei, formatUSD, isUndefined } from "utils/index";
1212
import { calculateSubtextRender } from "utils/calculateSubtextRender";
13+
import { CoinIds } from "consts/coingecko";
1314
import { useHomePageContext, HomePageQuery, HomePageQueryDataPoints } from "hooks/useHomePageContext";
1415
import { useCoinPrice } from "hooks/useCoinPrice";
15-
import { usePNKMainnetAddress, useWETHMainnetAddress } from "hooks/useContractAddress";
1616

1717
const StyledCard = styled(Card)`
1818
width: auto;
@@ -79,12 +79,12 @@ const stats: IStat[] = [
7979

8080
const Stats = () => {
8181
const { data } = useHomePageContext();
82-
const coinIdToAddress = [usePNKMainnetAddress(), useWETHMainnetAddress()];
83-
const { prices: pricesData } = useCoinPrice(coinIdToAddress);
82+
const coinIds = [CoinIds.PNK, CoinIds.ETH];
83+
const { prices: pricesData } = useCoinPrice(coinIds);
8484
return (
8585
<StyledCard>
8686
{stats.map(({ title, coinId, getText, getSubtext, color, icon }, i) => {
87-
const coinPrice = !isUndefined(pricesData) ? pricesData[coinIdToAddress[coinId!]]?.price : undefined;
87+
const coinPrice = !isUndefined(pricesData) ? pricesData[coinIds[coinId!]]?.price : undefined;
8888

8989
return (
9090
<StatDisplay

0 commit comments

Comments
 (0)