Skip to content

Commit

Permalink
Fix mixed up claiming address (#168)
Browse files Browse the repository at this point in the history
* Use `beneficiary` field to send along with withdraw request

* Tweak table list styling
  • Loading branch information
ken-futureverse authored Apr 20, 2022
1 parent 7ef9bd0 commit 231df2f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 46 deletions.
127 changes: 82 additions & 45 deletions components/BridgeUnclaimedWithdrawals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,7 @@ import {
import { useHistoricalWithdrawRequest } from "@/hooks";
import { getMinutesAndSeconds } from "@/utils";
import { useBridge } from "@/providers/BridgeProvider";

const ExpiryCell: VFC<{ expiryRaw: number; expiryString: string }> = ({
expiryRaw,
expiryString,
}) => {
const [expiry, setExpiry] = useState<string>("");
const [seconds, setSeconds] = useState<number>(0);

useEffect(() => {
if (expiryRaw * 1000 > Date.now() + 600000) return setExpiry(expiryString);

const intervalId = setInterval(() => {
setSeconds((seconds) => seconds + 1);
setExpiry(getMinutesAndSeconds(expiryRaw - seconds));
}, 1000);

return () => clearInterval(intervalId);
}, [expiryString, expiryRaw, seconds, setExpiry]);

return (
<TableCell css={[styles.column, styles.number]}>
{expiry && expiry}
{!expiry && <LinearProgress css={[styles.expiryProgress]} />}
</TableCell>
);
};
import { WithdrawClaim } from "@/types";

const BridgeUnclaimedWithdrawals: VFC = () => {
const { unclaimedWithdrawals } = useBridge();
Expand All @@ -52,17 +27,16 @@ const BridgeUnclaimedWithdrawals: VFC = () => {
<TableContainer css={styles.container}>
<Table>
<TableHead>
<TableRow>
<TableRow css={styles.rowHead}>
<TableCell css={styles.column}>ID</TableCell>
<TableCell css={styles.column}>Value</TableCell>
<TableCell css={styles.column}>Expiry</TableCell>
<TableCell css={styles.column}>Entry</TableCell>
<TableCell css={styles.column}>Action</TableCell>
</TableRow>
</TableHead>
<TableBody>
{!someUnclaimed && (
<TableRow css={[styles.row, styles.rowEmpty]}>
<TableCell colSpan={4}>
<TableCell colSpan={3}>
No unclaimed withdrawals &nbsp;&#127881;
</TableCell>
</TableRow>
Expand All @@ -77,23 +51,15 @@ const BridgeUnclaimedWithdrawals: VFC = () => {
<TableCell css={[styles.column, styles.number]}>
{unclaimed.eventProofId}
</TableCell>
{/* Value */}
<TableCell css={[styles.column, styles.number]}>
{unclaimed.transferAmount.toInput()}{" "}
{unclaimed.transferAsset.symbol}
</TableCell>
{/* Expiry */}
<ExpiryCell
expiryRaw={unclaimed.expiryRaw}
expiryString={unclaimed.expiry}
/>
<EntryCell withdrawClaim={unclaimed} />
{/* Action */}
<TableCell css={styles.column}>
<button
onClick={() => processHistoricalRequest(unclaimed)}
type="button"
>
claim
Claim
</button>
</TableCell>
</TableRow>
Expand All @@ -106,18 +72,81 @@ const BridgeUnclaimedWithdrawals: VFC = () => {

export default BridgeUnclaimedWithdrawals;

const EntryCell: VFC<{ withdrawClaim: WithdrawClaim }> = ({
withdrawClaim,
}) => {
const [expiry, setExpiry] = useState<string>("");
const [seconds, setSeconds] = useState<number>(0);
const {
expiryRaw,
expiry: expiryString,
transferAmount,
transferAsset,
beneficiary,
} = withdrawClaim;

useEffect(() => {
if (expiryRaw * 1000 > Date.now() + 600000) return setExpiry(expiryString);

const intervalId = setInterval(() => {
setSeconds((seconds) => seconds + 1);
setExpiry(getMinutesAndSeconds(expiryRaw - seconds));
}, 1000);

return () => clearInterval(intervalId);
}, [expiryString, expiryRaw, seconds, setExpiry]);

const truncatedAddress = `${beneficiary.slice(0, 5)}...${beneficiary.slice(
-4
)}`;

return (
<TableCell css={[styles.column, styles.columnMain]}>
<div>
<strong>Transfer:</strong>{" "}
<em>
<span>{transferAmount.toInput()}</span>{" "}
<span>{transferAsset.symbol}</span>
</em>
</div>
<div>
<strong>Address:</strong> <em>{truncatedAddress}</em>
</div>

<div>
<strong>Expiry:</strong>{" "}
<>
{!!expiry && expiry}
{!expiry && <LinearProgress css={[styles.expiryProgress]} />}
</>
</div>
</TableCell>
);
};

const styles = {
container: css`
margin-top: 0.2em;
border: 1px solid rgba(0, 0, 0, 0.1);
container: ({ palette }: Theme) => css`
border: 1px solid ${palette.text.secondary};
border-radius: 4px;
overflow-y: auto;
white-space: nowrap;
max-height: 15em;
`,

column: css`
column: ({ palette }: Theme) => css`
text-align: center;
border-bottom: 1px solid ${palette.grey["200"]};
`,

columnMain: css`
text-align: left;
em {
font-family: "Roboto Mono", monospace;
display: inline;
letter-spacing: -0.025em;
font-style: normal;
}
`,

number: css`
Expand All @@ -126,8 +155,9 @@ const styles = {

row: ({ palette, transitions }: Theme) => css`
transition: background-color ${transitions.duration.shortest}ms;
&:nth-of-type(even) {
background-color: rgba(0, 0, 0, 0.03);
background-color: rgba(0, 0, 0, 0.01);
}
&:last-of-type {
Expand Down Expand Up @@ -170,6 +200,13 @@ const styles = {
}
`,

rowHead: ({ palette }: Theme) => css`
background-color: ${palette.grey["200"]};
th {
padding: 0.5em;
}
`,

expiryProgress: css`
margin: 0 auto;
width: 25px;
Expand Down
2 changes: 1 addition & 1 deletion hooks/useHistoricalWithdrawRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function useHistoricalWithdrawRequest(): (
eventProof,
unclaimed.transferAmount,
unclaimed.transferAsset,
transferMetaMaskAddress,
unclaimed.beneficiary,
metaMaskWallet.getSigner(),
eventProof.blockHash
)
Expand Down
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ export interface WithdrawClaim {
eventProofId: number;
transferAsset: BridgedEthereumToken;
transferAmount: Balance;
beneficiary: string;
}
1 change: 1 addition & 0 deletions utils/fetchUnclaimedWithdrawals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default async function fetchUnclaimedWithdrawals(
eventProofId: Number(withdrawal.proofId),
transferAsset: transferAsset as BridgedEthereumToken,
transferAmount,
beneficiary: withdrawal.beneficiary,
};
})
);
Expand Down

0 comments on commit 231df2f

Please sign in to comment.