@naculus/connect-appkit-core 0.8.0 → 0.9.0

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/index.js CHANGED
@@ -1304,11 +1304,19 @@ function assetAddress(asset) {
1304
1304
  return asset.split(/[:/]/).at(-1);
1305
1305
  }
1306
1306
  function groupDigits(value) {
1307
- return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
1307
+ let out = "";
1308
+ for (let i = 0; i < value.length; i++)
1309
+ out += (i && (value.length - i) % 3 === 0 ? "," : "") + value[i];
1310
+ return out;
1311
+ }
1312
+ function trimTrailingZeros(value) {
1313
+ let end = value.length;
1314
+ while (value[end - 1] === "0") end--;
1315
+ return value.slice(0, end);
1308
1316
  }
1309
1317
  function formatAuthorizationAmount(amount, metadata) {
1310
1318
  const baseUnits = amount.toString();
1311
- if (!metadata || !metadata.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0) {
1319
+ if (!metadata || !metadata.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0 || metadata.decimals > 255) {
1312
1320
  return {
1313
1321
  formatted: `${groupDigits(baseUnits)} base units`
1314
1322
  };
@@ -1316,7 +1324,7 @@ function formatAuthorizationAmount(amount, metadata) {
1316
1324
  const decimals = metadata.decimals;
1317
1325
  const padded = baseUnits.padStart(decimals + 1, "0");
1318
1326
  const integer = decimals === 0 ? padded : padded.slice(0, -decimals);
1319
- const fraction = decimals === 0 ? "" : padded.slice(-decimals).replace(/0+$/, "");
1327
+ const fraction = decimals === 0 ? "" : trimTrailingZeros(padded.slice(-decimals));
1320
1328
  const value = `${groupDigits(integer)}${fraction ? `.${fraction}` : ""}`;
1321
1329
  return { formatted: `${value} ${metadata.symbol}` };
1322
1330
  }
@@ -1325,10 +1333,13 @@ function relativeExpiry(expiresAt, now, locale) {
1325
1333
  const absolute = Math.abs(seconds);
1326
1334
  const divisor = absolute >= 31536e3 ? 31536e3 : absolute >= 2592e3 ? 2592e3 : absolute >= 86400 ? 86400 : absolute >= 3600 ? 3600 : absolute >= 60 ? 60 : 1;
1327
1335
  const unit = divisor === 31536e3 ? "year" : divisor === 2592e3 ? "month" : divisor === 86400 ? "day" : divisor === 3600 ? "hour" : divisor === 60 ? "minute" : "second";
1328
- return new Intl.RelativeTimeFormat(locale).format(
1329
- Math.round(seconds / divisor),
1330
- unit
1331
- );
1336
+ const value = Math.round(seconds / divisor);
1337
+ if (typeof Intl.RelativeTimeFormat !== "function") {
1338
+ const count = Math.abs(value);
1339
+ const phrase = `${count} ${unit}${count === 1 ? "" : "s"}`;
1340
+ return value < 0 || Object.is(value, -0) ? `${phrase} ago` : `in ${phrase}`;
1341
+ }
1342
+ return new Intl.RelativeTimeFormat(locale).format(value, unit);
1332
1343
  }
1333
1344
  function describeAuthorization(input, options = {}) {
1334
1345
  const now = options.now ?? Math.floor(Date.now() / 1e3);