From 767178d3dd872c9ccd2023e83d6ed7305f54f911 Mon Sep 17 00:00:00 2001 From: Alec Ananian <1013230+alecananian@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:10:50 -0800 Subject: [PATCH] add Ethereum mainnet token contract addresses and balances --- .changeset/honest-terms-invite.md | 5 ++ .changeset/orange-snakes-knock.md | 5 ++ packages/core/src/constants.ts | 6 ++ packages/core/src/types.ts | 1 + packages/react/src/constants.ts | 89 +++++++++++++++++++++++++ packages/react/src/hooks/useConnect.tsx | 68 +++---------------- 6 files changed, 117 insertions(+), 57 deletions(-) create mode 100644 .changeset/honest-terms-invite.md create mode 100644 .changeset/orange-snakes-knock.md create mode 100644 packages/react/src/constants.ts diff --git a/.changeset/honest-terms-invite.md b/.changeset/honest-terms-invite.md new file mode 100644 index 00000000..99017415 --- /dev/null +++ b/.changeset/honest-terms-invite.md @@ -0,0 +1,5 @@ +--- +"@treasure-dev/tdk-react": patch +--- + +Added CRV to View Funds section of connected account modal diff --git a/.changeset/orange-snakes-knock.md b/.changeset/orange-snakes-knock.md new file mode 100644 index 00000000..009048e5 --- /dev/null +++ b/.changeset/orange-snakes-knock.md @@ -0,0 +1,5 @@ +--- +"@treasure-dev/tdk-core": patch +--- + +Added Ethereum mainnet token contract addresses diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index afebb2d3..2a3eda13 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -4,6 +4,7 @@ import { arbitrumSepolia, base, baseSepolia, + mainnet, sepolia, } from "thirdweb/chains"; @@ -142,6 +143,11 @@ export const CONTRACT_ADDRESSES: Record< TreasureConduit: "0x74c4ed7e3bcbdf8e32b56d4d11d2cbd34ad4dc0b", TreasureBanners: "0x023083def4855918dea65f1dea351fcdabb1e073", }, + [mainnet.id]: { + // Tokens + MAGIC: "0xb0c7a3ba49c7a6eaba6cd4a96c55a1391070ac9a", + CRV: "0xD533a949740bb3306d119CC777fa900bA034cd52", + }, [sepolia.id]: { // Tokens MAGIC: "0x013cb2854daad8203c6686682f5d876e5d3de4a2", diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 227a0a86..ab08f155 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -46,6 +46,7 @@ export type Contract = // Tokens | "MAGIC" | "VEE" + | "CRV" // Bridgeworld | "Middleman" | "BalancerCrystals" diff --git a/packages/react/src/constants.ts b/packages/react/src/constants.ts new file mode 100644 index 00000000..53b7a46e --- /dev/null +++ b/packages/react/src/constants.ts @@ -0,0 +1,89 @@ +import { getContractAddresses } from "@treasure-dev/tdk-core"; +import { arbitrum, arbitrumSepolia, mainnet, sepolia } from "thirdweb/chains"; +import { type SupportedTokens, darkTheme } from "thirdweb/react"; + +export const CONNECT_MODAL_THEME = darkTheme({ + colors: { + modalBg: "#131D2E", + modalOverlayBg: "rgba(0, 0, 0, 0.3)", + borderColor: "#1F2D45", + separatorLine: "#19253A", + danger: "#DC2626", + success: "#4AE387", + accentText: "#586C8D", + accentButtonBg: "#DC2626", + accentButtonText: "#FFFCF5", + primaryText: "#FFFCF5", + primaryButtonText: "#131418", + secondaryText: "#B7BABE", + secondaryButtonBg: "#283852", + secondaryIconColor: "#B7BABE", + secondaryIconHoverColor: "#FFFCF5", + secondaryIconHoverBg: "transparent", + tertiaryBg: "#19253A", + connectedButtonBg: "#131D2E", + connectedButtonBgHover: "#283852", + }, +}); + +const MAGIC_TOKEN = { + symbol: "MAGIC", + name: "MAGIC", + icon: "https://images.treasure.lol/tdk/login/magic.png", +} as const; + +const VEE_TOKEN = { + symbol: "VEE", + name: "VEE", + icon: "https://images.treasure.lol/tdk/login/vee.png", +}; + +const arbitrumContracts = getContractAddresses(arbitrum.id); +const arbitrumSepoliaContracts = getContractAddresses(arbitrumSepolia.id); +const mainnetContracts = getContractAddresses(mainnet.id); +const sepoliaContracts = getContractAddresses(sepolia.id); + +export const CONNECT_MODAL_SUPPORTED_TOKENS: SupportedTokens = { + [arbitrum.id]: [ + { + ...MAGIC_TOKEN, + address: arbitrumContracts.MAGIC, + }, + { + ...VEE_TOKEN, + address: arbitrumContracts.VEE, + }, + ], + [arbitrumSepolia.id]: [ + { + ...MAGIC_TOKEN, + address: arbitrumSepoliaContracts.MAGIC, + }, + { + ...VEE_TOKEN, + address: arbitrumSepoliaContracts.VEE, + }, + ], + [mainnet.id]: [ + { + ...MAGIC_TOKEN, + address: mainnetContracts.MAGIC, + }, + { + symbol: "CRV", + name: "Curve DAO Token", + icon: "https://etherscan.io/token/images/Curvefi_32.png", + address: mainnetContracts.CRV, + }, + ], + [sepolia.id]: [ + { + ...MAGIC_TOKEN, + address: sepoliaContracts.MAGIC, + }, + { + ...VEE_TOKEN, + address: sepoliaContracts.VEE, + }, + ], +}; diff --git a/packages/react/src/hooks/useConnect.tsx b/packages/react/src/hooks/useConnect.tsx index 0d565e43..b3437602 100644 --- a/packages/react/src/hooks/useConnect.tsx +++ b/packages/react/src/hooks/useConnect.tsx @@ -1,12 +1,7 @@ +import { getContractAddress } from "@treasure-dev/tdk-core"; +import { defineChain } from "thirdweb"; import { - getContractAddress, - getContractAddresses, -} from "@treasure-dev/tdk-core"; -import { ZERO_ADDRESS, defineChain } from "thirdweb"; -import { - type SupportedTokens, type UseWalletDetailsModalOptions, - darkTheme, useActiveWallet, useWalletDetailsModal, } from "thirdweb/react"; @@ -25,52 +20,18 @@ import { EVT_TREASURECONNECT_UI_LOGIN, } from "../utils/defaultAnalytics"; +import { + CONNECT_MODAL_SUPPORTED_TOKENS, + CONNECT_MODAL_THEME, +} from "../constants"; + export type Options = ConnectModalOptions & { supportedChainIds?: number[]; connectModalSize?: ConnectModalProps["size"]; accountModalProps?: UseWalletDetailsModalOptions; }; -type Props = Options; - -const THEME = darkTheme({ - colors: { - modalBg: "#131D2E", - modalOverlayBg: "rgba(0, 0, 0, 0.3)", - borderColor: "#1F2D45", - separatorLine: "#19253A", - danger: "#DC2626", - success: "#4AE387", - accentText: "#586C8D", - accentButtonBg: "#DC2626", - accentButtonText: "#FFFCF5", - primaryText: "#FFFCF5", - primaryButtonText: "#131418", - secondaryText: "#B7BABE", - secondaryButtonBg: "#283852", - secondaryIconColor: "#B7BABE", - secondaryIconHoverColor: "#FFFCF5", - secondaryIconHoverBg: "transparent", - tertiaryBg: "#19253A", - connectedButtonBg: "#131D2E", - connectedButtonBgHover: "#283852", - }, -}); - -const SUPPORTED_TOKENS = [ - { - symbol: "MAGIC", - name: "MAGIC", - icon: "https://images.treasure.lol/tdk/login/magic.png", - }, - { - symbol: "VEE", - name: "VEE", - icon: "https://images.treasure.lol/tdk/login/vee.png", - }, -] as const; - -export const useConnect = (props?: Props) => { +export const useConnect = (options?: Options) => { const { chain, client, @@ -91,7 +52,7 @@ export const useConnect = (props?: Props) => { connectModalSize, accountModalProps, ...connectModalProps - } = props ?? {}; + } = options ?? {}; const chains = supportedChainIds && supportedChainIds.length > 0 @@ -136,7 +97,7 @@ export const useConnect = (props?: Props) => { openWalletDetailsModal({ client, chains, - theme: THEME, + theme: CONNECT_MODAL_THEME, locale: getLocaleId(), connectOptions: { chain, @@ -169,14 +130,7 @@ export const useConnect = (props?: Props) => { }, {} as Record, ), - supportedTokens: chains.reduce((acc, chain) => { - const addresses = getContractAddresses(chain.id); - acc[chain.id] = SUPPORTED_TOKENS.map((token) => ({ - ...token, - address: addresses[token.symbol] ?? ZERO_ADDRESS, - })).filter(({ address }) => address !== ZERO_ADDRESS); - return acc; - }, {} as SupportedTokens), + supportedTokens: CONNECT_MODAL_SUPPORTED_TOKENS, showTestnetFaucet: true, onDisconnect: () => { logOut();