UNPKG

@ixily/activ

Version:

Alpha Capture Trade Idea Verification. Blockchain ownership proven trade ideas and strategies.

145 lines (129 loc) 3.54 kB
import { BehaviorSubject } from 'rxjs' import { CacheStorageModule, ContractModule, IActivConfig, LitModule, LogModule, NftStoreModule, PricingModule, ProvableModule, getBoolean, } from '../..' const state = { singleConfig: false as boolean, config: {} as IActivConfig, configUpdated$: new BehaviorSubject<IActivConfig | undefined>(undefined), } const updateModulesConfig = async () => { const _config = state.config if ( _config.nftStorageKey !== undefined || _config.mockNftStorage !== undefined ) { await NftStoreModule.config({ nftStorageKey: _config.nftStorageKey, mockNftStorage: _config.mockNftStorage, ipfsProxyEnabled: _config.ipfsProxyEnabled, usePinata: _config.usePinata, }) } if (_config.litConfig !== undefined) { await LitModule.config({ litProvider: _config.litConfig.litProvider, mock: _config.litConfig.mock, }) } if (getBoolean(_config.mockProvableValidation)) { ProvableModule.config({ mockValidation: true, }) } if (getBoolean(_config.mockLitPricing)) { ProvableModule.config({ mockValidation: true, mockLitPricing: true, }) } const contract = ContractModule.getBlockchainContract() if (contract.name === 'hardhat') { ProvableModule.config({ mockValidation: true, mockLitPricing: true, }) } if (_config.cacheStorageConfig !== undefined) { await CacheStorageModule.config(_config.cacheStorageConfig) } if (_config.useProxyInPricing !== undefined) { PricingModule.config({ useProxyUntrusted: _config.useProxyInPricing, }) } state.configUpdated$.next(state.config) } const config = async (_config: IActivConfig) => { if (!state.singleConfig) { if (!(_config.singleConfig === false)) { state.singleConfig = true } _config.defaultBlockchainNetwork = _config.defaultBlockchainNetwork || 'amoy' _config.defaultContract = _config.defaultContract || 'v4' state.config = _config // if (_config.contractRecipe !== undefined) { // await ContractModule.buildAndSet( // _config.contractRecipe, // _config.backendWalletPrivateKey, // _config.hardhatDemoWalletToUse, // ) // LitModule.setContract(_config.contractRecipe.coreContractAddress) // await updateModulesConfig() ContractModule.getUpdatedStream().subscribe((indeed) => { if (indeed) { updateModulesConfig() } }) const web3Auth = _config.web3AuthorizationOptions if ( (web3Auth.userWalletPrivateKey === undefined && web3Auth.webProvider === undefined) || (web3Auth.userWalletPrivateKey !== undefined && web3Auth.webProvider !== undefined) ) { throw new Error( 'Config Module Error: defaultContractOptions must have either userWalletPrivateKey or webProvider, but not both', ) } ContractModule.changeToContract( _config.defaultBlockchainNetwork, _config.defaultContract, _config.web3AuthorizationOptions, ) await new Promise((resolve) => { state.configUpdated$.subscribe((indeed) => { if (indeed !== undefined) { resolve(undefined) } }) }) // } LogModule.setLogStatus(getBoolean(_config.showLogsToDebug)) // if (_config?.mockPricing) { // state.mockPricing = true // } // if (_config?.skipPricingSignature) { // state.skipPricingSignature = true // } // await LibrarianModule.config( // _config.librarianConfig || { // sourceOfDataForValidation: 'standalone', // sourceOfDataForViews: 'standalone', // }, // ) } } export const ConfigModule = { config, getConfigUpdatedStream: () => state.configUpdated$, }