Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions app/deployments/[id]/DeploymentDetailClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
import { DEPLOYMENTS } from "@/lib/deployments-data";
import type { Deployment } from "@/lib/deployments-data";
import { useTranslations } from "@/lib/i18n";
import { parseEther, formatEther } from "viem";
import { parseEther, formatEther, parseGwei } from "viem";
import {
useReadContract,
useWriteContract,
useWaitForTransactionReceipt,
useChainId,
useAccount,
} from "wagmi";
import { tectonicAbi } from "@/lib/abi/Tectonic";

// Mappings for different networks
const CONTRACT_ADDRESSES: Record<number, `0x${string}`> = {
31337: "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512", // Anvil
11155111: "0x016eed9c27848d9ba152fe2d45dd2949f3f4780d", // Sepolia
80002: "0x016eed9c27848d9ba152fe2d45dd2949f3f4780d", // Amoy (Placeholder)
80002: "0xfD14ac4867954173552dFB72be1321Ce1AC35834", // Amoy
61: "0x016eed9c27848d9ba152fe2d45dd2949f3f4780d", // Ethereum Classic (Placeholder)
8453: "0x016eed9c27848d9ba152fe2d45dd2949f3f4780d", // Base Mainnet (Placeholder)
};
const FALLBACK_ADDRESS = "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512";

Check warning on line 30 in app/deployments/[id]/DeploymentDetailClient.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'FALLBACK_ADDRESS' is assigned a value but never used

function getContractAddress(chainId?: number): `0x${string}` | undefined {
if (!chainId) return undefined;
Expand Down Expand Up @@ -88,41 +89,54 @@
estimateNum = estimateNum * (1 - feePct);

// Wagmi hooks
const { data: hash, writeContract, isPending } = useWriteContract();
const { isLoading: isConfirming, isSuccess } = useWaitForTransactionReceipt({ hash });
const { address: userAddress } = useAccount();
const { data: hash, writeContract, isPending, error: writeError } = useWriteContract();
const { isLoading: isConfirming, isSuccess, error: receiptError } = useWaitForTransactionReceipt({ hash });
const currentChainId = useChainId();

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!amount || isNaN(valNum) || valNum <= 0 || !contractAddress) return;
if (!amount || isNaN(valNum) || valNum <= 0 || !contractAddress || !userAddress) return;
const weiAmount = parseEther(amount);

const txOptions = currentChainId === 80002 ? {
maxPriorityFeePerGas: parseGwei("30"),
maxFeePerGas: parseGwei("30")
} : {};

if (isMint && !isEquity) {
writeContract({
address: contractAddress,
abi: tectonicAbi,
functionName: "mint",
args: [userAddress],
value: weiAmount,
...txOptions
});
} else if (isMint && isEquity) {
writeContract({
address: contractAddress,
abi: tectonicAbi,
functionName: "mintEquityCoins",
args: [userAddress],
value: weiAmount,
...txOptions
});
} else if (!isMint && !isEquity) {
writeContract({
address: contractAddress,
abi: tectonicAbi,
functionName: "redeem",
args: [weiAmount],
args: [weiAmount, userAddress],
...txOptions
});
} else if (!isMint && isEquity) {
writeContract({
address: contractAddress,
abi: tectonicAbi,
functionName: "redeemEquityCoins",
args: [weiAmount],
args: [weiAmount, userAddress],
...txOptions
});
}
};
Expand Down Expand Up @@ -201,6 +215,11 @@
{t("transactionConfirmed", { defaultValue: "Transaction confirmed!" })}
</div>
)}
{(writeError || receiptError) && (
<div className="mt-2 text-center text-xs font-bold text-red-600 bg-red-50 py-2 px-3 rounded-lg border border-red-200 break-words">
{writeError?.message || receiptError?.message}
</div>
)}
</form>
);
}
Expand Down
11 changes: 10 additions & 1 deletion config/wagmi.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { getDefaultConfig } from '@rainbow-me/rainbowkit';
import { classic, sepolia, hardhat, polygonAmoy, base } from 'wagmi/chains';

import { http } from 'wagmi';

export const config = getDefaultConfig({
appName: 'Tectonic-EVM-WebUI',
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID || 'c4a4f8d9b1dbbb3d5006b9ef2db5c4a7', // Fallback to public demo ID without localhost restrictions
projectId: process.env.NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID || 'b56e18d47c72ab683b10814fe9495694', // Fallback to public demo ID without localhost restrictions
chains: [classic, base, sepolia, polygonAmoy, hardhat],
transports: {
[classic.id]: http(),
[base.id]: http(),
[sepolia.id]: http(),
[polygonAmoy.id]: http('https://polygon-amoy.drpc.org'),
[hardhat.id]: http('http://127.0.0.1:8545'),
},
ssr: true,
});
14 changes: 10 additions & 4 deletions lib/abi/Tectonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,34 @@ export const tectonicAbi = [

// WRITES
{
inputs: [],
inputs: [{ internalType: "address", name: "receiver", type: "address" }],
name: "mint",
outputs: [],
stateMutability: "payable",
type: "function",
},
{
inputs: [],
inputs: [{ internalType: "address", name: "receiver", type: "address" }],
name: "mintEquityCoins",
outputs: [],
stateMutability: "payable",
type: "function",
},
{
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
inputs: [
{ internalType: "uint256", name: "amount", type: "uint256" },
{ internalType: "address", name: "receiver", type: "address" }
],
name: "redeem",
outputs: [],
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
inputs: [
{ internalType: "uint256", name: "amount", type: "uint256" },
{ internalType: "address", name: "receiver", type: "address" }
],
name: "redeemEquityCoins",
outputs: [],
stateMutability: "nonpayable",
Expand Down
Loading