Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/babel/traverse-7.24.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DVitaliy authored Apr 18, 2024
2 parents ec2a785 + 6c70790 commit 84e0fb3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poolzfinance/reacthelper",
"version": "1.12.11",
"version": "2.0.0",
"description": "",
"type": "module",
"source": "src/index.ts",
Expand Down
5 changes: 3 additions & 2 deletions src/components/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from "react"
import Web3 from "web3"
import ThePoolzContext from "./Context"
import ThePoolz from "../poolz/ThePoolz"
import { TChainConfig } from "../types/IThePoolzInterface"

const ThePoolzProvider = ({ children }: { children: React.ReactNode }) => {
const ThePoolzProvider = ({ children, overrides }: { children: React.ReactNode, overrides?: TChainConfig }) => {
const [thePoolzInstance, setThePoolzInstance] = React.useState(new ThePoolz(Web3.givenProvider))
const [provider, setProvider] = React.useState(Web3.givenProvider)

Expand All @@ -13,7 +14,7 @@ const ThePoolzProvider = ({ children }: { children: React.ReactNode }) => {
if (!provider) return

const init = async () => {
const instance = new ThePoolz(provider)
const instance = new ThePoolz(provider, overrides)
await instance.init()
setThePoolzInstance(instance)
}
Expand Down
12 changes: 9 additions & 3 deletions src/poolz/ThePoolz.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Web3 from "web3"
import type { Contract } from "web3-eth-contract"
import type { AbiItem } from "web3-utils"
import type { IThePoolzInterface, IERC20Info } from "../types/IThePoolzInterface"
import type { IThePoolzInterface, IERC20Info, TChainConfig } from "../types/IThePoolzInterface"
import { CUSTOMER_ACCOUNT_VARIABLE, DEFAULT_CHAIN_ID, AVAILABLE_CHAINS } from "../constants"
import ERC20 from "../contracts/abi/ERC20.json"
import POOLZ from "../contracts/abi/ThePoolz.json"
Expand Down Expand Up @@ -48,11 +48,13 @@ class ThePoolz implements IThePoolzInterface {
#provider: typeof Web3.givenProvider
#contracts = new Map<string, Contract>()
#isTrustWallet = false
#overrides: TChainConfig | undefined = undefined

constructor(provider: typeof Web3.givenProvider) {
constructor(provider: typeof Web3.givenProvider, overrides?: TChainConfig) {
this.#provider = provider
this.web3 = new Web3(provider)
this.#isTrustWallet = !!provider?.isTrustWallet
this.#overrides = overrides
}
async init() {
await this.initTrust()
Expand Down Expand Up @@ -85,6 +87,7 @@ class ThePoolz implements IThePoolzInterface {
private async initPoolzContracts() {
const chainConfig = AVAILABLE_CHAINS.get(this.chainId)
if (!chainConfig) return
if (this.#overrides) Object.assign(chainConfig, this.#overrides)
const {
poolzTokenAddress,
poolzAddress,
Expand Down Expand Up @@ -316,7 +319,10 @@ class ThePoolz implements IThePoolzInterface {
abifetchPromises.push(
this.fetchContractAbi(tempMultiSender.nameVersion)
.then((abi) => {
this.tempMultiSenderContract = { ...tempMultiSender, contract: new this.web3.eth.Contract(abi as AbiItem[], tempMultiSender.address) }
this.tempMultiSenderContract = {
...tempMultiSender,
contract: new this.web3.eth.Contract(abi as AbiItem[], tempMultiSender.address)
}
})
.catch((e) => {
console.error(e)
Expand Down
36 changes: 35 additions & 1 deletion src/types/IThePoolzInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,43 @@ export interface IChainInfo {
chainId: number
}

export type AcceptableContractNames =
| "PoolzBack"
| "LockedDeal"
| "Whitelist"
| "SignUp"
| "EnvelopToken"
| "BeaconToken"
| "DelayVault"
| "TemporaryToken"
| "MultiWithdraw"
| "LockDealNFT"
| "VaultManager"
| "DealProvider"
| "LockDealProvider"
| "TimedDealProvider"
| "CollateralProvider"
| "RefundProvider"
| "SimpleBuilder"
| "SimpleRefundBuilder"
| "MultiSender"
| "DelayVaultProvider"
| "DelayVaultMigrator"
| "TokenNFTConnector"
| "MultiSenderV2"
| "TempMultiSender"

export type VersionNumber = `${number}.${number}.${number}`

export type NameVersion =
| `${AcceptableContractNames}@${VersionNumber}`
| `${AcceptableContractNames}@${VersionNumber}-${string}`
| "CPoolx"
| "CWhiteList"
| "CSignUp"
export interface IContractInfo {
address: string
nameVersion: string
nameVersion: NameVersion
contract: Contract
proxy?: string
proxyContract?: Contract
Expand Down
6 changes: 6 additions & 0 deletions tests/ThePoolz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,10 @@ describe("ThePoolz", () => {
const thePoolz = new ThePoolz("http://localhost:8545")
await thePoolz.init()
})

test("Overrides config", async () => {
const thePoolz = new ThePoolz("http://localhost:8545", { poolzAddress: "0x000" })
await thePoolz.init()
expect(thePoolz.CPoolx?.address).toEqual("0x000")
})
})

0 comments on commit 84e0fb3

Please sign in to comment.