@argent/x-shared 1.48.0 → 1.48.1

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("url-join"),a=require("../../../errors/swap.cjs"),p=require("../models/quote.model.cjs"),l=require("../utils/totalFee.cjs"),S=require("../models/trade.model.cjs"),i=require("../models/order.model.cjs"),d=require("../../../utils/url/urlWithQuery.cjs");class y{constructor(e,r){if(this.httpService=e,!r)throw new a.SwapError({code:"NO_SWAP_URL"});this.swapQuoteUrl=u(r,"/quote"),this.swapOrderUrl=u(r,"/order")}async getSwapQuoteForPay(e,r,o,n,t="USD"){const s=d.urlWithQuery(this.swapQuoteUrl,{accountAddress:n,currency:t,chain:"starknet",sellToken:e,buyToken:r,sellAmount:o});try{const c=await this.httpService.get(s);return await p.SwapQuoteResponseSchema.parseAsync(c)}catch(c){throw console.error(c),new a.SwapError({code:"INVALID_QUOTE_RESPONSE"})}}async getSwapTradeFromQuote(e,r,o){if(!r||!o)throw new a.SwapError({code:"INVALID_SWAP_TOKENS"});const{totalFee:n,totalFeeInCurrency:t,totalFeePercentage:s}=l.calculateTotalFee(e);return S.TradeSchema.parse({payToken:r,receiveToken:o,payAmount:e.sellAmount,receiveAmount:e.buyAmount,payAmountInCurrency:e.sellAmountInCurrency,receiveAmountInCurrency:e.buyAmountInCurrency,totalFee:n,totalFeeInCurrency:t,totalFeePercentage:s,expiresAt:e.expiresAt,expiresIn:e.expiresIn,route:e.routes[0],data:e.data})}async getSwapOrderFromTrade(e,r,o){const n=i.SwapOrderRequestSchema.parse({chain:"starknet",sellToken:r.payToken.address,buyToken:r.receiveToken.address,sellAmount:r.payAmount,buyAmount:r.receiveAmount,accountAddress:e,slippage:o/1e4,data:r.data});try{const t=await this.httpService.post(this.swapOrderUrl,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"}});return await i.SwapOrderResponseSchema.parseAsync(t)}catch(t){throw console.error(t),new a.SwapError({code:"INVALID_SWAP_ORDER_RESPONSE"})}}}exports.SharedSwapService=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("url-join"),a=require("../../../errors/swap.cjs"),p=require("../../../utils/url/urlWithQuery.cjs"),l=require("../models/quote.model.cjs"),S=require("../utils/totalFee.cjs"),d=require("../models/trade.model.cjs"),i=require("../models/order.model.cjs");class y{constructor(e,r){if(this.httpService=e,!r)throw new a.SwapError({code:"NO_SWAP_URL"});this.swapQuoteUrl=u(r,"/quote"),this.swapOrderUrl=u(r,"/order")}async getSwapQuoteForPay(e,r,o,n,t="USD"){const s=p.urlWithQuery(this.swapQuoteUrl,{accountAddress:n,currency:t,chain:"starknet",sellToken:e,buyToken:r,sellAmount:o});try{const c=await this.httpService.get(s);return await l.SwapQuoteResponseSchema.parseAsync(c)}catch(c){throw console.error(c),new a.SwapError({code:"INVALID_QUOTE_RESPONSE"})}}async getSwapTradeFromQuote(e,r,o){if(!r||!o)throw new a.SwapError({code:"INVALID_SWAP_TOKENS"});const{totalFee:n,totalFeeInCurrency:t,totalFeePercentage:s}=S.calculateTotalFee(e);return d.TradeSchema.parse({payToken:r,receiveToken:o,payAmount:e.sellAmount,receiveAmount:e.buyAmount,payAmountInCurrency:e.sellAmountInCurrency,receiveAmountInCurrency:e.buyAmountInCurrency,totalFee:n,totalFeeInCurrency:t,totalFeePercentage:s,expiresAt:e.expiresAt,expiresIn:e.expiresIn,route:e.routes[0],data:e.data})}async getSwapOrderFromTrade(e,r,o){const n=i.SwapOrderRequestSchema.parse({chain:"starknet",sellToken:r.payToken.address,buyToken:r.receiveToken.address,sellAmount:r.payAmount,buyAmount:r.receiveAmount,accountAddress:e,slippage:o/1e4,data:r.data});try{const t=await this.httpService.post(this.swapOrderUrl,{body:JSON.stringify(n),headers:{"Content-Type":"application/json"}});return await i.SwapOrderResponseSchema.parseAsync(t)}catch(t){throw console.error(t),new a.SwapError({code:"INVALID_SWAP_ORDER_RESPONSE"})}}}exports.SharedSwapService=y;
@@ -1,10 +1,10 @@
1
1
  import p from "url-join";
2
2
  import { SwapError as a } from "../../../errors/swap.js";
3
- import { SwapQuoteResponseSchema as i } from "../models/quote.model.js";
4
- import { calculateTotalFee as u } from "../utils/totalFee.js";
5
- import { TradeSchema as m } from "../models/trade.model.js";
6
- import { SwapOrderRequestSchema as l, SwapOrderResponseSchema as S } from "../models/order.model.js";
7
- import { urlWithQuery as y } from "../../../utils/url/urlWithQuery.js";
3
+ import { urlWithQuery as i } from "../../../utils/url/urlWithQuery.js";
4
+ import { SwapQuoteResponseSchema as u } from "../models/quote.model.js";
5
+ import { calculateTotalFee as m } from "../utils/totalFee.js";
6
+ import { TradeSchema as l } from "../models/trade.model.js";
7
+ import { SwapOrderRequestSchema as S, SwapOrderResponseSchema as y } from "../models/order.model.js";
8
8
  class _ {
9
9
  constructor(e, r) {
10
10
  if (this.httpService = e, !r)
@@ -12,7 +12,7 @@ class _ {
12
12
  this.swapQuoteUrl = p(r, "/quote"), this.swapOrderUrl = p(r, "/order");
13
13
  }
14
14
  async getSwapQuoteForPay(e, r, o, n, t = "USD") {
15
- const s = y(this.swapQuoteUrl, {
15
+ const s = i(this.swapQuoteUrl, {
16
16
  accountAddress: n,
17
17
  currency: t,
18
18
  chain: "starknet",
@@ -22,7 +22,7 @@ class _ {
22
22
  });
23
23
  try {
24
24
  const c = await this.httpService.get(s);
25
- return await i.parseAsync(c);
25
+ return await u.parseAsync(c);
26
26
  } catch (c) {
27
27
  throw console.error(c), new a({ code: "INVALID_QUOTE_RESPONSE" });
28
28
  }
@@ -30,8 +30,8 @@ class _ {
30
30
  async getSwapTradeFromQuote(e, r, o) {
31
31
  if (!r || !o)
32
32
  throw new a({ code: "INVALID_SWAP_TOKENS" });
33
- const { totalFee: n, totalFeeInCurrency: t, totalFeePercentage: s } = u(e);
34
- return m.parse({
33
+ const { totalFee: n, totalFeeInCurrency: t, totalFeePercentage: s } = m(e);
34
+ return l.parse({
35
35
  payToken: r,
36
36
  receiveToken: o,
37
37
  payAmount: e.sellAmount,
@@ -48,7 +48,7 @@ class _ {
48
48
  });
49
49
  }
50
50
  async getSwapOrderFromTrade(e, r, o) {
51
- const n = l.parse({
51
+ const n = S.parse({
52
52
  chain: "starknet",
53
53
  sellToken: r.payToken.address,
54
54
  buyToken: r.receiveToken.address,
@@ -65,7 +65,7 @@ class _ {
65
65
  "Content-Type": "application/json"
66
66
  }
67
67
  });
68
- return await S.parseAsync(t);
68
+ return await y.parseAsync(t);
69
69
  } catch (t) {
70
70
  throw console.error(t), new a({ code: "INVALID_SWAP_ORDER_RESPONSE" });
71
71
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../utils/number/prettifyNumber.cjs"),o=require("../utils/number/isNumeric.cjs"),n=(e,t="$",r)=>{if(e===void 0||!o.isNumeric(e))return null;const i=u.prettifyCurrencyNumber(e,r);return[t,i].filter(Boolean).join("")};exports.prettifyCurrencyValue=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../utils/number/prettifyNumber.cjs"),l=require("../utils/number/isNumeric.cjs"),s=(t,e="$",r)=>{if(t===void 0||!l.isNumeric(t))return null;const i=Number(t)<0,o=t.toString().replace("-",""),u=n.prettifyCurrencyNumber(o,r);return[i?"-":"",e,u].filter(Boolean).join("")};exports.prettifyCurrencyValue=s;
@@ -1,11 +1,15 @@
1
- import { prettifyCurrencyNumber as i } from "../utils/number/prettifyNumber.js";
2
- import { isNumeric as l } from "../utils/number/isNumeric.js";
3
- const u = (t, r = "$", e) => {
4
- if (t === void 0 || !l(t))
1
+ import { prettifyCurrencyNumber as n } from "../utils/number/prettifyNumber.js";
2
+ import { isNumeric as m } from "../utils/number/isNumeric.js";
3
+ const a = (t, e = "$", o) => {
4
+ if (t === void 0 || !m(t))
5
5
  return null;
6
- const o = i(t, e);
7
- return [r, o].filter(Boolean).join("");
6
+ const r = Number(t) < 0, i = t.toString().replace("-", ""), l = n(i, o);
7
+ return [
8
+ r ? "-" : "",
9
+ e,
10
+ l
11
+ ].filter(Boolean).join("");
8
12
  };
9
13
  export {
10
- u as prettifyCurrencyValue
14
+ a as prettifyCurrencyValue
11
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@argent/x-shared",
3
- "version": "1.48.0",
3
+ "version": "1.48.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/argentlabs/x-shared.git"