@bze/bze-ui-kit 1.0.10 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -61
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,17 +13,18 @@ npm install @bze/bze-ui-kit
|
|
|
13
13
|
The consuming app must have these installed (they are **not** bundled):
|
|
14
14
|
|
|
15
15
|
```sh
|
|
16
|
-
npm install @bze/bzejs @chakra-ui/react
|
|
16
|
+
npm install @bze/bzejs @chakra-ui/react bignumber.js chain-registry \
|
|
17
17
|
@chain-registry/types @chain-registry/utils \
|
|
18
|
-
@interchain-kit/core @interchain-kit/react
|
|
19
|
-
interchainjs
|
|
18
|
+
@interchain-kit/core @interchain-kit/react \
|
|
19
|
+
@interchainjs/cosmos @interchainjs/encoding \
|
|
20
|
+
next-themes react react-dom react-icons
|
|
20
21
|
```
|
|
21
22
|
|
|
22
23
|
## Usage
|
|
23
24
|
|
|
24
25
|
```ts
|
|
25
26
|
import {
|
|
26
|
-
// Configuration — call these early in your app
|
|
27
|
+
// Configuration — call these early in your app (both optional)
|
|
27
28
|
setStorageKeyVersion,
|
|
28
29
|
setDefaultTxMemo,
|
|
29
30
|
|
|
@@ -35,6 +36,7 @@ import {
|
|
|
35
36
|
|
|
36
37
|
// Hooks
|
|
37
38
|
useAssets, useBalances, useMarkets, useLiquidityPools,
|
|
39
|
+
useWalletHealthCheck,
|
|
38
40
|
|
|
39
41
|
// Context (provide your own AssetsProvider)
|
|
40
42
|
AssetsContext,
|
|
@@ -49,31 +51,76 @@ import {
|
|
|
49
51
|
Each app must configure the library at startup:
|
|
50
52
|
|
|
51
53
|
```ts
|
|
52
|
-
// In your app's entry point (e.g., layout.tsx
|
|
54
|
+
// In your app's entry point (e.g., layout.tsx)
|
|
53
55
|
import { setStorageKeyVersion, setDefaultTxMemo } from '@bze/bze-ui-kit';
|
|
54
56
|
|
|
55
57
|
// Set a unique storage prefix to avoid localStorage collisions between apps
|
|
56
58
|
setStorageKeyVersion('3'); // dex uses '3', burner uses '2'
|
|
57
59
|
|
|
58
|
-
//
|
|
60
|
+
// Optional — transaction memo defaults to NEXT_PUBLIC_APP_NAME if set.
|
|
61
|
+
// Only needed if you want a value different from the app name env var.
|
|
59
62
|
setDefaultTxMemo('dex.getbze.com');
|
|
60
63
|
```
|
|
61
64
|
|
|
62
65
|
### AssetsProvider
|
|
63
66
|
|
|
64
|
-
The library exports
|
|
67
|
+
The library exports `AssetsContext` and `AssetsContextType` but each app implements its own `AssetsProvider`. This is because dex and burner have different app-specific state on top of the shared base.
|
|
68
|
+
|
|
69
|
+
### Wallet health check
|
|
70
|
+
|
|
71
|
+
Call `useWalletHealthCheck()` in a top-level always-mounted component (e.g. `BlockchainListenerWrapper`) to proactively detect and clear stale wallet state restored from localStorage (e.g. extension locked after leaving the page for hours):
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { useWalletHealthCheck } from '@bze/bze-ui-kit';
|
|
75
|
+
|
|
76
|
+
export function BlockchainListenerWrapper() {
|
|
77
|
+
useWalletHealthCheck();
|
|
78
|
+
// ...
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Blockchain event subscriptions
|
|
83
|
+
|
|
84
|
+
Use `subscribeToBlockchainEvents` to subscribe to CometBFT events via a shared WebSocket singleton (one persistent connection reused across the whole app):
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
import { subscribeToBlockchainEvents, getSettings } from '@bze/bze-ui-kit';
|
|
88
|
+
|
|
89
|
+
const unsubscribe = await subscribeToBlockchainEvents(
|
|
90
|
+
getSettings().endpoints.rpcEndpoint,
|
|
91
|
+
"tm.event='NewBlock'",
|
|
92
|
+
(result) => { /* handle result.data.value */ }
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Later:
|
|
96
|
+
unsubscribe();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The singleton handles reconnection with exponential backoff and automatically resubscribes active subscriptions after reconnect.
|
|
100
|
+
|
|
101
|
+
### Event helper functions
|
|
102
|
+
|
|
103
|
+
Use these to filter CometBFT events in your blockchain listener:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
import {
|
|
107
|
+
isAddressTransfer, isBurnEvent, isCoinbaseEvent, isEpochStartEvent,
|
|
108
|
+
isOrderBookEvent, isOrderExecutedEvent, isSwapEvent,
|
|
109
|
+
getMintedAmount, getEventMarketId, getEventKeyValue,
|
|
110
|
+
} from '@bze/bze-ui-kit';
|
|
111
|
+
```
|
|
65
112
|
|
|
66
113
|
## What's included
|
|
67
114
|
|
|
68
115
|
| Module | Description |
|
|
69
116
|
|--------|-------------|
|
|
70
117
|
| `types/` | TypeScript interfaces for assets, balances, markets, pools, staking, IBC, events, settings, burn, block |
|
|
71
|
-
| `utils/` | Pure functions: amount math, denom helpers, formatting, address validation, staking APR, chart periods |
|
|
118
|
+
| `utils/` | Pure functions: amount math, denom helpers, formatting, address validation, staking APR, chart periods, event filters |
|
|
72
119
|
| `constants/` | Chain config, RPC/REST endpoints, asset lists, keplr fallbacks, testnet, ecosystem navigation |
|
|
73
120
|
| `storage/` | localStorage wrapper with TTL + app settings persistence |
|
|
74
121
|
| `service/` | AmmRouter (Dijkstra swap routing), BlockchainEventManager (pub-sub), assets_factory, keplr suggest chain |
|
|
75
122
|
| `query/` | REST clients for bank, staking, markets, liquidity pools, epochs, IBC, burner, raffle, block, module, rewards, aggregator, prices |
|
|
76
|
-
| `hooks/` | React hooks: useAssets, useBalances, useMarkets, useLiquidityPools, useLiquidityPool, usePrices, useEpochs, useSigningClient, useSettings, useFeeTokens, useAssetsValue, useConnectionType, useToast, useSDKTx/useBZETx/useIBCTx |
|
|
123
|
+
| `hooks/` | React hooks: useAssets, useBalances, useMarkets, useLiquidityPools, useLiquidityPool, usePrices, useEpochs, useSigningClient, useWalletHealthCheck, useSettings, useFeeTokens, useAssetsValue, useConnectionType, useToast, useSDKTx/useBZETx/useIBCTx |
|
|
77
124
|
| `contexts/` | Base `AssetsContextType` interface + `AssetsContext` React context |
|
|
78
125
|
| `components/` | Sidebar, WalletSidebarContent, SettingsSidebarContent, SettingsToggle, Toaster, HighlightText |
|
|
79
126
|
|
|
@@ -93,8 +140,9 @@ The library reads these `NEXT_PUBLIC_*` env vars at build time (inlined by Next.
|
|
|
93
140
|
| `NEXT_PUBLIC_USDC_IBC_DENOM` | _(empty)_ | IBC denom for USDC on BZE chain |
|
|
94
141
|
| `NEXT_PUBLIC_EXPLORER_URL` | `https://explorer.chaintools.tech` | Block explorer base URL |
|
|
95
142
|
| `NEXT_PUBLIC_WALLET_CHAINS_NAMES` | _(auto)_ | Comma-separated chain names for wallet connection |
|
|
96
|
-
| `NEXT_PUBLIC_LOCKER_ADDRESS` | `bze1pc5zjcvhx3e8l305zjl72grytfa30r5mdypmw4` | Locker module address
|
|
97
|
-
| `NEXT_PUBLIC_APP_NAME` | `BZE` | Display name
|
|
143
|
+
| `NEXT_PUBLIC_LOCKER_ADDRESS` | `bze1pc5zjcvhx3e8l305zjl72grytfa30r5mdypmw4` | Locker module address |
|
|
144
|
+
| `NEXT_PUBLIC_APP_NAME` | `BZE` | Display name and default transaction memo |
|
|
145
|
+
| `NEXT_PUBLIC_GAS_MULTIPLIER` | `1.5` | Multiplier applied to simulated gas estimates |
|
|
98
146
|
|
|
99
147
|
### BZE endpoints
|
|
100
148
|
|
|
@@ -103,7 +151,7 @@ The library reads these `NEXT_PUBLIC_*` env vars at build time (inlined by Next.
|
|
|
103
151
|
| `NEXT_PUBLIC_REST_URL` | _(empty)_ | Default BZE REST endpoint |
|
|
104
152
|
| `NEXT_PUBLIC_RPC_URL` | _(empty)_ | Default BZE RPC endpoint |
|
|
105
153
|
| `NEXT_PUBLIC_REST_ENDPOINT` | _(empty)_ | User-configurable REST endpoint (settings default) |
|
|
106
|
-
| `NEXT_PUBLIC_RPC_ENDPOINT` | _(empty)_ | User-configurable RPC endpoint (settings default) |
|
|
154
|
+
| `NEXT_PUBLIC_RPC_ENDPOINT` | _(empty)_ | User-configurable RPC/WebSocket endpoint (settings default) |
|
|
107
155
|
| `NEXT_PUBLIC_AGG_API_HOST` | `https://getbze.com` | Aggregator API host for prices/tickers |
|
|
108
156
|
|
|
109
157
|
### IBC chain endpoints
|
|
@@ -125,15 +173,11 @@ The library reads these `NEXT_PUBLIC_*` env vars at build time (inlined by Next.
|
|
|
125
173
|
|
|
126
174
|
### Ecosystem navigation
|
|
127
175
|
|
|
128
|
-
Override links and labels for the "Other" dropdown in the navbar, or exclude apps entirely. Useful for testnet deployments.
|
|
129
|
-
|
|
130
176
|
| Env var | Default | Description |
|
|
131
177
|
|---------|---------|-------------|
|
|
132
|
-
| `NEXT_PUBLIC_ECOSYSTEM_EXCLUDED` | _(empty)_ | Comma-separated keys to hide
|
|
133
|
-
| `NEXT_PUBLIC_ECOSYSTEM_LINK_{KEY}` | _(per app)_ | Override
|
|
134
|
-
| `NEXT_PUBLIC_ECOSYSTEM_LABEL_{KEY}` | _(per app)_ | Override
|
|
135
|
-
|
|
136
|
-
Call `getEcosystemApps()` to get the filtered and overridden list. Each app should exclude itself via `NEXT_PUBLIC_ECOSYSTEM_EXCLUDED`.
|
|
178
|
+
| `NEXT_PUBLIC_ECOSYSTEM_EXCLUDED` | _(empty)_ | Comma-separated keys to hide (e.g. `staking,factory`). Valid: `website`, `staking`, `dex`, `burner`, `factory` |
|
|
179
|
+
| `NEXT_PUBLIC_ECOSYSTEM_LINK_{KEY}` | _(per app)_ | Override URL for an app (e.g. `NEXT_PUBLIC_ECOSYSTEM_LINK_WEBSITE`) |
|
|
180
|
+
| `NEXT_PUBLIC_ECOSYSTEM_LABEL_{KEY}` | _(per app)_ | Override display label (e.g. `NEXT_PUBLIC_ECOSYSTEM_LABEL_DEX`) |
|
|
137
181
|
|
|
138
182
|
### AtomOne validator (dex-only)
|
|
139
183
|
|
|
@@ -146,10 +190,10 @@ Call `getEcosystemApps()` to get the filtered and overridden list. Each app shou
|
|
|
146
190
|
|
|
147
191
|
These are **not** in the library — each app keeps its own:
|
|
148
192
|
|
|
149
|
-
- **useBlockchainListener** — different WebSocket event subscriptions per app
|
|
193
|
+
- **useBlockchainListener** — different WebSocket event subscriptions per app; built on top of `subscribeToBlockchainEvents` from the lib
|
|
150
194
|
- **useNavigation** — completely different route structures
|
|
151
|
-
- **AssetsProvider** (`contexts/assets_context.tsx`) — each app
|
|
152
|
-
- **Burner-only**: `useBurnerContext
|
|
195
|
+
- **AssetsProvider** (`contexts/assets_context.tsx`) — each app extends the shared base `AssetsContextType` with app-specific state
|
|
196
|
+
- **Burner-only**: `useBurnerContext`, `useBurningHistory`, `useNextBurning`, `useRaffles`
|
|
153
197
|
- **Dex-only**: `useLockedLiquidity`, `useNativeStakingData`, `useRewardsStakingData`
|
|
154
198
|
|
|
155
199
|
## Development
|
|
@@ -172,51 +216,19 @@ npm run lint
|
|
|
172
216
|
|
|
173
217
|
### Prerequisites
|
|
174
218
|
|
|
175
|
-
|
|
176
|
-
```sh
|
|
177
|
-
npm login
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
2. Verify you have publish access to the `@bze` scope:
|
|
181
|
-
```sh
|
|
182
|
-
npm access list packages @bze
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
### Steps
|
|
219
|
+
Add a publish token to `~/.npmrc` so `npm publish` never prompts for login:
|
|
186
220
|
|
|
187
221
|
```sh
|
|
188
|
-
|
|
189
|
-
git status
|
|
190
|
-
|
|
191
|
-
# 2. Update the version in package.json
|
|
192
|
-
# For a patch release:
|
|
193
|
-
npm version patch
|
|
194
|
-
# For a minor release:
|
|
195
|
-
npm version minor
|
|
196
|
-
# For a major release:
|
|
197
|
-
npm version major
|
|
198
|
-
|
|
199
|
-
# 3. Build the library
|
|
200
|
-
npm run build
|
|
201
|
-
|
|
202
|
-
# 4. Verify the build output looks correct
|
|
203
|
-
ls -la dist/
|
|
204
|
-
# Should contain: index.js, index.mjs, index.d.ts, index.d.mts, and source maps
|
|
205
|
-
|
|
206
|
-
# 5. Do a dry run to see what would be published
|
|
207
|
-
npm publish --dry-run
|
|
208
|
-
|
|
209
|
-
# 6. Publish to npm
|
|
210
|
-
npm publish
|
|
211
|
-
|
|
212
|
-
# 7. Verify the published package
|
|
213
|
-
npm view @bze/bze-ui-kit
|
|
222
|
+
echo "//registry.npmjs.org/:_authToken=YOUR_TOKEN" >> ~/.npmrc
|
|
214
223
|
```
|
|
215
224
|
|
|
216
|
-
|
|
225
|
+
Generate the token at npmjs.com → your avatar → Access Tokens → Generate New Token → Classic → Publish.
|
|
226
|
+
|
|
227
|
+
### Steps
|
|
217
228
|
|
|
218
229
|
```sh
|
|
219
|
-
|
|
230
|
+
# 1. Bump the version in package.json, then:
|
|
231
|
+
npm run build && npm publish
|
|
220
232
|
```
|
|
221
233
|
|
|
222
234
|
## License
|
package/dist/index.js
CHANGED
|
@@ -3619,21 +3619,27 @@ var useSigningClient = ({ chainName }) => {
|
|
|
3619
3619
|
const { getSigningClient, signingClientError, wallet, chain } = (0, import_react4.useChain)(chainName != null ? chainName : getChainName());
|
|
3620
3620
|
const [signingClient, setSigningClient] = (0, import_react3.useState)(null);
|
|
3621
3621
|
const [isSigningClientReady, setIsSigningClientReady] = (0, import_react3.useState)(false);
|
|
3622
|
-
const
|
|
3622
|
+
const initializedForWallet = (0, import_react3.useRef)(null);
|
|
3623
3623
|
const createSigningClient = (0, import_react3.useCallback)(async () => {
|
|
3624
3624
|
return getSigningClient();
|
|
3625
3625
|
}, [getSigningClient]);
|
|
3626
3626
|
(0, import_react3.useEffect)(() => {
|
|
3627
|
-
if (!wallet || !chain
|
|
3627
|
+
if (!wallet || !chain) {
|
|
3628
|
+
if (initializedForWallet.current !== null) {
|
|
3629
|
+
setSigningClient(null);
|
|
3630
|
+
setIsSigningClientReady(false);
|
|
3631
|
+
initializedForWallet.current = null;
|
|
3632
|
+
}
|
|
3628
3633
|
return;
|
|
3629
3634
|
}
|
|
3635
|
+
if (initializedForWallet.current === wallet) return;
|
|
3630
3636
|
const load = async () => {
|
|
3631
3637
|
const client = await createSigningClient();
|
|
3632
3638
|
if (client) {
|
|
3633
3639
|
registerBzeEncoders(client);
|
|
3634
3640
|
setSigningClient(client);
|
|
3635
3641
|
setIsSigningClientReady(true);
|
|
3636
|
-
|
|
3642
|
+
initializedForWallet.current = wallet;
|
|
3637
3643
|
}
|
|
3638
3644
|
};
|
|
3639
3645
|
load();
|