diff --git a/package.json b/package.json index 6f33542..390bed3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poolzfinance/reacthelper", - "version": "2.1.8", + "version": "2.1.12", "description": "", "type": "module", "source": "src/index.ts", diff --git a/src/contracts/configs/Avalanche.config.ts b/src/contracts/configs/Avalanche.config.ts index 33d1f52..e4927a9 100644 --- a/src/contracts/configs/Avalanche.config.ts +++ b/src/contracts/configs/Avalanche.config.ts @@ -58,5 +58,9 @@ export const AvalancheChainConfig: TChainConfig = { simpleRefundBuilder: { address: "0xff1f0872f5462b30acdA92a08D2388612F7Bf7EE", nameVersion: "SimpleRefundBuilder@1.2.2" + }, + multiSenderV2: { + address: "0x1E947Ec4F6B74c746F13604438cE1A3026f30553", + nameVersion: "MultiSenderV2@2.1.0" } } diff --git a/src/contracts/configs/BinanceTest.config.ts b/src/contracts/configs/BinanceTest.config.ts index bb2bb9a..fefbeae 100644 --- a/src/contracts/configs/BinanceTest.config.ts +++ b/src/contracts/configs/BinanceTest.config.ts @@ -83,5 +83,9 @@ export const BinanceTestChainConfig: TChainConfig = { tokenNFTConnector: { address: "0x99dfade11d9cd4c2b192efda205c50d982cd76a1", nameVersion: "TokenNFTConnector@1.2.1" + }, + dispenserProvider: { + address: "0xeff8a476a62Ba2Ff1C8a202BEC40b45B7b822EC1", + nameVersion: "DispenserProvider@1.0.6" } } diff --git a/src/hooks/useTheSiwe.ts b/src/hooks/useTheSiwe.ts index 76990a1..3331445 100644 --- a/src/hooks/useTheSiwe.ts +++ b/src/hooks/useTheSiwe.ts @@ -11,14 +11,14 @@ interface ISiwe { IssuedAt: string ExpirationAt: string } -type TProps = () => Partial +type TProps = () => Promise> export const useTheSiwe = (props: TProps) => { const thePoolz = useThePoolz() const { web3, account } = thePoolz - const templateEip4361message = useCallback(() => { - const { Domain, URI, Statement, Version, ChainId, Nonce, IssuedAt, ExpirationAt } = props() + const templateEip4361message = useCallback(async () => { + const { Domain, URI, Statement, Version, ChainId, Nonce, IssuedAt, ExpirationAt } = await props() const { host: domain, href: uri } = window.location return `${Domain ?? domain} wants you to sign in with your Ethereum account: ${account} @@ -36,7 +36,7 @@ Expiration Time: ${ExpirationAt ?? new Date(new Date().getTime() + 1000 * 60 * 6 return useMemo(() => { const signInWithEthereum = async () => { if (!web3.currentProvider || !account) throw new Error("No web3 provider or account") - const eip4361message = templateEip4361message() + const eip4361message = await templateEip4361message() // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const signature = (await web3.currentProvider.request({ diff --git a/src/index.ts b/src/index.ts index 315c4f9..cfbc5a9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,7 @@ import { useTheSiwe } from "./hooks/useTheSiwe" import { useSidNameForAddress } from "./hooks/useSid" export { ThePoolzProvider, useThePoolz, useConnectWallet, useSidNameForAddress, useTheSiwe } -export type { IThePoolzInterface, IERC20Info } from "./types/IThePoolzInterface" +export type { IThePoolzInterface, IERC20Info, IChainConfig, TChainConfig } from "./types/IThePoolzInterface" export * from "./utils" export * from "./constants" export type { Contract } from "web3-eth-contract" diff --git a/src/poolz/ThePoolz.ts b/src/poolz/ThePoolz.ts index d72e948..de24e77 100644 --- a/src/poolz/ThePoolz.ts +++ b/src/poolz/ThePoolz.ts @@ -44,6 +44,7 @@ class ThePoolz implements EnforceInterface { public delayVaultProviderContract: IThePoolzInterface["delayVaultProviderContract"] public delayVaultMigratorContract: IThePoolzInterface["delayVaultMigratorContract"] public tokenNFTConnectorContract: IThePoolzInterface["tokenNFTConnectorContract"] + public dispenserProviderContract: IThePoolzInterface["dispenserProviderContract"] #provider: typeof Web3.givenProvider #contracts = new Map() @@ -108,7 +109,8 @@ class ThePoolz implements EnforceInterface { multiSenderV2, delayVaultProvider, delayVaultMigrator, - tokenNFTConnector + tokenNFTConnector, + dispenserProvider } = chainConfig this.poolzTokenAddress = poolzTokenAddress @@ -344,6 +346,20 @@ class ThePoolz implements EnforceInterface { }) ) } + if (dispenserProvider) { + abifetchPromises.push( + this.fetchContractAbi(dispenserProvider.nameVersion) + .then((abi) => { + this.dispenserProviderContract = { + ...dispenserProvider, + contract: new this.web3.eth.Contract(abi as AbiItem[], dispenserProvider.address) + } + }) + .catch((e) => { + console.error(e) + }) + ) + } try { await Promise.allSettled(abifetchPromises) diff --git a/src/types/IThePoolzInterface.ts b/src/types/IThePoolzInterface.ts index a4a51e9..9b159e0 100644 --- a/src/types/IThePoolzInterface.ts +++ b/src/types/IThePoolzInterface.ts @@ -24,6 +24,7 @@ export type AcceptableContractNames = | "DelayVaultMigrator" | "TokenNFTConnector" | "MultiSenderV2" + | "DispenserProvider" export type VersionNumber = `${number}.${number}.${number}` @@ -97,6 +98,7 @@ export interface IThePoolzInterface { delayVaultProviderContract?: IContractInfo delayVaultMigratorContract?: IContractInfo tokenNFTConnectorContract?: IContractInfo + dispenserProviderContract?: IContractInfo init(): Promise getChaincoinInfo(k?: number): Promise @@ -148,6 +150,8 @@ export interface IChainConfig { delayVaultProvider: Omit, "contract"> delayVaultMigrator: Omit, "contract"> tokenNFTConnector: Omit, "contract"> + + dispenserProvider: Omit, "contract"> } // copy chain data from https://chainid.network/chains.json