Skip to content

Commit

Permalink
fix: readd MintTo and ChangeSinkAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
williamluke4 committed Oct 14, 2024
1 parent 0f382dc commit 2b5801a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
30 changes: 27 additions & 3 deletions src/components/voucher/voucher-contract-functions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArchiveIcon, SendIcon, WalletIcon } from "lucide-react";
import { ArchiveIcon, PlusIcon, SendIcon, WalletIcon } from "lucide-react";
import { useAccount, useWalletClient } from "wagmi";
import { useIsWriter } from "~/hooks/useIsWriter";
import { cn } from "~/lib/utils";
Expand All @@ -9,6 +9,7 @@ import { useIsMounted } from "~/hooks/useIsMounted";
import { useIsOwner } from "~/hooks/useIsOwner";
import { type RouterOutputs } from "~/utils/api";
import ChangeSinkAddressDialog from "../dialogs/change-sink-dialog";
import MintToDialog from "../dialogs/mint-to-dialog";
import { useVoucherDetails } from "../pools/hooks";
import { Button } from "../ui/button";

Expand Down Expand Up @@ -44,7 +45,7 @@ export function ManageVoucherFunctions({
/>
{(isWriter || isOwner) && (
<ChangeSinkAddressDialog
voucher_address={voucher_address}
voucher_address={voucher_address as `0x${string}`}
button={
<Button className="mb-2 w-25" variant={"outline"}>
<ArchiveIcon className="mr-2 stroke-slate-700 h-3" />
Expand All @@ -65,6 +66,8 @@ export function BasicVoucherFunctions({
const account = useAccount();
const mounted = useIsMounted();
const wallet = useWalletClient();
const isWriter = useIsWriter(voucher_address);
const isOwner = useIsOwner(voucher_address);
const { data: details } = useVoucherDetails(voucher_address as `0x${string}`);
function watchVoucher() {
if (details?.symbol && details?.decimals) {
Expand Down Expand Up @@ -107,7 +110,28 @@ export function BasicVoucherFunctions({
</Button>
}
/>

{(isWriter || isOwner) && (
<MintToDialog
voucher_address={voucher_address as `0x${string}`}
button={
<Button className="mb-2 w-25" variant={"outline"}>
<PlusIcon className="mr-2 stroke-slate-700 h-3" />
Mint
</Button>
}
/>
)}
{(isWriter || isOwner) && (
<ChangeSinkAddressDialog
voucher_address={voucher_address as `0x${string}`}
button={
<Button className="mb-2 w-25" variant={"outline"}>
<ArchiveIcon className="mr-2 stroke-slate-700 h-3" />
Change Fund
</Button>
}
/>
)}
{account?.connector?.id &&
["io.metamask"].includes(account?.connector?.id) && (
<Button
Expand Down
35 changes: 4 additions & 31 deletions src/pages/vouchers/[address]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { useToken } from "wagmi";
import { BreadcrumbResponsive } from "~/components/breadcrumbs";
import StatisticsCard from "~/components/cards/statistics-card";
import { LineChart } from "~/components/charts/line-chart";
import { ContractFunctions } from "~/components/contract/ContractFunctions";
import { Icons } from "~/components/icons";
import { ContentContainer } from "~/components/layout/content-container";
import { getVoucherDetails } from "~/components/pools/contract-functions";
Expand All @@ -31,13 +30,8 @@ import { Avatar, AvatarFallback, AvatarImage } from "~/components/ui/avatar";
import { CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs";
import UpdateVoucherForm from "~/components/voucher/forms/update-voucher-form";
import {
BasicVoucherFunctions,
ManageVoucherFunctions,
} from "~/components/voucher/voucher-contract-functions";
import { BasicVoucherFunctions } from "~/components/voucher/voucher-contract-functions";
import { VoucherHoldersTable } from "~/components/voucher/voucher-holders-table";
import { abi as DMRAbi } from "~/contracts/erc20-demurrage-token/contract";
import { abi as GiftableAbi } from "~/contracts/erc20-giftable-token/contract";
import { env } from "~/env";
import { Authorization } from "~/hooks/useAuth";
import { useIsMounted } from "~/hooks/useIsMounted";
Expand Down Expand Up @@ -143,14 +137,6 @@ const VoucherPage = ({
},
});

const getAbiByVoucherType = (voucherType: string | undefined) => {
if (voucherType === "GIFTABLE") {
return GiftableAbi;
} else if (voucherType === "DEMURRAGE") {
return DMRAbi;
}
return undefined;
};
const getVoucherTypeName = (voucherType: string | undefined) => {
if (voucherType === "GIFTABLE") {
return "No Expiration";
Expand All @@ -159,7 +145,6 @@ const VoucherPage = ({
}
return "Unknown";
};
const abi = getAbiByVoucherType(voucher?.voucher_type);

return (
<ContentContainer title={details?.name ?? "Voucher Details"}>
Expand Down Expand Up @@ -217,8 +202,8 @@ const VoucherPage = ({
{voucher?.voucher_value && voucher?.voucher_uoa && (
<div className="mt-4 inline-block px-4 py-2 bg-secondary rounded-md">
<p className="text-sm font-semibold text-secondary-foreground">
1 {details.symbol} = {voucher.voucher_value} {voucher.voucher_uoa} of
Products
1 {details.symbol} = {voucher.voucher_value}{" "}
{voucher.voucher_uoa} of Products
</p>
</div>
)}
Expand All @@ -236,13 +221,6 @@ const VoucherPage = ({
<TabsTrigger value="data">Data</TabsTrigger>
<TabsTrigger value="transactions">Transactions</TabsTrigger>
<TabsTrigger value="holders">Holders</TabsTrigger>
<Authorization
resource={"Contract"}
action="UPDATE"
isOwner={isOwner}
>
<TabsTrigger value="manage">Manage</TabsTrigger>
</Authorization>
<Authorization
resource={"Vouchers"}
action="UPDATE"
Expand All @@ -254,12 +232,7 @@ const VoucherPage = ({
</TabsTrigger>
</Authorization>
</TabsList>
<TabsContent value="manage">
<ManageVoucherFunctions voucher_address={voucher_address} />
{isMounted && abi && (
<ContractFunctions abi={abi} address={voucher_address} />
)}
</TabsContent>

<TabsContent value="home">
<div className="grid grid-cols-1 lg:grid-cols-3 gap-8">
<div className="lg:col-span-2 space-y-8">
Expand Down

0 comments on commit 2b5801a

Please sign in to comment.