From adb3b9389b960d9ab8ace649ebf7ef52aad90d6a Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Mon, 20 Nov 2023 11:10:28 -0500 Subject: [PATCH 1/3] improve: closed handler --- src/views/Bridge/components/BridgeForm.tsx | 2 +- src/views/Bridge/components/ReferralCTA.tsx | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/views/Bridge/components/BridgeForm.tsx b/src/views/Bridge/components/BridgeForm.tsx index edd49f2c3..31316ed39 100644 --- a/src/views/Bridge/components/BridgeForm.tsx +++ b/src/views/Bridge/components/BridgeForm.tsx @@ -135,7 +135,7 @@ const BridgeForm = ({ - {isConnected && } + { const { referralLinkWithProtocol } = useReferralLink(); + const { isConnected, connect } = useConnection(); const handleCopy = useCallback(() => { - if (referralLinkWithProtocol) { + if (!isConnected) { + connect({ + trackSection: "bridgeForm", + }); + } else if (referralLinkWithProtocol) { copy(referralLinkWithProtocol); } - }, [referralLinkWithProtocol]); + }, [connect, isConnected, referralLinkWithProtocol]); return ( @@ -35,10 +41,10 @@ const ReferralCTA = () => { backgroundColor="black-700" textColor="aqua" > - Copy link + {isConnected ? "Copy link" : "Connect"} - Copy + {isConnected ? "copy" : "Connect"} ); From d2fbc010c1767ce2c03b269a6748db7d30067d27 Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Mon, 20 Nov 2023 11:14:30 -0500 Subject: [PATCH 2/3] improve: modify rewards program --- src/hooks/index.ts | 2 ++ src/hooks/useRewardToken.ts | 4 ++-- src/utils/constants.ts | 40 +++++++++++++++++++++++++++++++------ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 2f46f8bf7..db639a6fa 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -18,3 +18,5 @@ export * from "./useRouteTrace"; export * from "./useWalletTrace"; export * from "./useQueue"; export * from "./useAmplitude"; +export * from "./useReferralSummary"; +export * from "./useSimplifiedReferralSummary"; diff --git a/src/hooks/useRewardToken.ts b/src/hooks/useRewardToken.ts index fd0d7f59f..aecb88e96 100644 --- a/src/hooks/useRewardToken.ts +++ b/src/hooks/useRewardToken.ts @@ -1,13 +1,13 @@ import { useConnection } from "hooks"; import { useMemo } from "react"; import { useQuery } from "react-query"; -import { getToken, rebateTokensAvailable } from "utils"; +import { getToken, rewardProgramsAvailable } from "utils"; import useReferrer from "./useReferrer"; import { useSimplifiedReferralSummary } from "./useSimplifiedReferralSummary"; export function useRewardToken(destinationChainId: number) { const rewardToken = useMemo(() => { - if (rebateTokensAvailable.includes("OP")) { + if (rewardProgramsAvailable.includes("op-rebate")) { return getToken(destinationChainId === 10 ? "OP" : "ACX"); } return getToken("ACX"); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 018175c3f..a1fad5630 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -333,6 +333,31 @@ export const tokenList = [ ...externalLPsForStaking[hubPoolChainId], ]; +export type rewardProgramTypes = "referrals" | "op-rebate"; + +export const rewardPrograms: Record< + rewardProgramTypes, + { + programName: string; + primaryColor: keyof typeof COLORS; + url: string; + rewardTokenSymbol: string; + } +> = { + referrals: { + programName: "Across Referral Program", + primaryColor: "aqua", + url: "/rewards/referrals", + rewardTokenSymbol: "ACX", + }, + "op-rebate": { + programName: "OP Rewards Program", + primaryColor: "op-red", + url: "/rewards/op-rewards", + rewardTokenSymbol: "OP", + }, +}; + // process.env variables export const rewardsApiUrl = process.env.REACT_APP_REWARDS_API_URL || "https://api.across.to"; @@ -357,12 +382,15 @@ export const debug = Boolean(process.env.REACT_APP_DEBUG); export const isProductionBuild = process.env.NODE_ENV === "production"; export const isAmplitudeLoggingEnabled = process.env.REACT_APP_AMPLITUDE_DEBUG_LOGGING === "true"; -export const rebateTokensAvailable = String( - process.env.REACT_APP_EXTERNAL_REBATE_TOKENS_AVAILABLE || "" -) - .toUpperCase() - .split(","); - +export const rewardProgramsAvailable: (keyof typeof rewardPrograms)[] = [ + // Our referrals program is always available + "referrals", + ...( + String(process.env.REACT_APP_REBATE_PROGRAMS_AVAILABLE || "") + .toLowerCase() + .split(",") as (keyof typeof rewardPrograms)[] + ).filter((v) => v), +]; export const rewardsBannerWarning = process.env.REACT_APP_REWARDS_BANNER_WARNING; From ed661873c6c649f60eced9306481ad748e36ae64 Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Mon, 20 Nov 2023 11:19:39 -0500 Subject: [PATCH 3/3] chore: refactor imports --- src/utils/ethers.ts | 14 ++++++++++++-- src/utils/format.ts | 2 +- src/utils/transactions.ts | 14 +++++++------- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/utils/ethers.ts b/src/utils/ethers.ts index b83051e44..0519946fe 100644 --- a/src/utils/ethers.ts +++ b/src/utils/ethers.ts @@ -1,14 +1,24 @@ -import { Contract, ethers } from "ethers"; +import { Contract, ethers, providers } from "ethers"; import type { Event } from "ethers"; import { Provider } from "@ethersproject/providers"; import { Signer } from "@ethersproject/abstract-signer"; import type { TypedEvent, TypedEventFilter } from "utils/typechain"; -export { Provider, Signer, Contract, TypedEventFilter, TypedEvent, Event }; +export { + Provider, + Signer, + Contract, + TypedEventFilter, + TypedEvent, + Event, + providers, +}; export type Result = ethers.utils.Result; +export type ContractTransaction = ethers.ContractTransaction; + export interface Callable { (...args: any[]): any; } diff --git a/src/utils/format.ts b/src/utils/format.ts index d87311ab3..abefd896c 100644 --- a/src/utils/format.ts +++ b/src/utils/format.ts @@ -292,5 +292,5 @@ export function humanReadableNumber(num: number, decimals = 0): string { */ export function formatUSD(value: BigNumberish): string { const formattedString = formatUnits(value, 18); - return numeral(formattedString).format("0.00"); + return numeral(formattedString).format("0,0.00"); } diff --git a/src/utils/transactions.ts b/src/utils/transactions.ts index b7617acaa..57ac68c3f 100644 --- a/src/utils/transactions.ts +++ b/src/utils/transactions.ts @@ -1,10 +1,10 @@ -import { Contract, ContractTransaction, ethers } from "ethers"; -import { parseEther } from "ethers/lib/utils"; import { fixedPointAdjustment, gasMultiplierPerChain, hubPoolChainId, } from "./constants"; +import { Contract, ContractTransaction, Signer, providers } from "./ethers"; +import { parseUnits } from "./format"; /** * This function takes a raw transaction and a signer and returns the result of signing the transaction. @@ -13,8 +13,8 @@ import { * @returns The raw transaction signed by the given `signer`. */ export function signTransaction( - rawTx: ethers.providers.TransactionRequest, - signer: ethers.Signer + rawTx: providers.TransactionRequest, + signer: Signer ): Promise { //TODO: here is where we might do safety checks on the transaction return signer.signTransaction(rawTx); @@ -22,8 +22,8 @@ export function signTransaction( export async function sendSignedTransaction( signedTx: string, - provider: ethers.providers.Provider -): Promise { + provider: providers.Provider +): Promise { const tx = await provider.sendTransaction(signedTx); return tx; } @@ -45,7 +45,7 @@ export async function getPaddedGasEstimation( const gasEstimation = await contract.estimateGas[method](...args); // Factor in the padding const gasToRecommend = gasEstimation - .mul(parseEther(String(gasMultiplier))) + .mul(parseUnits(String(gasMultiplier), 18)) .div(fixedPointAdjustment); return gasToRecommend; }