@getalby/lightning-tools 6.0.0 → 6.1.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/esm/fiat.js CHANGED
@@ -1,4 +1,24 @@
1
1
  const numSatsInBtc = 100000000;
2
+ const getFiatCurrencies = async () => {
3
+ const url = "https://getalby.com/api/rates";
4
+ const response = await fetch(url);
5
+ if (!response.ok) {
6
+ throw new Error(`Failed to fetch currencies: ${response.status} ${response.statusText}`);
7
+ }
8
+ const data = await response.json();
9
+ const mappedCurrencies = Object.entries(data)
10
+ .filter(([code]) => code.toUpperCase() !== "BTC")
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ .map(([code, details]) => ({
13
+ code: code.toUpperCase(),
14
+ name: details.name,
15
+ priority: details.priority,
16
+ symbol: details.symbol,
17
+ }))
18
+ .sort((a, b) => a.name.localeCompare(b.name))
19
+ .sort((a, b) => a.priority - b.priority);
20
+ return mappedCurrencies;
21
+ };
2
22
  const getFiatBtcRate = async (currency) => {
3
23
  const url = "https://getalby.com/api/rates/" + currency.toLowerCase() + ".json";
4
24
  const response = await fetch(url);
@@ -27,5 +47,5 @@ const getFormattedFiatValue = async ({ satoshi, currency, locale, }) => {
27
47
  });
28
48
  };
29
49
 
30
- export { getFiatBtcRate, getFiatValue, getFormattedFiatValue, getSatoshiValue };
50
+ export { getFiatBtcRate, getFiatCurrencies, getFiatValue, getFormattedFiatValue, getSatoshiValue };
31
51
  //# sourceMappingURL=fiat.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fiat.js","sources":["../../src/fiat/fiat.ts"],"sourcesContent":["const numSatsInBtc = 100_000_000;\n\nexport const getFiatBtcRate = async (currency: string): Promise<number> => {\n const url =\n \"https://getalby.com/api/rates/\" + currency.toLowerCase() + \".json\";\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch rate: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n return data.rate_float / numSatsInBtc;\n};\n\nexport const getFiatValue = async ({\n satoshi,\n currency,\n}: {\n satoshi: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Number(satoshi) * rate;\n};\n\nexport const getSatoshiValue = async ({\n amount,\n currency,\n}: {\n amount: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Math.floor(Number(amount) / rate);\n};\n\nexport const getFormattedFiatValue = async ({\n satoshi,\n currency,\n locale,\n}: {\n satoshi: number | string;\n currency: string;\n locale: string;\n}) => {\n if (!locale) {\n locale = \"en\";\n }\n const fiatValue = await getFiatValue({ satoshi, currency });\n return fiatValue.toLocaleString(locale, {\n style: \"currency\",\n currency,\n });\n};\n"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,SAAW;MAEnB,cAAc,GAAG,OAAO,QAAgB,KAAqB;IACxE,MAAM,GAAG,GACP,gCAAgC,GAAG,QAAQ,CAAC,WAAW,EAAE,GAAG,OAAO;AACrE,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;AAEjC,IAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CACb,CAAA,sBAAA,EAAyB,QAAQ,CAAC,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAC,UAAU,CAAA,CAAE,CAClE;IACH;AAEA,IAAA,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;AAElC,IAAA,OAAO,IAAI,CAAC,UAAU,GAAG,YAAY;AACvC;AAEO,MAAM,YAAY,GAAG,OAAO,EACjC,OAAO,EACP,QAAQ,GAIT,KAAI;AACH,IAAA,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC;AAE3C,IAAA,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI;AAC/B;AAEO,MAAM,eAAe,GAAG,OAAO,EACpC,MAAM,EACN,QAAQ,GAIT,KAAI;AACH,IAAA,MAAM,IAAI,GAAG,MAAM,cAAc,CAAC,QAAQ,CAAC;IAE3C,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;AAC1C;AAEO,MAAM,qBAAqB,GAAG,OAAO,EAC1C,OAAO,EACP,QAAQ,EACR,MAAM,GAKP,KAAI;IACH,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,IAAI;IACf;IACA,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC3D,IAAA,OAAO,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE;AACtC,QAAA,KAAK,EAAE,UAAU;QACjB,QAAQ;AACT,KAAA,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"fiat.js","sources":["../../src/fiat/fiat.ts"],"sourcesContent":["const numSatsInBtc = 100_000_000;\n\nexport interface FiatCurrency {\n code: string;\n name: string;\n symbol: string;\n priority: number;\n}\n\nexport const getFiatCurrencies = async (): Promise<FiatCurrency[]> => {\n const url = \"https://getalby.com/api/rates\";\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch currencies: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n const mappedCurrencies: FiatCurrency[] = Object.entries(data)\n .filter(([code]) => code.toUpperCase() !== \"BTC\")\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n .map(([code, details]: any) => ({\n code: code.toUpperCase(),\n name: details.name,\n priority: details.priority,\n symbol: details.symbol,\n }))\n .sort((a, b) => a.name.localeCompare(b.name))\n .sort((a, b) => a.priority - b.priority) as FiatCurrency[];\n\n return mappedCurrencies;\n};\n\nexport const getFiatBtcRate = async (currency: string): Promise<number> => {\n const url =\n \"https://getalby.com/api/rates/\" + currency.toLowerCase() + \".json\";\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch rate: ${response.status} ${response.statusText}`,\n );\n }\n\n const data = await response.json();\n\n return data.rate_float / numSatsInBtc;\n};\n\nexport const getFiatValue = async ({\n satoshi,\n currency,\n}: {\n satoshi: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Number(satoshi) * rate;\n};\n\nexport const getSatoshiValue = async ({\n amount,\n currency,\n}: {\n amount: number | string;\n currency: string;\n}) => {\n const rate = await getFiatBtcRate(currency);\n\n return Math.floor(Number(amount) / rate);\n};\n\nexport const getFormattedFiatValue = async ({\n satoshi,\n currency,\n locale,\n}: {\n satoshi: number | string;\n currency: string;\n locale: string;\n}) => {\n if (!locale) {\n locale = \"en\";\n }\n const fiatValue = await getFiatValue({ satoshi, currency });\n return fiatValue.toLocaleString(locale, {\n style: \"currency\",\n currency,\n });\n};\n"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,SAAW;AASzB,MAAM,iBAAiB,GAAG,YAAoC;IACnE,MAAM,GAAG,GAAG,+BAA+B;AAC3C,IAAA,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC;AAEjC,IAAA,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;AAChB,QAAA,MAAM,IAAI,KAAK,CACb,CAAA,4BAAA,EAA+B,QAAQ,CAAC,MAAM,CAAA,CAAA,EAAI,QAAQ,CAAC,UAAU,CAAA,CAAE,CACxE;IACH;AAEA,IAAA,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE;AAClC,IAAA,MAAM,gBAAgB,GAAmB,MAAM,CAAC,OAAO,CAAC,IAAI;AACzD,SAAA,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK;;SAE/C,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAM,MAAM;AAC9B,QAAA,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE;QACxB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,OAAO,C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AC1C,OAAO,EACP,QAAQ,EACR,MAAM,GAKP,KAAI;IACH,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,GAAG,IAAI;IACf;IACA,MAAM,SAAS,GAAG,MAAM,YAAY,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAC3D,IAAA,OAAO,SAAS,CAAC,cAAc,CAAC,MAAM,EAAE;AACtC,QAAA,KAAK,EAAE,UAAU;QACjB,QAAQ;AACT,KAAA,CAAC;AACJ;;;;"}
package/dist/esm/index.js CHANGED
@@ -1740,6 +1740,26 @@ const fetchWithL402 = async (url, fetchArgs, options) => {
1740
1740
  };
1741
1741
 
1742
1742
  const numSatsInBtc = 100000000;
1743
+ const getFiatCurrencies = async () => {
1744
+ const url = "https://getalby.com/api/rates";
1745
+ const response = await fetch(url);
1746
+ if (!response.ok) {
1747
+ throw new Error(`Failed to fetch currencies: ${response.status} ${response.statusText}`);
1748
+ }
1749
+ const data = await response.json();
1750
+ const mappedCurrencies = Object.entries(data)
1751
+ .filter(([code]) => code.toUpperCase() !== "BTC")
1752
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1753
+ .map(([code, details]) => ({
1754
+ code: code.toUpperCase(),
1755
+ name: details.name,
1756
+ priority: details.priority,
1757
+ symbol: details.symbol,
1758
+ }))
1759
+ .sort((a, b) => a.name.localeCompare(b.name))
1760
+ .sort((a, b) => a.priority - b.priority);
1761
+ return mappedCurrencies;
1762
+ };
1743
1763
  const getFiatBtcRate = async (currency) => {
1744
1764
  const url = "https://getalby.com/api/rates/" + currency.toLowerCase() + ".json";
1745
1765
  const response = await fetch(url);
@@ -1768,5 +1788,5 @@ const getFormattedFiatValue = async ({ satoshi, currency, locale, }) => {
1768
1788
  });
1769
1789
  };
1770
1790
 
1771
- export { DEFAULT_PROXY, Invoice, LN_ADDRESS_REGEX, LightningAddress, MemoryStorage, NoStorage, decodeInvoice, fetchWithL402, fromHexString, generateZapEvent, getEventHash, getFiatBtcRate, getFiatValue, getFormattedFiatValue, getSatoshiValue, isUrl, isValidAmount, parseKeysendResponse, parseL402, parseLnUrlPayResponse, parseNostrResponse, sendBoostagram, serializeEvent, validateEvent };
1791
+ export { DEFAULT_PROXY, Invoice, LN_ADDRESS_REGEX, LightningAddress, MemoryStorage, NoStorage, decodeInvoice, fetchWithL402, fromHexString, generateZapEvent, getEventHash, getFiatBtcRate, getFiatCurrencies, getFiatValue, getFormattedFiatValue, getSatoshiValue, isUrl, isValidAmount, parseKeysendResponse, parseL402, parseLnUrlPayResponse, parseNostrResponse, sendBoostagram, serializeEvent, validateEvent };
1772
1792
  //# sourceMappingURL=index.js.map