added rough mainnet implementation and added backup contact for email

This commit is contained in:
Siavash Sameni
2025-08-28 14:07:09 +04:00
parent 29c346e868
commit f60e4ca3a5
6 changed files with 86 additions and 18 deletions

View File

@@ -2,7 +2,7 @@
import { useEffect, useMemo, useState } from 'react';
import { useAccount, useChainId, useReadContract, useReadContracts, useSwitchChain, usePublicClient, useWriteContract, useSendTransaction } from 'wagmi';
import { base, arbitrum } from 'wagmi/chains';
import { base, arbitrum, mainnet } from 'wagmi/chains';
import { Abi, parseUnits } from 'viem';
import debtAbi from '@/ABIs/mortgagefiusdccbbtcupgraded.json';
import Link from 'next/link';
@@ -21,6 +21,8 @@ const erc721Abi = [
{ type: 'function', name: 'tokenOfOwnerByIndex', stateMutability: 'view', inputs: [{ name: 'owner', type: 'address' }, { name: 'index', type: 'uint256' }], outputs: [{ type: 'uint256' }] },
] as const satisfies Abi;
const ENABLE_MAINNET = process.env.NEXT_PUBLIC_ENABLE_MAINNET === 'true';
const DEFAULTS = {
[base.id]: {
nft: '0xcc9a350c5b1e1c9ecd23d376e6618cdfd6bbbdbe',
@@ -30,10 +32,17 @@ const DEFAULTS = {
nft: '0xedE6F5F8A9D6B90b1392Dcc9E7FD8A5B0192Bfe1',
debt: '0x9Be2Cf73E62DD3b5dF4334D9A36888394822A33F',
},
...(ENABLE_MAINNET ? {
[mainnet.id]: {
// Dummy placeholders for future USDC-WETH mainnet vault
nft: '0x0000000000000000000000000000000000000001',
debt: '0x0000000000000000000000000000000000000002',
},
} : {}),
} as const;
// Presets per chain (selectable pairs)
const PRESETS: Record<number, { key: string; label: string; nft: string; debt: string }[]> = {
const PRESETS: Partial<Record<number, { key: string; label: string; nft: string; debt: string }[]>> = {
[base.id]: [
{ key: 'cbBTC-USDC', label: 'cbBTC-USDC', nft: '0xcc9a350c5b1e1c9ecd23d376e6618cdfd6bbbdbe', debt: '0xe93131620945a1273b48f57f453983d270b62dc7' },
{ key: 'WETH-USDC', label: 'WETH-USDC', nft: '0xab825f45e9e5d2459fb7a1527a8d0ca082c582f4', debt: '0x1be87d273d47c3832ab7853812e9a995a4de9eea' },
@@ -41,6 +50,11 @@ const PRESETS: Record<number, { key: string; label: string; nft: string; debt: s
[arbitrum.id]: [
{ key: 'USDTO-WBTC', label: 'USDTO-WBTC', nft: '0xedE6F5F8A9D6B90b1392Dcc9E7FD8A5B0192Bfe1', debt: '0x9Be2Cf73E62DD3b5dF4334D9A36888394822A33F' },
],
...(ENABLE_MAINNET ? {
[mainnet.id]: [
{ key: 'USDC-WETH', label: 'USDC-WETH (mainnet dummy)', nft: '0x0000000000000000000000000000000000000001', debt: '0x0000000000000000000000000000000000000002' },
],
} : {}),
};
export default function DappPage() {
@@ -158,7 +172,9 @@ export default function DappPage() {
if (age > 600) return; // ignore stale links >10min
const net = String(parsed.network || '').toUpperCase();
const presetIdx = Math.max(1, Number(parsed.preset || 1));
const nextChainId = net === 'BASE' ? base.id : ((net === 'ARBITRUM' || net === 'ARB') ? arbitrum.id : selectedChainId);
const nextChainId = net === 'BASE' ? base.id
: ((net === 'ARBITRUM' || net === 'ARB') ? arbitrum.id
: (ENABLE_MAINNET && net === 'MAINNET' ? mainnet.id : selectedChainId));
if (nextChainId !== selectedChainId) {
setSelectedChainId(nextChainId);
loadChainDefaults(nextChainId);
@@ -720,7 +736,7 @@ export default function DappPage() {
const debtRemaining = (row as any)?.debtAtThisSize as bigint | undefined;
const origin = (typeof window !== 'undefined' && window.location?.origin) ? window.location.origin : 'https://markets.mortgagefi.app';
const dappUrl = `${origin}/dapp`;
const networkSlug = selectedChainId === base.id ? 'BASE' : (selectedChainId === arbitrum.id ? 'ARBITRUM' : 'UNKNOWN');
const networkSlug = selectedChainId === base.id ? 'BASE' : (selectedChainId === arbitrum.id ? 'ARBITRUM' : (selectedChainId === mainnet.id ? 'MAINNET' : 'UNKNOWN'));
const presetIdx = Math.max(0, (PRESETS[selectedChainId]?.findIndex(p => p.key === presetKey) ?? 0)) + 1; // 1-based
const positionUrl = `${origin}/dapp/position/${networkSlug}/${presetIdx}/${row.tokenId.toString()}`;
const humanLeft = human(offset);