astra-modal-test 1.0.8 → 1.0.9
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/dist/{SwapController-CDa6lMYy.js → SwapController-rSbURdpJ.js} +1 -1
- package/dist/{add-xF_ArAzf.js → add-CpqI0qih.js} +1 -1
- package/dist/{all-wallets-Ce6u9aar.js → all-wallets-BCS6tMyX.js} +1 -1
- package/dist/{app-store-BSB6s3ao.js → app-store-BJcpQsmn.js} +1 -1
- package/dist/{apple-5FMqwZ50.js → apple-BYXq8xra.js} +1 -1
- package/dist/{arrow-bottom-UI4iKSwb.js → arrow-bottom-DyDya01u.js} +1 -1
- package/dist/{arrow-bottom-circle-jiPRKg_i.js → arrow-bottom-circle-7zz6Cez4.js} +1 -1
- package/dist/{arrow-left-vWFYC_Uy.js → arrow-left-DFjTrDxq.js} +1 -1
- package/dist/{arrow-right-RDYl_d9f.js → arrow-right-BeKBpPGZ.js} +1 -1
- package/dist/{arrow-top-CFdymIsb.js → arrow-top-C8kkMQwd.js} +1 -1
- package/dist/astra-sdk.es.js +1 -1
- package/dist/{bank-B6Ywh_tB.js → bank-FSmmDSOr.js} +1 -1
- package/dist/{bin-Das2naOJ.js → bin-BxSWmf4U.js} +1 -1
- package/dist/{bitcoin-cEJe5mt0.js → bitcoin-DOtAY1tg.js} +1 -1
- package/dist/{browser-BdXpj-Hv.js → browser-CxU-j1-l.js} +1 -1
- package/dist/{card-C1ElQWBR.js → card-CjYkck9C.js} +1 -1
- package/dist/{ccip-xelHOcyN.js → ccip-Dzjn7iUj.js} +1 -1
- package/dist/{checkmark-CoMIwXfk.js → checkmark-BQzWjMBG.js} +1 -1
- package/dist/{checkmark-bold-Cw14vvfX.js → checkmark-bold-CydTLhCY.js} +1 -1
- package/dist/{chevron-bottom-BIpRQPXG.js → chevron-bottom-CA607zpT.js} +1 -1
- package/dist/{chevron-left-Ba9KSrTt.js → chevron-left-BGmBZSZo.js} +1 -1
- package/dist/{chevron-right-DiRY5RBl.js → chevron-right-NBRpcLa8.js} +1 -1
- package/dist/{chevron-top-D63uD3sz.js → chevron-top-Cw5I5ZOR.js} +1 -1
- package/dist/{chrome-store-CDMywF6G.js → chrome-store-Bg96vfCc.js} +1 -1
- package/dist/{circle-RKQpGmr7.js → circle-D_QW929y.js} +1 -1
- package/dist/{clock-DLLB40xi.js → clock-o4gqCbWO.js} +1 -1
- package/dist/{close-r9wJQIs6.js → close-z2Y-xc4H.js} +1 -1
- package/dist/{coinPlaceholder-DwEAr3DY.js → coinPlaceholder-D_9U8ws8.js} +1 -1
- package/dist/{compass-DNvmj1tj.js → compass-BVM30Hj-.js} +1 -1
- package/dist/{copy-CMAbqfSd.js → copy-BvKR_En_.js} +1 -1
- package/dist/{cursor-C1UG5uSa.js → cursor-DKFz2C-k.js} +1 -1
- package/dist/{cursor-transparent-gRO-kv14.js → cursor-transparent-DwsHTJdY.js} +1 -1
- package/dist/{desktop-USBykYXc.js → desktop-_hiZGUrG.js} +1 -1
- package/dist/{disconnect-gXgOnS1O.js → disconnect-DbmK87x7.js} +1 -1
- package/dist/{discord-BoVW92xx.js → discord-CGEs_Ewv.js} +1 -1
- package/dist/{email-MUGxDZyn.js → email-B64OZpkU.js} +1 -1
- package/dist/{embedded-wallet-wtFatZbn.js → embedded-wallet-CdFJiA0M.js} +1 -1
- package/dist/{ethereum-CrlKIxWS.js → ethereum-ByYB2hkU.js} +1 -1
- package/dist/{etherscan-B7rldLcE.js → etherscan-BbjvIHaL.js} +1 -1
- package/dist/{exclamation-triangle-DkWjxCXA.js → exclamation-triangle-CdD-9Mg9.js} +1 -1
- package/dist/{extension-Cc-fkUZ4.js → extension-CwWz_fIf.js} +1 -1
- package/dist/{external-link-BGpONWeJ.js → external-link-B-H5cp6t.js} +1 -1
- package/dist/{facebook-WtT1OR1K.js → facebook-BCVDL-tg.js} +1 -1
- package/dist/{farcaster-XYlVovPm.js → farcaster-jtO1GaIa.js} +1 -1
- package/dist/{filters-BHJQ4Xxm.js → filters-D-d663Tl.js} +1 -1
- package/dist/{github-BrLDodDi.js → github-GYbnMtDL.js} +1 -1
- package/dist/{google-DyLvy2-l.js → google-D0T6MiMp.js} +1 -1
- package/dist/{help-circle-DSrnsOz5.js → help-circle-S_PJYnAb.js} +1 -1
- package/dist/{id-hq9eJ4Qc.js → id-ovWduNYl.js} +1 -1
- package/dist/{image-BSNbjEuh.js → image-DWMmztGY.js} +1 -1
- package/dist/{index-BAAVr7gv.js → index-3RuZHNxg.js} +1 -1
- package/dist/{index-1xpIFQ10.js → index-BrVBbGpA.js} +1 -1
- package/dist/{index-BSaELrPQ.js → index-CJ7s8Rmk.js} +6 -6
- package/dist/{index-BBtSm4ym.js → index-CTtOlAw3.js} +1 -1
- package/dist/{index-j1CHbogh.js → index-CXZjl-KY.js} +1 -1
- package/dist/{index-DAggWyCU.js → index-D49QXkg7.js} +1 -1
- package/dist/{index-D0yTNAa2.js → index-DEIfu1o6.js} +1 -1
- package/dist/{index-DLgq0XCK.js → index-DpJh5yXk.js} +5326 -5266
- package/dist/{index-CjuYAla0.js → index-Dv7m_bJu.js} +1 -1
- package/dist/{index-DKXwTi_4.js → index-RJEV23nN.js} +1 -1
- package/dist/{info-Dwz6bnKI.js → info-B_t5Wxs5.js} +1 -1
- package/dist/{info-circle-Dlv6yGm-.js → info-circle-BE3c4h9q.js} +1 -1
- package/dist/{lightbulb-B22koKw9.js → lightbulb-WY74qWMh.js} +1 -1
- package/dist/{mail-CTfIfuUf.js → mail-BZffBQJn.js} +1 -1
- package/dist/{mobile-CXKePK9r.js → mobile-BzoKYXrP.js} +1 -1
- package/dist/{more-BAc1_O1l.js → more-DLl0U_yq.js} +1 -1
- package/dist/{network-placeholder-DQimEkgX.js → network-placeholder-GUlJsW90.js} +1 -1
- package/dist/{nftPlaceholder-TmxwESKA.js → nftPlaceholder-URobOrrj.js} +1 -1
- package/dist/{off-BEIz28wS.js → off-Dd3KIizg.js} +1 -1
- package/dist/{onramp-CDGUJxkp.js → onramp-D3nPDHgs.js} +1 -1
- package/dist/{play-store-7v3FRGPC.js → play-store-DQcCWm53.js} +1 -1
- package/dist/{plus-DgWZStdP.js → plus-CBsitvpf.js} +1 -1
- package/dist/{qr-code-Za-zeUy1.js → qr-code-BLKOY5TH.js} +1 -1
- package/dist/{receive-BvZ2zsvF.js → receive-Cs7OrQ5H.js} +1 -1
- package/dist/{recycle-horizontal-D6nbmPsy.js → recycle-horizontal-DA3_DhRi.js} +1 -1
- package/dist/{refresh-CB3gA1em.js → refresh-DA83X8jf.js} +1 -1
- package/dist/{reown-logo-xKt4nApt.js → reown-logo-CYujsMCS.js} +1 -1
- package/dist/{search-B5scACGZ.js → search-dhyszWwL.js} +1 -1
- package/dist/{secp256k1-BS_H6cc8.js → secp256k1-BzR-XYTV.js} +1 -1
- package/dist/{send-D1BZuohM.js → send-Dio4rhmI.js} +3 -3
- package/dist/{send-CPH_rRYi.js → send-Djdyyp-y.js} +1 -1
- package/dist/{socials-BJX4OF48.js → socials-CyiUMsk1.js} +1 -1
- package/dist/{solana-T53kr1IG.js → solana-B01U90Av.js} +1 -1
- package/dist/{swapHorizontal-CaqxaS7f.js → swapHorizontal-BazEPj1l.js} +1 -1
- package/dist/{swapHorizontalBold-Sig9ZLtj.js → swapHorizontalBold-DOjBCDPH.js} +1 -1
- package/dist/{swapHorizontalMedium-BRczHHwL.js → swapHorizontalMedium-Bp7rqwQ_.js} +1 -1
- package/dist/{swapHorizontalRoundedBold-BpdCU9Bp.js → swapHorizontalRoundedBold-fXXQeesr.js} +1 -1
- package/dist/{swapVertical-vOPpeKvX.js → swapVertical-lb6FRfr-.js} +1 -1
- package/dist/{swaps-BLkPFWh6.js → swaps-DXWgEjt_.js} +3 -3
- package/dist/{telegram-muGVhw5Y.js → telegram-Cw3woU3F.js} +1 -1
- package/dist/{three-dots-BsyVBW01.js → three-dots-CrS1ZJoA.js} +1 -1
- package/dist/{transactions-BOv1jcPD.js → transactions-ClKYRDBc.js} +1 -1
- package/dist/{twitch-DnFvNzNv.js → twitch-BTFS8sbh.js} +1 -1
- package/dist/{twitterIcon--wOgsps0.js → twitterIcon-BEey2zuH.js} +1 -1
- package/dist/{ui-BUY2qZV0.js → ui-xSZiungl.js} +2 -2
- package/dist/{user-Y3D7wRs8.js → user-fcwj6TqA.js} +1 -1
- package/dist/{verify-C3Wv-vWi.js → verify-BLatL5Dw.js} +1 -1
- package/dist/{verify-filled-Dy1sirT4.js → verify-filled-DPYDyDVg.js} +1 -1
- package/dist/{w3m-modal-Bw-dR_fI.js → w3m-modal-IpSIarQs.js} +2 -2
- package/dist/{wallet-BcaN7X2R.js → wallet-Cgmznx42.js} +1 -1
- package/dist/{wallet-placeholder-JKwOItCz.js → wallet-placeholder-B7P5m3g1.js} +1 -1
- package/dist/{walletconnect-DT2QhxnA.js → walletconnect-DPJfWPxF.js} +1 -1
- package/dist/{warning-circle-D-vheGlH.js → warning-circle-yU7or6qZ.js} +1 -1
- package/dist/{x-DzCcyciF.js → x-Cr3BPl_T.js} +1 -1
- package/dist/{x-mark-BaQ2cTjZ.js → x-mark-CZyZTZeg.js} +1 -1
- package/package.json +1 -1
- package/src/comps/ToLightning.jsx +40 -4
- package/src/comps/ToToken.jsx +40 -4
- package/src/index.jsx +9 -1
- package/src/main.jsx +7 -4
- package/src/utils/index.js +128 -9
package/src/utils/index.js
CHANGED
|
@@ -87,17 +87,122 @@ export const toBytes32 = (value) => {
|
|
|
87
87
|
|
|
88
88
|
return hash;
|
|
89
89
|
};
|
|
90
|
+
/**
|
|
91
|
+
* 解析 Lightning Invoice,获取资产信息
|
|
92
|
+
* 使用后端 assetPayReq API 自动识别资产类型(RGB、Taproot Asset 或 BTC)
|
|
93
|
+
* @param {string} payReq - Lightning Invoice 字符串
|
|
94
|
+
* @param {string} assetId - 可选,指定资产 ID。如果不传入,后端会自动识别
|
|
95
|
+
* @returns {Promise<{amount: string, assetId: string, decimal: number}>}
|
|
96
|
+
*/
|
|
90
97
|
export const invoiceToAssetInfo = async ({ payReq, assetId }) => {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
try {
|
|
99
|
+
// 调用后端 API,后端会自动识别资产类型(RGB/Taproot/BTC)
|
|
100
|
+
const ret = await getAssetPayReq({ payReq: payReq, assetId: assetId });
|
|
101
|
+
const { amount, decimal, asset_id } = ret.data;
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
amount: amount, // 使用后端返回的精确金额
|
|
105
|
+
assetId: asset_id || assetId, // 优先使用后端返回的 asset_id(支持自动识别)
|
|
106
|
+
decimal: decimal,
|
|
107
|
+
};
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error("Failed to parse invoice:", error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
100
112
|
};
|
|
113
|
+
/**
|
|
114
|
+
* 校验资产是否在交易对列表中支持
|
|
115
|
+
* @param {string} assetId - 资产 ID(如 BTC、Taproot Asset ID、RGB Asset ID)
|
|
116
|
+
* @param {Array} allAssetPairs - 所有交易对列表
|
|
117
|
+
* @returns {{isSupported: boolean, supportedPairs: Array, error: string|null}}
|
|
118
|
+
*/
|
|
119
|
+
export function validateAssetSupport(assetId, allAssetPairs) {
|
|
120
|
+
if (!assetId) {
|
|
121
|
+
return {
|
|
122
|
+
isSupported: false,
|
|
123
|
+
supportedPairs: [],
|
|
124
|
+
error: "Asset ID is required",
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!allAssetPairs || allAssetPairs.length === 0) {
|
|
129
|
+
return {
|
|
130
|
+
isSupported: false,
|
|
131
|
+
supportedPairs: [],
|
|
132
|
+
error: "No trading pairs available. Please wait for pairs to load.",
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 查找支持该 asset_id 的交易对
|
|
137
|
+
const supportedPairs = allAssetPairs.filter(
|
|
138
|
+
(pair) => pair?.asset?.assetId === assetId
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (supportedPairs.length === 0) {
|
|
142
|
+
const supportedAssetIds = allAssetPairs
|
|
143
|
+
.map((pair) => pair?.asset?.assetId)
|
|
144
|
+
.filter(Boolean);
|
|
145
|
+
return {
|
|
146
|
+
isSupported: false,
|
|
147
|
+
supportedPairs: [],
|
|
148
|
+
error: `Asset "${assetId}" is not supported. Supported assets: ${supportedAssetIds.join(", ")}`,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
isSupported: true,
|
|
154
|
+
supportedPairs,
|
|
155
|
+
error: null,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* 校验 token 地址是否在交易对列表中支持
|
|
161
|
+
* @param {string} tokenAddress - Token 合约地址
|
|
162
|
+
* @param {Array} allAssetPairs - 所有交易对列表
|
|
163
|
+
* @returns {{isSupported: boolean, supportedPairs: Array, error: string|null}}
|
|
164
|
+
*/
|
|
165
|
+
export function validateTokenSupport(tokenAddress, allAssetPairs) {
|
|
166
|
+
if (!tokenAddress) {
|
|
167
|
+
return {
|
|
168
|
+
isSupported: false,
|
|
169
|
+
supportedPairs: [],
|
|
170
|
+
error: "Token address is required",
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!allAssetPairs || allAssetPairs.length === 0) {
|
|
175
|
+
return {
|
|
176
|
+
isSupported: false,
|
|
177
|
+
supportedPairs: [],
|
|
178
|
+
error: "No trading pairs available. Please wait for pairs to load.",
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 查找支持该 token 地址的交易对(不区分大小写)
|
|
183
|
+
const normalizedAddress = tokenAddress.toLowerCase();
|
|
184
|
+
const supportedPairs = allAssetPairs.filter(
|
|
185
|
+
(pair) => pair?.token?.address?.toLowerCase() === normalizedAddress
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (supportedPairs.length === 0) {
|
|
189
|
+
const supportedTokens = allAssetPairs
|
|
190
|
+
.map((pair) => pair?.token?.address)
|
|
191
|
+
.filter(Boolean);
|
|
192
|
+
return {
|
|
193
|
+
isSupported: false,
|
|
194
|
+
supportedPairs: [],
|
|
195
|
+
error: `Token "${tokenAddress}" is not supported. Supported tokens: ${supportedTokens.join(", ")}`,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
isSupported: true,
|
|
201
|
+
supportedPairs,
|
|
202
|
+
error: null,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
101
206
|
export function balanceToFixed(balance, decimals) {
|
|
102
207
|
const fixedBalance = balance
|
|
103
208
|
? new Decimal(balance)
|
|
@@ -107,7 +212,21 @@ export function balanceToFixed(balance, decimals) {
|
|
|
107
212
|
: 0;
|
|
108
213
|
return fixedBalance;
|
|
109
214
|
}
|
|
215
|
+
/**
|
|
216
|
+
* @deprecated 此函数已废弃,建议使用 invoiceToAssetInfo 代替
|
|
217
|
+
* 提取 invoice 中的资产信息(从 memo/description 解析)
|
|
218
|
+
*
|
|
219
|
+
* 废弃原因:
|
|
220
|
+
* 1. 依赖 memo 格式,不够稳定
|
|
221
|
+
* 2. 无法支持 RGB 资产
|
|
222
|
+
* 3. 后端 API 已支持自动识别资产类型,更准确
|
|
223
|
+
*
|
|
224
|
+
* @param {string} inputString - invoice description 字符串
|
|
225
|
+
* @returns {{assetID: string|null, amount: string|null}}
|
|
226
|
+
*/
|
|
110
227
|
export function extractAssetInfo(inputString) {
|
|
228
|
+
console.warn("⚠️ extractAssetInfo is deprecated. Use invoiceToAssetInfo instead.");
|
|
229
|
+
|
|
111
230
|
const result = {
|
|
112
231
|
assetID: null,
|
|
113
232
|
amount: null,
|