From 3d0f97e0bf52032c2d2cd5347cd8774c6113016e Mon Sep 17 00:00:00 2001 From: Kenan Soylu Date: Mon, 10 Jan 2022 11:54:47 +0100 Subject: [PATCH] updated types --- src/svelte-web3.d.ts | 68 ++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 25 deletions(-) diff --git a/src/svelte-web3.d.ts b/src/svelte-web3.d.ts index 666e6d1..43e6f59 100644 --- a/src/svelte-web3.d.ts +++ b/src/svelte-web3.d.ts @@ -1,5 +1,8 @@ import { Readable } from "svelte/store"; import Web3 from "web3"; +import { provider } from "web3-core"; +import { AbiItem } from "web3-utils"; +import { ContractOptions, Contract } from "web3-eth-contract"; declare module "svelte-web3" { /** @@ -30,26 +33,19 @@ declare module "svelte-web3" { }[]; } - interface DefaultChainStore { + interface ChainStore { /** - * Enables a connection with the current window provider - * Note that your code need to be in browser context when setBrowserProvider is running. - * So you may want to use onMount when using Sapper or Sveltekit. Similarly, you cannot use setBrowserProvider in SSR context. - */ - readonly setBrowserProvider(): Promise; - /** - * To enable connection using a custom provider. + * Enables a connection with the current window provider. + * Note that your code need to be in browser context when setProvider is running. + * So you may want to use onMount when using Sapper or Sveltekit. * @param provider An url string or a valid provider object (as returned by web3Modal or WalletConnect for example) + * @param index Select another account than the default when possible. */ - readonly setProvider(provider: string): Promise; + setProvider(provider?: provider, index?: string): Promise; /** * Forces a disconnect (and event subscriptions from a provider) */ - readonly close(): Promise; - } - - // ---------- CUSTOM CHAIN STORE PROPERTIES ---------- - interface ChainStore extends DefaultChainStore { + disconnect(): Promise; /** * The whole Web3.js API. It must be references as `$web3` and not `web3` since it is a Svelte store. * @see https://web3js.readthedocs.io/en/v1.5.2/web3.html @@ -77,53 +73,75 @@ declare module "svelte-web3" { /** * The main connection helper and derived Svelte stores */ - const defaultChainStore: DefaultChainStore; + const defaultEvmStores: ChainStore; /** - * The whole Web3.js API for the `defaultChainStore`. It must be references as `$web3` and not `web3` since it is a Svelte store. + * The whole Web3.js API for the `defaultEvmStores`. It must be references as `$web3` and not `web3` since it is a Svelte store. * @see https://web3js.readthedocs.io/en/v1.5.2/web3.html */ const web3: Readable; /** - * Current selected account address of the `defaultChainStore` if connected, `null` otherwise. + * Current selected account address of the `defaultEvmStores` if connected, `null` otherwise. */ const selectedAccount: Readable; /** - * `true` if connection to the provider was successful for `defaultChainStore`. + * `true` if connection to the provider was successful for `defaultEvmStores`. */ const connected: Readable; /** - * The current blockchain CAIP-2 data of `defaultChainStore` if connected, empty object otherwise. + * The current blockchain CAIP-2 data of `defaultEvmStores` if connected, empty object otherwise. */ const chainData: Readable; /** - * The current chainId of `defaultChainStore` if connected. + * The current chainId of `defaultEvmStores` if connected. */ const chainId: Readable; /** * This can be used to create several stores, each connected to different providers. * This lets you manage different chains at the same time. - * @param name Unique name for the newly created store. The name `default` is used to create `defaultChainStore` so you shouldn't use it unless you want to override the default store. + * @param name Unique name for the newly created store. The name `default` is used to create `defaultEvmStores` so you shouldn't use it unless you want to override the default store. */ - function makeChainStore(name: string): ChainStore; + function makeEvmStores(name: string): ChainStore; /** * Retrieves the store without re-initializing the connection: * @param name Name of the previously created store. + * @returns The store if connected, `null` otherwise. */ function getChainStore(name: string): ChainStore; + /** + * You might want to access all chains CAIP-2 data directly without using the chainData store. + * In this case, use the getter allChainsData, it returns the list of all CAIP-2 data available. + */ + const allChainsData: ChainData[]; + + /** + * Allows you to create a Svelte derived store of a web3.eth.Contract object instance. + * It takes the same parameters as a ̀new web3.eth.Contract` call. + * @param jsonInterface The contract ABI array + * @param address The contract address + * @param options The contract options + * @returns A Svelte derived store of a web3.eth.Contract object instance + */ + function makeContractStore( + jsonInterface: AbiItem[], + address?: string, + options?: ContractOptions + ): Readable; + export { ChainData, - DefaultChainStore, ChainStore, web3, selectedAccount, connected, chainId, chainData, - defaultChainStore, - makeChainStore, + defaultEvmStores, + makeEvmStores, getChainStore, + allChainsData, + makeContractStore, }; }