@naculus/connect-appkit-core 0.8.1 → 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.cjs CHANGED
@@ -1385,11 +1385,19 @@ function assetAddress(asset) {
1385
1385
  return asset.split(/[:/]/).at(-1);
1386
1386
  }
1387
1387
  function groupDigits(value) {
1388
- return value.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
1388
+ let out = "";
1389
+ for (let i = 0; i < value.length; i++)
1390
+ out += (i && (value.length - i) % 3 === 0 ? "," : "") + value[i];
1391
+ return out;
1392
+ }
1393
+ function trimTrailingZeros(value) {
1394
+ let end = value.length;
1395
+ while (value[end - 1] === "0") end--;
1396
+ return value.slice(0, end);
1389
1397
  }
1390
1398
  function formatAuthorizationAmount(amount, metadata) {
1391
1399
  const baseUnits = amount.toString();
1392
- if (!metadata || !metadata.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0) {
1400
+ if (!metadata || !metadata.symbol || !Number.isSafeInteger(metadata.decimals) || metadata.decimals < 0 || metadata.decimals > 255) {
1393
1401
  return {
1394
1402
  formatted: `${groupDigits(baseUnits)} base units`
1395
1403
  };
@@ -1397,7 +1405,7 @@ function formatAuthorizationAmount(amount, metadata) {
1397
1405
  const decimals = metadata.decimals;
1398
1406
  const padded = baseUnits.padStart(decimals + 1, "0");
1399
1407
  const integer = decimals === 0 ? padded : padded.slice(0, -decimals);
1400
- const fraction = decimals === 0 ? "" : padded.slice(-decimals).replace(/0+$/, "");
1408
+ const fraction = decimals === 0 ? "" : trimTrailingZeros(padded.slice(-decimals));
1401
1409
  const value = `${groupDigits(integer)}${fraction ? `.${fraction}` : ""}`;
1402
1410
  return { formatted: `${value} ${metadata.symbol}` };
1403
1411
  }
@@ -1406,10 +1414,13 @@ function relativeExpiry(expiresAt, now, locale) {
1406
1414
  const absolute = Math.abs(seconds);
1407
1415
  const divisor = absolute >= 31536e3 ? 31536e3 : absolute >= 2592e3 ? 2592e3 : absolute >= 86400 ? 86400 : absolute >= 3600 ? 3600 : absolute >= 60 ? 60 : 1;
1408
1416
  const unit = divisor === 31536e3 ? "year" : divisor === 2592e3 ? "month" : divisor === 86400 ? "day" : divisor === 3600 ? "hour" : divisor === 60 ? "minute" : "second";
1409
- return new Intl.RelativeTimeFormat(locale).format(
1410
- Math.round(seconds / divisor),
1411
- unit
1412
- );
1417
+ const value = Math.round(seconds / divisor);
1418
+ if (typeof Intl.RelativeTimeFormat !== "function") {
1419
+ const count = Math.abs(value);
1420
+ const phrase = `${count} ${unit}${count === 1 ? "" : "s"}`;
1421
+ return value < 0 || Object.is(value, -0) ? `${phrase} ago` : `in ${phrase}`;
1422
+ }
1423
+ return new Intl.RelativeTimeFormat(locale).format(value, unit);
1413
1424
  }
1414
1425
  function describeAuthorization(input, options = {}) {
1415
1426
  const now = options.now ?? Math.floor(Date.now() / 1e3);