UNPKG

@suiware/kit

Version:

Opinionated React components and hooks for building Sui dApps.

54 lines (52 loc) 1.72 kB
interface IUseNetworkTypeParams { /** * (Optional) The flag determines whether the app network needs to be synchronized with the wallet network regularly or just once. */ autoSync?: boolean; /** * (Optional) Auto sync interval in milliseconds. */ autoSyncInterval?: number; } interface IUseNetworkTypeResponse { /** * Network type or undefined if wallet is not connected. */ networkType?: 'mainnet' | 'testnet' | 'devnet' | 'localnet'; /** * Synchronize app network with wallet network on demand. */ synchronize: () => void; } /** * The useNetworkType() hook lets you determine which network is currently active in the user wallet. * * It's possible to request the network type once or on a regular basis. * If a wallet is not connected, the network type will be undefined. * Please note the user wallet is the single point of truth and the only way to switch the network now is through wallet settings. * * Usage: * - One-time request * ```ts * const { networkType } = useNetworkType({ * autoSync: false * }) * ``` * - On demand * ```ts * const { networkType, synchronize } = useNetworkType() * synchronize() * ``` * - Regular update * ```ts * const { networkType } = useNetworkType({ * autoSync: true, * autoSyncInterval: 3000 * }) * ``` * * @param {IUseNetworkTypeParams} params The parameter object. * @returns {IUseNetworkTypeResponse} An object with the network type and synchronize function. */ declare const useNetworkType: ({ autoSync, autoSyncInterval, }?: IUseNetworkTypeParams) => IUseNetworkTypeResponse; export { type IUseNetworkTypeParams, type IUseNetworkTypeResponse, useNetworkType as default };