@bluxcc/core 0.2.12 → 0.2.14

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.
@@ -0,0 +1,2 @@
1
+ declare const TokenDetails: () => import("react/jsx-runtime").JSX.Element | null;
2
+ export default TokenDetails;
package/dist/store.d.ts CHANGED
@@ -4,7 +4,7 @@ import { Route } from './enums';
4
4
  import { UseBalancesResult } from './hooks/useBalances';
5
5
  import { UseTransactionsResult } from './hooks/useTransactions';
6
6
  import Emitter, { BluxEventMap } from './utils/events';
7
- import { IAsset, IWallet, IAppearance, ISignMessage, IInternalConfig, ISendTransaction, AuthenticateApiResponse, ISignAuthEntry } from './types';
7
+ import { IAsset, IWallet, IAppearance, AssetMetaMap, ICustomToken, ICustomTokens, ISignMessage, IInternalConfig, ISendTransaction, AuthenticateApiResponse, ISignAuthEntry } from './types';
8
8
  export type AlertType = 'error' | 'success' | 'warn' | 'none' | 'copy';
9
9
  export type WaitingStatus = 'login' | 'sendTransaction' | 'signMessage' | 'signAuthEntry';
10
10
  export interface ILogo {
@@ -49,6 +49,7 @@ export interface ILoginPromise {
49
49
  }
50
50
  export interface IStoreProperties {
51
51
  logos: ILogo[] | null;
52
+ assetMeta: AssetMetaMap | null;
52
53
  emitter: Emitter<BluxEventMap>;
53
54
  auth?: IAuth;
54
55
  config: IInternalConfig;
@@ -80,6 +81,9 @@ export interface IStoreProperties {
80
81
  transactions: UseTransactionsResult;
81
82
  selectAsset: ISelectAsset;
82
83
  detailsAsset?: IAsset;
84
+ customTokens: ICustomTokens;
85
+ balancesTab: 'assets' | 'tokens';
86
+ detailsToken?: ICustomToken;
83
87
  walletConnect?: {
84
88
  connection: any;
85
89
  client: SignClient;
@@ -110,6 +114,12 @@ export interface IStoreMethods {
110
114
  setBalanceValues: (balanceValues: Record<string, string>) => void;
111
115
  setSelectAsset: (selectAsset: ISelectAsset) => void;
112
116
  setDetailsAsset: (asset: IAsset | undefined) => void;
117
+ setCustomTokens: (customTokens: ICustomTokens) => void;
118
+ addCustomToken: (token: ICustomToken) => void;
119
+ removeCustomToken: (network: 'mainnet' | 'testnet', id: number) => void;
120
+ setCustomTokenBalances: (network: 'mainnet' | 'testnet', balances: Record<number, string>) => void;
121
+ setBalancesTab: (tab: 'assets' | 'tokens') => void;
122
+ setDetailsToken: (token: ICustomToken | undefined) => void;
113
123
  setTransactions: (transactions: UseTransactionsResult) => void;
114
124
  setWalletConnectClient: (client: SignClient, connection: any) => void;
115
125
  cleanUp: (method: 'sendTransaction' | 'signMessage') => void;
@@ -121,6 +131,7 @@ export interface IStoreMethods {
121
131
  setLogin: (loginDetails: ILoginPromise | undefined) => void;
122
132
  setLoginError: (message?: string) => void;
123
133
  setLogos: (logos: ILogo[]) => void;
134
+ setAssetMeta: (assetMeta: AssetMetaMap) => void;
124
135
  }
125
136
  export interface IStore extends IStoreProperties, IStoreMethods {
126
137
  }
package/dist/types.d.ts CHANGED
@@ -156,6 +156,49 @@ export interface IAsset {
156
156
  assetType: string;
157
157
  assetIssuer: string;
158
158
  }
159
+ /**
160
+ * Display metadata for a single asset, sourced from curated SEP-42 asset lists
161
+ * (Lobstr, StellarExpert, Soroswap) and served as a gzipped blob from R2.
162
+ */
163
+ export interface IAssetMeta {
164
+ code: string;
165
+ issuer: string | null;
166
+ contract: string | null;
167
+ name: string;
168
+ org: string | null;
169
+ domain: string | null;
170
+ /** HTTPS (or IPFS gateway) URL of the asset logo. */
171
+ icon: string;
172
+ decimals: number;
173
+ /** Which curated list this entry came from. */
174
+ source: string;
175
+ }
176
+ /** Asset metadata keyed by `${network}:${code}:${issuer}` (e.g. `pubnet:USDC:GA5Z...`). */
177
+ export type AssetMetaMap = Record<string, IAssetMeta>;
178
+ /**
179
+ * A custom Stellar Asset Contract (SAC) / SEP-41 token the user added to their
180
+ * preferred list. The id/contract/name/symbol/decimals come from the Blux API
181
+ * (`TokenView`); `balance` is read on-chain for the logged-in account (the API
182
+ * does not store balances). The API only buckets tokens by `mainnet`/`testnet`.
183
+ */
184
+ export interface ICustomToken {
185
+ /** Server-side id, used for the DELETE route. */
186
+ id: number;
187
+ /** Token contract id (`C...`). */
188
+ contractAddress: string;
189
+ /** API network bucket this token belongs to. */
190
+ network: 'mainnet' | 'testnet';
191
+ name: string;
192
+ symbol: string;
193
+ decimals: number;
194
+ /** Human-readable on-chain balance for the logged-in account; `'0'` until read. */
195
+ balance: string;
196
+ }
197
+ /** Custom tokens grouped by the two network buckets the Blux API supports. */
198
+ export interface ICustomTokens {
199
+ mainnet: ICustomToken[];
200
+ testnet: ICustomToken[];
201
+ }
159
202
  export interface ISignOptions {
160
203
  network: string;
161
204
  }
@@ -25,4 +25,21 @@ type ApiGetUserResponse = {
25
25
  export declare const apiGetUser: (JWT: string) => Promise<ApiGetUserResponse>;
26
26
  export declare const apiSignMessage: (JWT: string, message: string) => Promise<string>;
27
27
  export declare const apiSignTransaction: (JWT: string, xdr: string, network: string) => Promise<string>;
28
+ /** Mirrors the API's `TokenView`. The API only buckets tokens mainnet/testnet. */
29
+ export type ApiTokenView = {
30
+ id: number;
31
+ contract_address: string;
32
+ network: string;
33
+ name: string;
34
+ symbol: string;
35
+ decimals: number;
36
+ };
37
+ /** GET /tokens result: the user's tokens grouped per network bucket. */
38
+ export type ApiGroupedTokens = {
39
+ mainnet: ApiTokenView[];
40
+ testnet: ApiTokenView[];
41
+ };
42
+ export declare const apiGetTokens: (JWT: string) => Promise<ApiGroupedTokens>;
43
+ export declare const apiAddToken: (JWT: string, contractAddress: string, network: "mainnet" | "testnet") => Promise<ApiTokenView>;
44
+ export declare const apiDeleteToken: (JWT: string, tokenId: number) => Promise<boolean>;
28
45
  export {};
@@ -0,0 +1,78 @@
1
+ import { ICustomToken } from '../types';
2
+ import { ApiTokenView } from './api';
3
+ /**
4
+ * Maps a network passphrase to the API's token bucket. The Blux API only stores
5
+ * tokens for mainnet/testnet, so every non-public network maps to `'testnet'`
6
+ * (matching the curated-asset-meta convention in {@link networkSlug}).
7
+ */
8
+ export declare const apiNetworkSlug: (activeNetwork?: string) => "mainnet" | "testnet";
9
+ /**
10
+ * Converts a raw i128 token amount (as returned by `balance`) into a
11
+ * human-readable decimal string, without floating-point precision loss.
12
+ */
13
+ export declare const formatTokenAmount: (raw: string, decimals: number) => string;
14
+ /** A classic Stellar asset that a SAC wraps, derived from its on-chain `name()`. */
15
+ export type SacClassicAsset = {
16
+ type: 'native';
17
+ } | {
18
+ type: 'credit';
19
+ code: string;
20
+ issuer: string;
21
+ };
22
+ /**
23
+ * Derives the classic asset a Stellar Asset Contract wraps from its on-chain
24
+ * `name()`: a SAC reports `"native"` for XLM and `"CODE:ISSUER"` for credit
25
+ * assets (e.g. `"USDC:GBBD…"`). Returns `null` for a non-SAC custom token, whose
26
+ * `name()` is a free-form string. Used both to show a short name and to detect a
27
+ * token the user already holds as a classic asset.
28
+ */
29
+ export declare const sacToClassicAsset: (name: string) => SacClassicAsset | null;
30
+ /**
31
+ * A short, layout-safe display name for a token. SAC-wrapped classic assets
32
+ * report `name()` as the long `"CODE:ISSUER"`, so fall back to the symbol; XLM
33
+ * reports `"native"`.
34
+ */
35
+ export declare const tokenDisplayName: (name: string, symbol: string) => string;
36
+ /**
37
+ * The `(code, issuer)` to feed AssetLogo so a SAC-wrapped classic asset resolves
38
+ * its real curated logo; non-classic tokens get an empty issuer and fall back to
39
+ * the generic icon. Never resolves to the native XLM / Stellar glyph.
40
+ */
41
+ export declare const tokenLogoAsset: (name: string, symbol: string) => {
42
+ code: string;
43
+ issuer: string;
44
+ };
45
+ /** The on-chain shape of a SAC / SEP-41 token, read by {@link readTokenOnChain}. */
46
+ export interface TokenOnChain {
47
+ name: string;
48
+ symbol: string;
49
+ decimals: number;
50
+ /** Raw i128 balance for `accountAddress`; `'0'` when no account was given. */
51
+ rawBalance: string;
52
+ /** Human-readable balance (`rawBalance` scaled by `decimals`). */
53
+ balance: string;
54
+ /** admin() (SACs) or owner() (custom tokens), whichever the contract exposes. */
55
+ adminOrOwner?: string;
56
+ }
57
+ /**
58
+ * Reads a token contract's on-chain state by simulating its read-only
59
+ * entrypoints — no account, signing, or fees required. `name`/`symbol`/
60
+ * `decimals` are the standard SEP-41 interface; `balance` is read for
61
+ * `accountAddress` when given; `adminOrOwner` is best-effort.
62
+ *
63
+ * @throws If `contractAddress` is not a contract id, or it is missing the
64
+ * standard `name`/`symbol`/`decimals` entrypoints (i.e. not a token).
65
+ */
66
+ export declare const readTokenOnChain: (contractAddress: string, accountAddress?: string, network?: string) => Promise<TokenOnChain>;
67
+ /**
68
+ * Reads just a token's `balance` for an account in a single simulation and
69
+ * formats it with an already-known `decimals` — far lighter than
70
+ * {@link readTokenOnChain} for the periodic balance refresh. Returns `'0'` on
71
+ * any failure so a single unreachable token can't break the others.
72
+ */
73
+ export declare const readTokenBalance: (contractAddress: string, accountAddress: string, decimals: number, network?: string) => Promise<string>;
74
+ /**
75
+ * Maps an API `TokenView` to the store's {@link ICustomToken}, attaching a
76
+ * (separately read) on-chain balance.
77
+ */
78
+ export declare const apiTokenToCustomToken: (view: ApiTokenView, balance?: string) => ICustomToken;
@@ -0,0 +1,5 @@
1
+ /** `pubnet` for Mainnet, `testnet` otherwise. The curated blob is Mainnet-only. */
2
+ export declare const networkSlug: (activeNetwork?: string) => string;
3
+ /** Lookup key into the asset-meta map, e.g. `pubnet:USDC:GA5Z...`. */
4
+ export declare const assetMetaKey: (activeNetwork: string | undefined, code: string, issuer: string) => string;
5
+ export declare const preloadAssetMeta: () => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluxcc/core",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "homepage": "https://blux.cc",
5
5
  "description": "Blux is a wallet infra for the Stellar network",
6
6
  "type": "module",