2023-02-02 08:34:28 +00:00
|
|
|
import type { UseBadgeHubContractProps } from 'contracts/badgeHub'
|
|
|
|
import { useBadgeHubContract } from 'contracts/badgeHub'
|
2022-12-09 08:27:50 +00:00
|
|
|
import type { UseBaseFactoryContractProps } from 'contracts/baseFactory'
|
|
|
|
import { useBaseFactoryContract } from 'contracts/baseFactory'
|
|
|
|
import type { UseBaseMinterContractProps } from 'contracts/baseMinter'
|
|
|
|
import { useBaseMinterContract } from 'contracts/baseMinter'
|
2023-06-14 09:40:02 +00:00
|
|
|
import { type UseOpenEditionFactoryContractProps, useOpenEditionFactoryContract } from 'contracts/openEditionFactory'
|
|
|
|
import { type UseOpenEditionMinterContractProps, useOpenEditionMinterContract } from 'contracts/openEditionMinter'
|
2022-07-19 07:53:03 +00:00
|
|
|
import type { UseSG721ContractProps } from 'contracts/sg721'
|
|
|
|
import { useSG721Contract } from 'contracts/sg721'
|
2022-10-21 01:02:52 +00:00
|
|
|
import type { UseVendingFactoryContractProps } from 'contracts/vendingFactory'
|
|
|
|
import { useVendingFactoryContract } from 'contracts/vendingFactory'
|
2022-12-09 08:27:50 +00:00
|
|
|
import type { UseVendingMinterContractProps } from 'contracts/vendingMinter'
|
|
|
|
import { useVendingMinterContract } from 'contracts/vendingMinter'
|
2022-07-19 07:53:03 +00:00
|
|
|
import type { UseWhiteListContractProps } from 'contracts/whitelist'
|
|
|
|
import { useWhiteListContract } from 'contracts/whitelist'
|
|
|
|
import type { ReactNode, VFC } from 'react'
|
|
|
|
import { Fragment, useEffect } from 'react'
|
|
|
|
import type { State } from 'zustand'
|
|
|
|
import create from 'zustand'
|
2022-07-13 13:56:36 +00:00
|
|
|
|
2023-03-19 06:57:42 +00:00
|
|
|
import type { UseSplitsContractProps } from '../contracts/splits/useContract'
|
|
|
|
import { useSplitsContract } from '../contracts/splits/useContract'
|
|
|
|
|
2022-07-13 13:56:36 +00:00
|
|
|
/**
|
|
|
|
* Contracts store type definitions
|
|
|
|
*/
|
|
|
|
export interface ContractsStore extends State {
|
2022-07-14 10:16:50 +00:00
|
|
|
sg721: UseSG721ContractProps | null
|
2022-12-09 08:27:50 +00:00
|
|
|
vendingMinter: UseVendingMinterContractProps | null
|
|
|
|
baseMinter: UseBaseMinterContractProps | null
|
2023-06-14 09:40:02 +00:00
|
|
|
openEditionMinter: UseOpenEditionMinterContractProps | null
|
2022-07-19 07:53:03 +00:00
|
|
|
whitelist: UseWhiteListContractProps | null
|
2022-10-21 01:02:52 +00:00
|
|
|
vendingFactory: UseVendingFactoryContractProps | null
|
2022-12-09 08:27:50 +00:00
|
|
|
baseFactory: UseBaseFactoryContractProps | null
|
2023-06-14 09:40:02 +00:00
|
|
|
openEditionFactory: UseOpenEditionFactoryContractProps | null
|
2023-02-01 12:55:52 +00:00
|
|
|
badgeHub: UseBadgeHubContractProps | null
|
2023-03-19 06:57:42 +00:00
|
|
|
splits: UseSplitsContractProps | null
|
2022-07-13 13:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contracts store default values as a separate variable for reusability
|
|
|
|
*/
|
|
|
|
export const defaultValues: ContractsStore = {
|
2022-07-14 10:16:50 +00:00
|
|
|
sg721: null,
|
2022-12-09 08:27:50 +00:00
|
|
|
vendingMinter: null,
|
|
|
|
baseMinter: null,
|
2023-06-14 09:40:02 +00:00
|
|
|
openEditionMinter: null,
|
2022-07-14 10:16:50 +00:00
|
|
|
whitelist: null,
|
2022-10-21 01:02:52 +00:00
|
|
|
vendingFactory: null,
|
2022-12-09 08:27:50 +00:00
|
|
|
baseFactory: null,
|
2023-06-14 09:40:02 +00:00
|
|
|
openEditionFactory: null,
|
2023-02-01 12:55:52 +00:00
|
|
|
badgeHub: null,
|
2023-03-19 06:57:42 +00:00
|
|
|
splits: null,
|
2022-07-13 13:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Entrypoint for contracts store using {@link defaultValues}
|
|
|
|
*/
|
|
|
|
export const useContracts = create<ContractsStore>(() => ({
|
|
|
|
...defaultValues,
|
|
|
|
}))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Contracts store provider to easily mount {@link ContractsSubscription}
|
|
|
|
* to listen/subscribe to contract changes
|
|
|
|
*/
|
|
|
|
export const ContractsProvider = ({ children }: { children: ReactNode }) => {
|
|
|
|
return (
|
2022-07-19 07:53:03 +00:00
|
|
|
<>
|
2022-07-13 13:56:36 +00:00
|
|
|
{children}
|
|
|
|
<ContractsSubscription />
|
2022-07-19 07:53:03 +00:00
|
|
|
</>
|
2022-07-13 13:56:36 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-07-14 10:16:50 +00:00
|
|
|
const ContractsSubscription: VFC = () => {
|
|
|
|
const sg721 = useSG721Contract()
|
2022-12-09 08:27:50 +00:00
|
|
|
const vendingMinter = useVendingMinterContract()
|
|
|
|
const baseMinter = useBaseMinterContract()
|
2023-06-14 09:40:02 +00:00
|
|
|
const openEditionMinter = useOpenEditionMinterContract()
|
2022-07-14 10:16:50 +00:00
|
|
|
const whitelist = useWhiteListContract()
|
2022-10-21 01:02:52 +00:00
|
|
|
const vendingFactory = useVendingFactoryContract()
|
2022-12-09 08:27:50 +00:00
|
|
|
const baseFactory = useBaseFactoryContract()
|
2023-06-14 09:40:02 +00:00
|
|
|
const openEditionFactory = useOpenEditionFactoryContract()
|
2023-02-01 12:55:52 +00:00
|
|
|
const badgeHub = useBadgeHubContract()
|
2023-03-19 06:57:42 +00:00
|
|
|
const splits = useSplitsContract()
|
2022-07-14 10:16:50 +00:00
|
|
|
|
2022-07-13 13:56:36 +00:00
|
|
|
useEffect(() => {
|
|
|
|
useContracts.setState({
|
2022-07-14 10:16:50 +00:00
|
|
|
sg721,
|
2022-12-09 08:27:50 +00:00
|
|
|
vendingMinter,
|
|
|
|
baseMinter,
|
2023-06-14 09:40:02 +00:00
|
|
|
openEditionMinter,
|
2022-07-14 10:16:50 +00:00
|
|
|
whitelist,
|
2022-10-21 01:02:52 +00:00
|
|
|
vendingFactory,
|
2022-12-09 08:27:50 +00:00
|
|
|
baseFactory,
|
2023-06-14 09:40:02 +00:00
|
|
|
openEditionFactory,
|
2023-02-01 12:55:52 +00:00
|
|
|
badgeHub,
|
2023-03-19 06:57:42 +00:00
|
|
|
splits,
|
2022-07-13 13:56:36 +00:00
|
|
|
})
|
2023-03-19 06:57:42 +00:00
|
|
|
}, [sg721, vendingMinter, baseMinter, whitelist, vendingFactory, baseFactory, badgeHub, splits])
|
2022-07-13 13:56:36 +00:00
|
|
|
|
|
|
|
return null
|
|
|
|
}
|