Skip to content

Commit

Permalink
chore: wip token details
Browse files Browse the repository at this point in the history
  • Loading branch information
SGiaccobasso committed Dec 10, 2024
1 parent 8593f94 commit 135ab42
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 53 deletions.
24 changes: 24 additions & 0 deletions apps/maestro/src/config/evm-chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,32 @@ export const ALL_CHAINS: ExtendedWagmiChainConfig[] = [
default: { name: "Sui Explorer", url: "https://suiscan.xyz/testnet" },
},
},
//TODO: check if this is ok
{
id: 103,
axelarChainId: "sui",
axelarChainName: "sui",
environment: ENVIRONMENTS.testnet,
name: "Sui Testnet",
nativeCurrency: {
name: "SUI",
symbol: "SUI",
decimals: 9,
},
rpcUrls: {
default: { http: ["https://fullnode.testnet.sui.io:443"] },
public: { http: ["https://fullnode.testnet.sui.io:443"] },
},
blockExplorers: {
default: { name: "Sui Explorer", url: "https://suiscan.xyz/testnet" },
},
},
{
...sepolia,
rpcUrls: {
default: { http: ["https://rpc-sepolia.rockx.com"] },
public: { http: ["https://rpc-sepolia.rockx.com"] },
},
axelarChainId: "ethereum-sepolia",
axelarChainName: "ethereum-sepolia",
environment: ENVIRONMENTS.testnet,
Expand Down
4 changes: 2 additions & 2 deletions apps/maestro/src/lib/providers/WagmiConfigPropvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { FC, PropsWithChildren } from "react";

import { WagmiConfig } from "wagmi";
import { WagmiProvider } from "wagmi";

import { wagmiConfig } from "~/config/wagmi";

export const WagmiConfigPropvider: FC<PropsWithChildren> = ({ children }) => {
if (!wagmiConfig) {
return <>{children}</>;
}
return <WagmiConfig config={wagmiConfig}>{children}</WagmiConfig>;
return <WagmiProvider config={wagmiConfig}>{children}</WagmiProvider>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { always } from "rambda";
import { z } from "zod";

import { ExtendedWagmiChainConfig } from "~/config/evm-chains";
import { hex40Literal } from "~/lib/utils/validation";
import { publicProcedure } from "~/server/trpc";

//TODO: migrate to kv store?
Expand All @@ -20,13 +19,12 @@ export const getERC20TokenDetails = publicProcedure
.input(
z.object({
chainId: z.number().optional(),
tokenAddress: hex40Literal(),
tokenAddress: z.string(),
})
)
.query(async ({ input, ctx }) => {
try {
const { wagmiChainConfigs: chainConfigs } = ctx.configs;

const chainConfig = chainConfigs.find(
(chain) => chain.id === input.chainId
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ import { TRPCError } from "@trpc/server";
import { z } from "zod";

import { TOKEN_MANAGER_TYPES } from "~/lib/drizzle/schema/common";
import {
hex0xLiteral,
hex40Literal,
hex64Literal,
} from "~/lib/utils/validation";
import { hex0xLiteral, hex64Literal } from "~/lib/utils/validation";
import { publicProcedure } from "~/server/trpc";

const remoteTokenSchema = z.object({
id: z.string(),
tokenId: z.string(),
axelarChainId: z.string(),
tokenAddress: hex40Literal(),
tokenManagerAddress: hex40Literal().nullable(),
tokenAddress: z.string(),
tokenManagerAddress: z.string().nullable(),
tokenManagerType: z.enum(TOKEN_MANAGER_TYPES).nullable(),
deploymentMessageId: z.string(),
deploymentStatus: z.string().nullable(),
Expand All @@ -24,21 +20,21 @@ const remoteTokenSchema = z.object({

export const inputSchema = z.object({
chainId: z.number(),
tokenAddress: hex40Literal(),
tokenAddress: z.string(),
});

const outputSchema = z.object({
tokenId: z.string(),
tokenAddress: hex40Literal(),
tokenAddress: z.string(),
axelarChainId: z.string(),
tokenName: z.string(),
tokenSymbol: z.string(),
tokenDecimals: z.number(),
deploymentMessageId: z.string(),
deployerAddress: hex40Literal(),
tokenManagerAddress: hex40Literal().nullable(),
deployerAddress: z.string(),
tokenManagerAddress: z.string().nullable(),
tokenManagerType: z.enum(TOKEN_MANAGER_TYPES).nullable(),
originalMinterAddress: hex40Literal().nullable(),
originalMinterAddress: z.string().nullable(),
kind: z.string(),
createdAt: z.date().nullable(),
updatedAt: z.date().nullable(),
Expand All @@ -62,10 +58,11 @@ export const getInterchainTokenDetails = publicProcedure
.query(async ({ input, ctx }) => {
const chains = await ctx.configs.evmChains();
const configs = chains[input.chainId];

// TODO: remove this once we have sui in the chains object
const axelarChainId = input.chainId === 103 ? "sui" : configs.info.id;
const tokenRecord =
await ctx.persistence.postgres.getInterchainTokenByChainIdAndTokenAddress(
configs.info.id,
axelarChainId,
input.tokenAddress
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { z } from "zod";
import type { ExtendedWagmiChainConfig } from "~/config/wagmi";
import { InterchainToken, RemoteInterchainToken } from "~/lib/drizzle/schema";
import { TOKEN_MANAGER_TYPES } from "~/lib/drizzle/schema/common";
import { hex40Literal, hexLiteral } from "~/lib/utils/validation";
import { hexLiteral } from "~/lib/utils/validation";
import type { Context } from "~/server/context";
import { publicProcedure } from "~/server/trpc";

Expand All @@ -17,8 +17,8 @@ const tokenDetailsSchema = z.object({
axelarChainId: z.string(),
// nullable fields
tokenId: hexLiteral().nullable(),
tokenAddress: hex40Literal().nullable(),
tokenManagerAddress: hex40Literal().optional().nullable(),
tokenAddress: z.string().nullable(),
tokenManagerAddress: z.string().optional().nullable(),
tokenManagerType: z.enum(TOKEN_MANAGER_TYPES).nullable(),
isOriginToken: z.boolean().nullable(),
isRegistered: z.boolean(),
Expand All @@ -27,7 +27,7 @@ const tokenDetailsSchema = z.object({

export const inputSchema = z.object({
chainId: z.number().optional(),
tokenAddress: hex40Literal(),
tokenAddress: z.string(),
strict: z.boolean().optional(),
});

Expand Down
2 changes: 1 addition & 1 deletion apps/maestro/src/services/erc20/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useERC20TokenDetailsQuery(input: {
tokenAddress: String(input.tokenAddress),
},
{
enabled: isAddress(input.tokenAddress ?? ""),
enabled: !!input.tokenAddress,
retry: false,
staleTime: 1000 * 60 * 60 * 24, // 24 hours
refetchOnWindowFocus: false,
Expand Down
4 changes: 1 addition & 3 deletions apps/maestro/src/services/gmp/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Maybe } from "@axelarjs/utils";
import { useMemo } from "react";

import { isAddress } from "viem";

import { trpc } from "~/lib/trpc";
import { hex64 } from "~/lib/utils/validation";
import { useEVMChainConfigsQuery } from "../axelarscan/hooks";
Expand All @@ -22,7 +20,7 @@ export function useInterchainTokensQuery(input: {
strict: input.strict,
},
{
enabled: Maybe.of(input.tokenAddress).mapOr(false, isAddress),
enabled: Maybe.of(input.tokenAddress).mapOr(false, Boolean),
retry: false,
refetchOnWindowFocus: false,
}
Expand Down
16 changes: 14 additions & 2 deletions apps/maestro/src/services/interchainToken/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Maybe } from "@axelarjs/utils";

import { getFullnodeUrl } from "@mysten/sui.js/client";
import { SuiClient } from "@mysten/sui/client";
import { isAddress } from "viem";

import { trpc } from "~/lib/trpc";
Expand All @@ -14,18 +16,28 @@ export function useInterchainTokenDetailsQuery(input: {
tokenAddress: String(input.tokenAddress),
},
{
enabled: isAddress(input.tokenAddress ?? ""),
enabled: !!input.tokenAddress,
staleTime: 1000 * 60 * 60 * 24, // 24 hours
refetchOnWindowFocus: false,
}
);
}

export function useInterchainTokenBalanceForOwnerQuery(input: {
export async function useInterchainTokenBalanceForOwnerQuery(input: {
chainId?: number;
tokenAddress?: `0x${string}`;
owner?: `0x${string}`;
}) {
// TODO: WIP
if (input.chainId === 103) {
const coinType = `${input.tokenAddress}::sui::SUI`;
const client = new SuiClient({ url: getFullnodeUrl("testnet") });
const coins = await client.getCoins({
owner: input.owner as string,
coinType,
});
return coins;
}
return trpc.erc20.getERC20TokenBalanceForOwner.useQuery(
{
chainId: Number(input.chainId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import { useWeb3Modal } from "@web3modal/wagmi/react";
type Props = ButtonProps;

const ConnectWalletButton = forwardRef<HTMLButtonElement, Props>(
(props, ref) => {
(
{
$size = "sm",
$variant = "primary",
children = "Connect Wallet",
...props
},
ref
) => {
const { open } = useWeb3Modal();

return (
Expand All @@ -15,17 +23,15 @@ const ConnectWalletButton = forwardRef<HTMLButtonElement, Props>(
{...props}
onClick={open.bind(null, { view: "Connect" })}
ref={ref}
/>
$size={$size}
$variant={$variant}
>
{children}
</Button>
);
}
);

ConnectWalletButton.displayName = "ConnectWalletButton";

ConnectWalletButton.defaultProps = {
$size: "sm",
$variant: "primary",
children: "Connect Wallet",
};

export default ConnectWalletButton;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ import { ConnectModal } from "@mysten/dapp-kit";
import ConnectWalletButton from "../ConnectWalletButton/ConnectWalletButton";

const ConnectWalletModal = forwardRef<HTMLButtonElement, ButtonProps>(
({ children, ...props }, ref) => {
(
{
$size = "md",
$variant = "primary",
children = "Connect Wallet",
...props
},
ref
) => {
const [isModalOpen, setIsModalOpen] = React.useState(false);
return (
<Modal
Expand All @@ -18,7 +26,7 @@ const ConnectWalletModal = forwardRef<HTMLButtonElement, ButtonProps>(
}}
trigger={
<Button
$variant="primary"
$variant={$variant}
{...props}
ref={ref}
aria-label="Open wallet connection modal"
Expand All @@ -31,7 +39,7 @@ const ConnectWalletModal = forwardRef<HTMLButtonElement, ButtonProps>(
<span>Select Chain Type</span>
</Modal.Title>
<Modal.Body className="flex flex-col gap-4">
<ConnectWalletButton $size="md">EVM Chains</ConnectWalletButton>
<ConnectWalletButton $size={$size}>EVM Chains</ConnectWalletButton>
<ConnectModal
trigger={
<Button
Expand All @@ -51,9 +59,4 @@ const ConnectWalletModal = forwardRef<HTMLButtonElement, ButtonProps>(

ConnectWalletModal.displayName = "ConnectWalletButton";

ConnectWalletModal.defaultProps = {
$size: "md",
$variant: "primary",
children: "Connect Wallet",
};
export default ConnectWalletModal;
12 changes: 4 additions & 8 deletions apps/maestro/src/ui/pages/InterchainTokenDetailsPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Alert } from "@axelarjs/ui";
import type { FC } from "react";
import { useRouter } from "next/router";

import { isAddress } from "viem";

import { useChainFromRoute } from "~/lib/hooks";
import { getPrefilledClaimOwnershipFormLink } from "~/lib/utils/gform";
import { useERC20TokenDetailsQuery } from "~/services/erc20/hooks";
Expand Down Expand Up @@ -40,10 +37,9 @@ const InterchainTokensPage: FC = () => {
tokenAddress,
});

if (!isAddress(tokenAddress)) {
return <Alert $status="error">Invalid token address</Alert>;
}

// if (!isAddress(tokenAddress)) {
// return <Alert $status="error">Invalid token address</Alert>;
// }
const chainNames =
interchainToken?.matchingTokens
?.filter((token) => token.isRegistered)
Expand Down Expand Up @@ -78,7 +74,7 @@ const InterchainTokensPage: FC = () => {
interchainToken.chain.name,
chainNames,
"Interchain Token Service (ITS)",
destToken.tokenAddress as string,
destToken.tokenAddress,
tokenDetails.name,
tokenDetails.symbol
)
Expand Down

0 comments on commit 135ab42

Please sign in to comment.