Skip to content

Commit

Permalink
add Ethereum mainnet token contract addresses and balances
Browse files Browse the repository at this point in the history
  • Loading branch information
alecananian committed Dec 18, 2024
1 parent 09a40fd commit 767178d
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 57 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-terms-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@treasure-dev/tdk-react": patch
---

Added CRV to View Funds section of connected account modal
5 changes: 5 additions & 0 deletions .changeset/orange-snakes-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@treasure-dev/tdk-core": patch
---

Added Ethereum mainnet token contract addresses
6 changes: 6 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
arbitrumSepolia,
base,
baseSepolia,
mainnet,
sepolia,
} from "thirdweb/chains";

Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type Contract =
// Tokens
| "MAGIC"
| "VEE"
| "CRV"
// Bridgeworld
| "Middleman"
| "BalancerCrystals"
Expand Down
89 changes: 89 additions & 0 deletions packages/react/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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,
},
],
};
68 changes: 11 additions & 57 deletions packages/react/src/hooks/useConnect.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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,
Expand All @@ -91,7 +52,7 @@ export const useConnect = (props?: Props) => {
connectModalSize,
accountModalProps,
...connectModalProps
} = props ?? {};
} = options ?? {};

const chains =
supportedChainIds && supportedChainIds.length > 0
Expand Down Expand Up @@ -136,7 +97,7 @@ export const useConnect = (props?: Props) => {
openWalletDetailsModal({
client,
chains,
theme: THEME,
theme: CONNECT_MODAL_THEME,
locale: getLocaleId(),
connectOptions: {
chain,
Expand Down Expand Up @@ -169,14 +130,7 @@ export const useConnect = (props?: Props) => {
},
{} as Record<number, string>,
),
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();
Expand Down

0 comments on commit 767178d

Please sign in to comment.