Skip to content

Commit

Permalink
chore: simplify payout tokens handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vacekj committed Nov 22, 2023
1 parent 12dba4d commit e6c768f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions packages/round-manager/src/context/application/usePayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "../../types/generated/typechain";
import { BigNumber, ethers } from "ethers";
import { waitForSubgraphSyncTo } from "../../features/api/subgraph";
import { PayoutTokens } from "../../features/api/payoutTokens";
import { PayoutToken } from "../../features/api/payoutTokens";

export function usePayout() {
const [contractApproveSpendStatus, setContractApproveSpendStatus] =
Expand Down Expand Up @@ -71,7 +71,7 @@ export function usePayout() {
type Args = {
address: string;
signer: ethers.Signer;
token: PayoutTokens;
token: PayoutToken;
projectId: string;
applicationIndex: number;
payoutStrategyAddress: string;
Expand Down
10 changes: 5 additions & 5 deletions packages/round-manager/src/context/round/FundContractContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { waitForSubgraphSyncTo } from "../../features/api/subgraph";

import { ProgressStatus } from "../../features/api/types";

import { PayoutTokens } from "../../features/api/payoutTokens";
import { PayoutToken } from "../../features/api/payoutTokens";

export interface FundContractState {
tokenApprovalStatus: ProgressStatus;
Expand All @@ -31,14 +31,14 @@ export interface FundContractState {
export type FundContractParams = {
roundId: string;
fundAmount: number;
payoutToken: PayoutTokens;
payoutToken: PayoutToken;
};

interface SubmitFundParams {
signer: Signer;
context: FundContractState;
roundId: string;
payoutToken: PayoutTokens;
payoutToken: PayoutToken;
fundAmount: number;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ async function _fundContract({
async function approveTokenForFunding(
signerOrProvider: Signer,
roundId: string,
token: PayoutTokens,
token: PayoutToken,
amount: number,
context: FundContractState
): Promise<void> {
Expand All @@ -204,7 +204,7 @@ async function approveTokenForFunding(
async function fund(
signerOrProvider: Signer,
roundId: string,
token: PayoutTokens,
token: PayoutToken,
fundAmount: number,
context: FundContractState
): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions packages/round-manager/src/features/api/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Signer } from "@ethersproject/abstract-signer";
import { Web3Provider } from "@ethersproject/providers";
import { graphql_fetch } from "common";
import { DirectPayoutStrategy__factory } from "../../types/generated/typechain";
import { PayoutTokens } from "./payoutTokens";
import { PayoutToken } from "./payoutTokens";
// import { verifyApplicationMetadata } from "common/src/verification";
// import { fetchProjectOwners } from "common/src/registry";

Expand Down Expand Up @@ -485,7 +485,7 @@ export const updateApplicationList = async (
export const fundRoundContract = async (
roundId: string,
signer: Signer,
payoutToken: PayoutTokens,
payoutToken: PayoutToken,
amount: BigNumber
): Promise<{ txBlockNumber: number; txHash: string }> => {
// checksum conversion
Expand Down
28 changes: 14 additions & 14 deletions packages/round-manager/src/features/api/payoutTokens.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChainId, RedstoneTokenIds } from "common";
import { ethers } from "ethers";

export type PayoutTokens = {
export type PayoutToken = {
name: string;
chainId: number;
address: string;
Expand All @@ -24,7 +24,7 @@ export const TokenNamesAndLogos = {
MATIC: "/logos/pol-logo.svg",
CVP: "/logos/power-pool.png", // PowerPool
} as const;
const MAINNET_TOKENS: PayoutTokens[] = [
const MAINNET_TOKENS: PayoutToken[] = [
{
name: "DAI",
chainId: ChainId.MAINNET,
Expand All @@ -50,7 +50,7 @@ const MAINNET_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["CVP"],
},
];
const OPTIMISM_MAINNET_TOKENS: PayoutTokens[] = [
const OPTIMISM_MAINNET_TOKENS: PayoutToken[] = [
{
name: "DAI",
chainId: ChainId.OPTIMISM_MAINNET_CHAIN_ID,
Expand All @@ -68,7 +68,7 @@ const OPTIMISM_MAINNET_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["ETH"],
},
];
const FANTOM_MAINNET_TOKENS: PayoutTokens[] = [
const FANTOM_MAINNET_TOKENS: PayoutToken[] = [
{
name: "WFTM",
chainId: ChainId.FANTOM_MAINNET_CHAIN_ID,
Expand Down Expand Up @@ -110,7 +110,7 @@ const FANTOM_MAINNET_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["DAI"], // We use DAI for the price
},
];
const FANTOM_TESTNET_TOKENS: PayoutTokens[] = [
const FANTOM_TESTNET_TOKENS: PayoutToken[] = [
{
name: "DAI",
chainId: ChainId.FANTOM_TESTNET_CHAIN_ID,
Expand All @@ -128,7 +128,7 @@ const FANTOM_TESTNET_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["FTM"],
},
];
const PGN_TESTNET_TOKENS: PayoutTokens[] = [
const PGN_TESTNET_TOKENS: PayoutToken[] = [
{
name: "TEST",
chainId: ChainId.PGN_TESTNET,
Expand All @@ -144,7 +144,7 @@ const PGN_TESTNET_TOKENS: PayoutTokens[] = [
decimal: 18,
},
];
const PGN_MAINNET_TOKENS: PayoutTokens[] = [
const PGN_MAINNET_TOKENS: PayoutToken[] = [
{
name: "ETH",
chainId: ChainId.PGN,
Expand All @@ -170,7 +170,7 @@ const PGN_MAINNET_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["DAI"],
},
];
const ARBITRUM_GOERLI_TOKENS: PayoutTokens[] = [
const ARBITRUM_GOERLI_TOKENS: PayoutToken[] = [
{
name: "ETH",
chainId: ChainId.ARBITRUM_GOERLI,
Expand All @@ -180,7 +180,7 @@ const ARBITRUM_GOERLI_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["ETH"],
},
];
const ARBITRUM_TOKENS: PayoutTokens[] = [
const ARBITRUM_TOKENS: PayoutToken[] = [
{
name: "ETH",
chainId: ChainId.ARBITRUM,
Expand All @@ -206,7 +206,7 @@ const ARBITRUM_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["ARB"],
},
];
const AVALANCHE_TOKENS: PayoutTokens[] = [
const AVALANCHE_TOKENS: PayoutToken[] = [
{
name: "AVAX",
chainId: ChainId.AVALANCHE,
Expand All @@ -224,7 +224,7 @@ const AVALANCHE_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["USDC"],
},
];
const FUJI_TOKENS: PayoutTokens[] = [
const FUJI_TOKENS: PayoutToken[] = [
{
name: "AVAX",
chainId: ChainId.FUJI,
Expand All @@ -242,7 +242,7 @@ const FUJI_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["USDC"],
},
];
const POLYGON_TOKENS: PayoutTokens[] = [
const POLYGON_TOKENS: PayoutToken[] = [
{
name: "MATIC",
chainId: ChainId.POLYGON,
Expand All @@ -260,7 +260,7 @@ const POLYGON_TOKENS: PayoutTokens[] = [
redstoneTokenId: RedstoneTokenIds["USDC"],
},
];
const POLYGON_MUMBAI_TOKENS: PayoutTokens[] = [
const POLYGON_MUMBAI_TOKENS: PayoutToken[] = [
{
name: "MATIC",
chainId: ChainId.POLYGON_MUMBAI,
Expand Down Expand Up @@ -293,7 +293,7 @@ export const payoutTokens = [
...POLYGON_MUMBAI_TOKENS,
];

export const getPayoutTokenOptions = (chainId: ChainId): PayoutTokens[] => {
export const getPayoutTokenOptions = (chainId: ChainId): PayoutToken[] => {
const tokens = payoutTokens.filter((token) => token.chainId === chainId);
return tokens.length > 0 ? tokens : MAINNET_TOKENS;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Round } from "../api/types";
import { useWallet } from "../common/Auth";
import { FormStepper } from "../common/FormStepper";
import { FormContext } from "../common/FormWizard";
import { getPayoutTokenOptions, PayoutTokens } from "../api/payoutTokens";
import { getPayoutTokenOptions, PayoutToken } from "../api/payoutTokens";
interface QuadraticFundingFormProps {
stepper: typeof FormStepper;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ export default function QuadraticFundingForm(props: QuadraticFundingFormProps) {
};

const { chain } = useWallet();
const payoutTokenOptions: PayoutTokens[] = [
const payoutTokenOptions: PayoutToken[] = [
{
name: "Choose Payout Token",
chainId: chain.id,
Expand Down Expand Up @@ -288,7 +288,7 @@ function LeftSidebar() {

function PayoutTokenButton(props: {
errors: FieldErrors<Round>;
token?: PayoutTokens;
token?: PayoutToken;
}) {
const { token } = props;
return (
Expand Down Expand Up @@ -353,7 +353,7 @@ function PayoutTokenDropdown(props: {
register: UseFormRegisterReturn<string>;
errors: FieldErrors<Round>;
control: Control<Round>;
payoutTokenOptions: PayoutTokens[];
payoutTokenOptions: PayoutToken[];
}) {
const { field } = useController({
name: "token",
Expand Down Expand Up @@ -463,7 +463,7 @@ function MatchingFundsAvailable(props: {
register: UseFormRegisterReturn<string>;
errors: FieldErrors<Round>;
token: string;
payoutTokenOptions: PayoutTokens[];
payoutTokenOptions: PayoutToken[];
}) {
// not sure why UseFormRegisterReturn only takes strings for react-hook-form
return (
Expand Down Expand Up @@ -522,7 +522,7 @@ function MatchingCap(props: {
errors: FieldErrors<Round>;
control?: Control<Round>;
token: string;
payoutTokenOptions: PayoutTokens[];
payoutTokenOptions: PayoutToken[];
}) {
const { field: matchingCapField } = useController({
name: "roundMetadata.quadraticFundingConfig.matchingCap",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import InfoModal from "../common/InfoModal";
import ProgressModal from "../common/ProgressModal";
import { Spinner } from "../common/Spinner";
import { assertAddress } from "common/src/address";
import { PayoutTokens, payoutTokens } from "../api/payoutTokens";
import { PayoutToken, payoutTokens } from "../api/payoutTokens";

export default function ViewFundGrantees(props: {
round: Round | undefined;
Expand Down Expand Up @@ -100,7 +100,7 @@ function FinalizedRoundContent(props: { round: Round }) {
const [unpaidProjects, setUnpaidProjects] = useState<MatchingStatsData[]>([]);
const [price, setPrice] = useState<number>(0);

const matchingFundPayoutToken: PayoutTokens = payoutTokens.filter(
const matchingFundPayoutToken: PayoutToken = payoutTokens.filter(
(t) => t.address.toLowerCase() == props.round.token.toLowerCase()
)[0];

Expand Down Expand Up @@ -184,7 +184,7 @@ function FinalizedRoundContent(props: { round: Round }) {
// TODO: Add types
export function PayProjectsTable(props: {
projects: MatchingStatsData[];
token: PayoutTokens;
token: PayoutToken;
price: number;
round: Round;
allProjects: MatchingStatsData[];
Expand Down Expand Up @@ -513,7 +513,7 @@ export function PayProjectsTable(props: {
export function PaidProjectsTable(props: {
projects: MatchingStatsData[];
chainId: number;
token: PayoutTokens;
token: PayoutToken;
price: number;
}) {
// todo: such a nice table should be in a separate and shared file
Expand Down

0 comments on commit e6c768f

Please sign in to comment.