Skip to content

Commit

Permalink
fix: Updated according to #104 reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesGuesnon committed Jul 4, 2023
1 parent de76be9 commit 226552a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
48 changes: 30 additions & 18 deletions components/FA2Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,25 @@ const FA2Transfer = ({
onTokenChange?.(newToken);
setCurrentToken(newToken);

if (autoSetField) {
const previousValue = getFieldProps(
`transfers.${proposalIndex}.values.${localIndex}`
).value;

if (
Array.isArray(previousValue) ||
(!!previousValue && "balance" in previousValue)
) {
throw new Error("Expect previous value to be formValue");
}

setFieldValue(`transfers.${proposalIndex}.values.${localIndex}`, {
...(previousValue ?? {}),
token: newToken ?? "",
tokenId: newToken?.token.tokenId ?? "",
fa2Address: newToken?.token.contract.address ?? "",
});
if (!autoSetField) return;

const previousValue = getFieldProps(
`transfers.${proposalIndex}.values.${localIndex}`
).value;

if (
Array.isArray(previousValue) ||
(!!previousValue && "balance" in previousValue)
) {
throw new Error("Expect previous value to be formValue");
}

setFieldValue(`transfers.${proposalIndex}.values.${localIndex}`, {
...(previousValue ?? {}),
token: newToken ?? "",
tokenId: newToken?.token.tokenId ?? "",
fa2Address: newToken?.token.contract.address ?? "",
});
};

const fetchTokens = useCallback(
Expand Down Expand Up @@ -345,7 +345,19 @@ const FA2TransferGroup = ({ proposalIndex, remove }: props) => {
remove={remove}
autoSetField={false}
onTokenChange={token => {
const previousValue = getFieldProps(
`transfers.${proposalIndex}.values.0`
).value;

if (
Array.isArray(previousValue) ||
(!!previousValue && "balance" in previousValue)
) {
throw new Error("Expect previous value to be formValue");
}

const data = {
...previousValue,
token,
fa2Address: token.token.contract.address,
tokenId: token.token.tokenId,
Expand Down
6 changes: 3 additions & 3 deletions components/HistoryToken.tsx → components/HistoryFaToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type props = {
};
};

const HistoryToken = ({ transferType, token }: props) => {
const HistoryFaToken = ({ transferType, token }: props) => {
const [isOpen, setIsOpen] = useState(false);

const { tzDate, tzHours, tzMinutes } = useMemo(
Expand Down Expand Up @@ -77,7 +77,7 @@ const HistoryToken = ({ transferType, token }: props) => {
{token.token.metadata.name}
</li>
<li>
<span className="text-zinc-400">Token id:</span>{" "}
<span className="text-zinc-400">Token ID:</span>{" "}
{token.token.tokenId}
</li>
<li>
Expand All @@ -90,4 +90,4 @@ const HistoryToken = ({ transferType, token }: props) => {
);
};

export default HistoryToken;
export default HistoryFaToken;
7 changes: 5 additions & 2 deletions pages/history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { validateContractAddress } from "@taquito/utils";
import BigNumber from "bignumber.js";
import { useContext, useEffect, useMemo, useState } from "react";
import Alias from "../components/Alias";
import HistoryToken from "../components/HistoryToken";
import HistoryFaToken from "../components/HistoryFaToken";
import ProposalCard from "../components/ProposalCard";
import Spinner from "../components/Spinner";
import Meta from "../components/meta";
Expand Down Expand Up @@ -247,7 +247,10 @@ const History = () => {
case TransferType.FA2:
case TransferType.FA1_2:
return (
<HistoryToken transferType={x[0]} token={x[1] as any} />
<HistoryFaToken
transferType={x[0]}
token={x[1] as any}
/>
);

case TransferType.UNKNOWN:
Expand Down

0 comments on commit 226552a

Please sign in to comment.