|
1 | 1 | import React, { useState, useMemo, useEffect } from "react"; |
2 | 2 | import styled, { css } from "styled-components"; |
3 | | -import { landscapeStyle } from "styles/landscapeStyle"; |
4 | 3 |
|
5 | 4 | import { useParams } from "react-router-dom"; |
6 | 5 | import { useDebounce } from "react-use"; |
7 | | -import { useAccount } from "wagmi"; |
8 | | - |
9 | | -import { REFETCH_INTERVAL } from "consts/index"; |
10 | 6 |
|
11 | | -import { useReadSortitionModuleGetJurorBalance, useReadPnkBalanceOf } from "hooks/contracts/generated"; |
12 | 7 | import { useParsedAmount } from "hooks/useParsedAmount"; |
13 | | - |
| 8 | +import { usePnkData } from "hooks/usePNKData"; |
14 | 9 | import { commify, uncommify } from "utils/commify"; |
15 | 10 | import { formatPNK, roundNumberDown } from "utils/format"; |
16 | 11 | import { isUndefined } from "utils/index"; |
17 | 12 |
|
| 13 | +import { landscapeStyle } from "styles/landscapeStyle"; |
| 14 | + |
18 | 15 | import { NumberInputField } from "components/NumberInputField"; |
| 16 | + |
19 | 17 | import StakeWithdrawButton, { ActionType } from "./StakeWithdrawButton"; |
20 | 18 |
|
21 | 19 | const StyledField = styled(NumberInputField)` |
22 | 20 | height: fit-content; |
| 21 | + input { |
| 22 | + border-radius: 3px 0px 0px 3px; |
| 23 | + } |
23 | 24 | `; |
24 | 25 |
|
25 | 26 | const LabelArea = styled.div` |
@@ -62,48 +63,27 @@ const EnsureChainContainer = styled.div` |
62 | 63 | button { |
63 | 64 | height: 45px; |
64 | 65 | border: 1px solid ${({ theme }) => theme.stroke}; |
| 66 | + border-radius: 0px 3px 3px 0px; |
65 | 67 | } |
66 | 68 | `; |
67 | 69 |
|
68 | 70 | interface IInputDisplay { |
69 | 71 | action: ActionType; |
70 | | - isSending: boolean; |
71 | | - setIsSending: (arg0: boolean) => void; |
72 | | - setIsPopupOpen: (arg0: boolean) => void; |
73 | 72 | amount: string; |
74 | 73 | setAmount: (arg0: string) => void; |
75 | 74 | } |
76 | 75 |
|
77 | | -const InputDisplay: React.FC<IInputDisplay> = ({ |
78 | | - action, |
79 | | - isSending, |
80 | | - setIsSending, |
81 | | - setIsPopupOpen, |
82 | | - amount, |
83 | | - setAmount, |
84 | | -}) => { |
| 76 | +const InputDisplay: React.FC<IInputDisplay> = ({ action, amount, setAmount }) => { |
85 | 77 | const [debouncedAmount, setDebouncedAmount] = useState(""); |
86 | 78 | const [errorMsg, setErrorMsg] = useState<string | undefined>(); |
87 | 79 | useDebounce(() => setDebouncedAmount(amount), 500, [amount]); |
88 | 80 | const parsedAmount = useParsedAmount(uncommify(debouncedAmount) as `${number}`); |
89 | 81 |
|
90 | 82 | const { id } = useParams(); |
91 | | - const { address } = useAccount(); |
92 | | - const { data: balance } = useReadPnkBalanceOf({ |
93 | | - query: { |
94 | | - enabled: !isUndefined(address), |
95 | | - refetchInterval: REFETCH_INTERVAL, |
96 | | - }, |
97 | | - args: [address ?? "0x"], |
98 | | - }); |
| 83 | + const { balance, jurorBalance } = usePnkData({ courtId: id }); |
| 84 | + |
99 | 85 | const parsedBalance = formatPNK(balance ?? 0n, 0, true); |
100 | | - const { data: jurorBalance } = useReadSortitionModuleGetJurorBalance({ |
101 | | - query: { |
102 | | - enabled: !isUndefined(address), |
103 | | - refetchInterval: REFETCH_INTERVAL, |
104 | | - }, |
105 | | - args: [address ?? "0x", BigInt(id ?? "0")], |
106 | | - }); |
| 86 | + |
107 | 87 | const parsedStake = formatPNK(jurorBalance?.[2] ?? 0n, 0, true); |
108 | 88 | const isStaking = useMemo(() => action === ActionType.stake, [action]); |
109 | 89 |
|
@@ -147,12 +127,10 @@ const InputDisplay: React.FC<IInputDisplay> = ({ |
147 | 127 | <EnsureChainContainer> |
148 | 128 | <StakeWithdrawButton |
149 | 129 | {...{ |
| 130 | + amount, |
150 | 131 | parsedAmount, |
151 | 132 | action, |
152 | 133 | setAmount, |
153 | | - isSending, |
154 | | - setIsSending, |
155 | | - setIsPopupOpen, |
156 | 134 | setErrorMsg, |
157 | 135 | }} |
158 | 136 | /> |
|
0 commit comments