UNPKG

@suiware/kit

Version:

Opinionated React components and hooks for building Sui dApps.

1 lines 1.69 kB
{"version":3,"sources":["../src/components/NetworkType.tsx"],"names":[],"mappings":";;;;AAeA,IAAM,cAAc,MAAM;AACxB,EAAA,MAAM,EAAE,WAAY,EAAA,GAAI,uBAAe,EAAE,QAAA,EAAU,MAAM,CAAA;AAEzD,EAAA,IAAI,KAAQ,GAAA,OAAA;AACZ,EAAA,IAAI,eAAe,IAAM,EAAA;AACvB,IAAQ,KAAA,GAAA,QAAA;AAAA,GACV,MAAA,IAAW,gBAAgB,SAAW,EAAA;AACpC,IAAQ,KAAA,GAAA,OAAA;AAAA;AAKV,EAAA,2BACG,KAAM,EAAA,EAAA,KAAA,EAAqB,SAAU,EAAA,kBAAA,EACnC,yBAAe,cAClB,EAAA,CAAA;AAEJ,CAAA;AAEA,IAAO,mBAAQ,GAAA","file":"chunk-OCRJKDUB.mjs","sourcesContent":["import { Badge } from '@radix-ui/themes'\nimport useNetworkType from '~~/hooks/useNetworkType'\n\n/**\n * The `NetworkType` component renders the name of the currently selected network or disconnected if no wallet connected.\n *\n * It automatically re-fetches the network type from wallet every 3 seconds.\n * Every network is displayed in its own color:\n * - disconnected: tomato\n * - localnet/devnet/testnet: amber\n * - mainnet: green\n * Please note the user wallet is the single point of truth and the only way to switch the network now is through wallet settings.\n *\n * The component is using the useNetworkType hook to fetch the network type.\n */\nconst NetworkType = () => {\n const { networkType } = useNetworkType({ autoSync: true })\n\n let color = 'amber'\n if (networkType == null) {\n color = 'tomato'\n } else if (networkType === 'mainnet') {\n color = 'green'\n }\n\n // @todo Suggest Radix adding a better type for the color.\n /* eslint-disable @typescript-eslint/no-explicit-any */\n return (\n <Badge color={color as any} className=\"sk-network-badge\">\n {networkType || 'disconnected'}\n </Badge>\n )\n}\n\nexport default NetworkType\n"]}