@swapkit/helpers
Advanced tools
Comparing version 1.0.0-rc.55 to 1.0.0-rc.56
@@ -13,3 +13,3 @@ var bt = Object.defineProperty; | ||
var m = (s, t, e) => (wt(s, t, "access private method"), e); | ||
import { FeeOption as U, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types"; | ||
import { FeeOption as L, BaseDecimal as d, Chain as o, EVMChainList as At, ChainToRPC as $t, MemoType as _ } from "@swapkit/types"; | ||
const vt = "0x313ce567", nt = async ({ chain: s, to: t }) => { | ||
@@ -39,6 +39,6 @@ try { | ||
return t != null && t.startsWith("0x") ? nt({ chain: o.Ethereum, to: t }) : d.ETH; | ||
}, Ct = async (s) => { | ||
}, Rt = async (s) => { | ||
const [, t] = s.split("-"); | ||
return t != null && t.startsWith("0x") ? nt({ chain: o.Avalanche, to: t.toLowerCase() }) : d.AVAX; | ||
}, Rt = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => { | ||
}, Ct = async (s) => s === o.BinanceSmartChain ? d.BSC : d.BSC, St = async ({ chain: s, symbol: t }) => { | ||
switch (s) { | ||
@@ -48,5 +48,5 @@ case o.Ethereum: | ||
case o.Avalanche: | ||
return Rt(t); | ||
case o.BinanceSmartChain: | ||
return Ct(t); | ||
case o.BinanceSmartChain: | ||
return Rt(t); | ||
default: | ||
@@ -56,5 +56,5 @@ return d[s]; | ||
}, ne = { | ||
[U.Average]: 1.2, | ||
[U.Fast]: 1.5, | ||
[U.Fastest]: 2 | ||
[L.Average]: 1.2, | ||
[L.Fast]: 1.5, | ||
[L.Fastest]: 2 | ||
}, it = ({ chain: s, symbol: t }) => { | ||
@@ -355,3 +355,3 @@ switch (s) { | ||
return t; | ||
}, Vt = (() => { | ||
}, Pt = (() => { | ||
let s = !1, t = !1; | ||
@@ -367,3 +367,3 @@ const e = typeof globalThis.ReadableStream == "function", r = typeof globalThis.Request == "function"; | ||
}).headers.has("Content-Type")), s && !t; | ||
})(), Pt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = { | ||
})(), Vt = typeof globalThis.AbortController == "function", kt = typeof globalThis.ReadableStream == "function", Nt = typeof globalThis.FormData == "function", ct = ["get", "post", "put", "patch", "head", "delete"], jt = { | ||
json: "application/json", | ||
@@ -374,3 +374,3 @@ text: "text/*", | ||
blob: "*/*" | ||
}, L = 2147483647, ut = Symbol("stop"), Ht = { | ||
}, U = 2147483647, ut = Symbol("stop"), Ht = { | ||
json: !0, | ||
@@ -402,5 +402,5 @@ parseJson: !0, | ||
duplex: !0 | ||
}, Ut = (s) => ct.includes(s) ? s.toUpperCase() : s, Lt = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = { | ||
}, Lt = (s) => ct.includes(s) ? s.toUpperCase() : s, Ut = ["get", "put", "head", "delete", "options", "trace"], Ft = [408, 413, 429, 500, 502, 503, 504], lt = [413, 429, 503], Z = { | ||
limit: 2, | ||
methods: Lt, | ||
methods: Ut, | ||
statusCodes: Ft, | ||
@@ -454,7 +454,7 @@ afterStatusCodes: lt, | ||
}; | ||
class P { | ||
class V { | ||
static create(t, e) { | ||
const r = new P(t, e), n = async () => { | ||
if (typeof r._options.timeout == "number" && r._options.timeout > L) | ||
throw new RangeError(`The \`timeout\` option cannot be greater than ${L}`); | ||
const r = new V(t, e), n = async () => { | ||
if (typeof r._options.timeout == "number" && r._options.timeout > U) | ||
throw new RangeError(`The \`timeout\` option cannot be greater than ${U}`); | ||
await Promise.resolve(); | ||
@@ -533,3 +533,3 @@ let a = await r._fetch(); | ||
}, e.hooks), | ||
method: Ut(e.method ?? this._input.method), | ||
method: Lt(e.method ?? this._input.method), | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing | ||
@@ -548,3 +548,3 @@ prefixUrl: String(e.prefixUrl || ""), | ||
} | ||
if (Pt) { | ||
if (Vt) { | ||
if (this.abortController = new globalThis.AbortController(), this._options.signal) { | ||
@@ -558,3 +558,3 @@ const r = this._options.signal; | ||
} | ||
if (Vt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) { | ||
if (Pt && (this._options.duplex = "half"), this.request = new globalThis.Request(this._input, this._options), this._options.searchParams) { | ||
const n = "?" + (typeof this._options.searchParams == "string" ? this._options.searchParams.replace(/^\?/, "") : new URLSearchParams(this._options.searchParams).toString()), i = this.request.url.replace(/(?:\?.*?)?(?=#|$)/, n); | ||
@@ -590,3 +590,3 @@ (Nt && this._options.body instanceof globalThis.FormData || this._options.body instanceof URLSearchParams) && !(this._options.headers && this._options.headers["content-type"]) && this.request.headers.delete("content-type"), this.request = new globalThis.Request(new globalThis.Request(i, { ...this.request }), this._options); | ||
} catch (e) { | ||
const r = Math.min(this._calculateRetryDelay(e), L); | ||
const r = Math.min(this._calculateRetryDelay(e), U); | ||
if (r !== 0 && this._retryCount > 0) { | ||
@@ -656,5 +656,5 @@ await Yt(r, { signal: this._options.signal }); | ||
const W = (s) => { | ||
const t = (e, r) => P.create(e, M(s, r)); | ||
const t = (e, r) => V.create(e, M(s, r)); | ||
for (const e of ct) | ||
t[e] = (r, n) => P.create(r, M(s, n, { method: e })); | ||
t[e] = (r, n) => V.create(r, M(s, n, { method: e })); | ||
return t.create = (e) => W(M(e)), t.extend = (e) => W(M(s, e)), t.stop = ut, t; | ||
@@ -676,3 +676,3 @@ }, Jt = W(), Kt = Jt, Qt = typeof window < "u" ? {} : { referrer: "https://sk.thorswap.net", referer: "https://sk.thorswap.net" }, tt = Kt.create({ headers: Qt }), Xt = { | ||
} | ||
const O = 8, y = (s) => 10n ** BigInt(s), C = (s) => Math.log10(parseFloat(s.toString())); | ||
const O = 8, y = (s) => 10n ** BigInt(s), R = (s) => Math.log10(parseFloat(s.toString())); | ||
function k({ | ||
@@ -696,3 +696,3 @@ value: s, | ||
} | ||
var w, R, b, T, j, ht, E, G, B, Y; | ||
var w, C, b, T, j, ht, E, G, B, Y; | ||
const K = class K { | ||
@@ -731,12 +731,12 @@ constructor(t) { | ||
add(...t) { | ||
return m(this, w, R).call(this, "add", ...t); | ||
return m(this, w, C).call(this, "add", ...t); | ||
} | ||
sub(...t) { | ||
return m(this, w, R).call(this, "sub", ...t); | ||
return m(this, w, C).call(this, "sub", ...t); | ||
} | ||
mul(...t) { | ||
return m(this, w, R).call(this, "mul", ...t); | ||
return m(this, w, C).call(this, "mul", ...t); | ||
} | ||
div(...t) { | ||
return m(this, w, R).call(this, "div", ...t); | ||
return m(this, w, C).call(this, "div", ...t); | ||
} | ||
@@ -762,3 +762,3 @@ gt(t) { | ||
this.bigIntValue, | ||
this.decimal || C(this.decimalMultiplier) | ||
this.decimal || R(this.decimalMultiplier) | ||
); | ||
@@ -838,3 +838,3 @@ switch (t) { | ||
r, | ||
C(this.decimalMultiplier) | ||
R(this.decimalMultiplier) | ||
), i = t < 0n, c = t.toString().substring(i ? 1 : 0), a = n - (c.length - 1), u = a > 0 ? "0".repeat(a) + c : c, l = u.length - n; | ||
@@ -848,4 +848,4 @@ let h = u.slice(-n); | ||
}; | ||
w = new WeakSet(), R = function(t, ...e) { | ||
const r = m(this, E, G).call(this, this, ...e), n = Math.max(r, C(this.decimalMultiplier)), i = y(n), c = e.reduce( | ||
w = new WeakSet(), C = function(t, ...e) { | ||
const r = m(this, E, G).call(this, this, ...e), n = Math.max(r, R(this.decimalMultiplier)), i = y(n), c = e.reduce( | ||
(u, l) => { | ||
@@ -900,6 +900,6 @@ const h = this.getBigIntValue(l, n); | ||
}, E = new WeakSet(), G = function(...t) { | ||
const e = t.map((r) => typeof r == "object" ? r.decimal || C(r.decimalMultiplier) : rt(x(r))).filter(Boolean); | ||
const e = t.map((r) => typeof r == "object" ? r.decimal || R(r.decimalMultiplier) : rt(x(r))).filter(Boolean); | ||
return Math.max(...e, O); | ||
}, B = new WeakSet(), Y = function(t, e) { | ||
const r = e ? y(e) : this.decimalMultiplier, n = C(r), [i = "", c = ""] = t.split("."); | ||
const r = e ? y(e) : this.decimalMultiplier, n = R(r), [i = "", c = ""] = t.split("."); | ||
return BigInt(`${i}${c.padEnd(n, "0")}`); | ||
@@ -943,3 +943,3 @@ }; | ||
f(this, "type"); | ||
const u = V(a || `${i}.${c}`); | ||
const u = P(a || `${i}.${c}`); | ||
this.type = Ot(u), this.tax = n, this.chain = u.chain, this.ticker = u.ticker, this.symbol = u.symbol, this.address = u.address, this.isSynthetic = u.isSynthetic, this.isGasAsset = u.isGasAsset; | ||
@@ -973,8 +973,5 @@ } | ||
static fromStringSync(e, r = 0) { | ||
const { chain: n, isSynthetic: i } = V(e), c = S.get(e.toUpperCase()); | ||
const { chain: n, isSynthetic: i } = P(e), c = S.get(e.toUpperCase()); | ||
if (i) | ||
return st(e, r); | ||
c || console.error( | ||
`Asset ${e} is not loaded. Use AssetValue.loadStaticAssets() to load it` | ||
); | ||
const { tax: a, decimal: u, identifier: l } = c || { | ||
@@ -992,8 +989,5 @@ decimal: d[n], | ||
static fromIdentifierSync(e, r = 0) { | ||
const { chain: n, isSynthetic: i } = V(e), c = S.get(e); | ||
const { chain: n, isSynthetic: i } = P(e), c = S.get(e); | ||
if (i) | ||
return st(e, r); | ||
c || console.error( | ||
`Asset ${e} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it` | ||
); | ||
const { tax: a, decimal: u, identifier: l } = c || { | ||
@@ -1055,3 +1049,3 @@ decimal: d[n], | ||
Zt(s); | ||
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await St(V(s)); | ||
const e = S.get(s.toUpperCase()), r = (e == null ? void 0 : e.decimal) || await St(P(s)); | ||
return e || S.set(s.toUpperCase(), { identifier: s, decimal: r }), new A({ decimal: r, value: I(t, r), identifier: s }); | ||
@@ -1070,3 +1064,3 @@ } | ||
} | ||
function V(s) { | ||
function P(s) { | ||
const t = s.slice(0, 14).includes("/"), [e, r] = s.split(".").pop().split("/"), n = s.includes(".") && !t ? s : `${o.THORChain}.${r}`, [i, c] = n.split("."), [a, u] = (t ? r : c).split("-"); | ||
@@ -1073,0 +1067,0 @@ return { |
@@ -12,4 +12,4 @@ { | ||
"@internal/config": "null-rc.0", | ||
"@swapkit/tokens": "1.0.0-rc.31", | ||
"@swapkit/types": "1.0.0-rc.30" | ||
"@swapkit/tokens": "1.0.0-rc.32", | ||
"@swapkit/types": "1.0.0-rc.31" | ||
}, | ||
@@ -20,4 +20,4 @@ "eslintConfig": { | ||
"peerDependencies": { | ||
"@swapkit/tokens": "1.0.0-rc.31", | ||
"@swapkit/types": "1.0.0-rc.30" | ||
"@swapkit/tokens": "1.0.0-rc.32", | ||
"@swapkit/types": "1.0.0-rc.31" | ||
}, | ||
@@ -47,3 +47,3 @@ "exports": { | ||
"types": "./dist/index.d.ts", | ||
"version": "1.0.0-rc.55", | ||
"version": "1.0.0-rc.56", | ||
"scripts": { | ||
@@ -50,0 +50,0 @@ "build": "vite build", |
@@ -96,7 +96,8 @@ import { BaseDecimal, Chain } from '@swapkit/types'; | ||
if (isSynthetic) return createSyntheticAssetValue(assetString, value); | ||
if (!tokenInfo) { | ||
console.error( | ||
`Asset ${assetString} is not loaded. Use AssetValue.loadStaticAssets() to load it`, | ||
); | ||
} | ||
// TODO: write logger that will only run in dev mode with some flag | ||
// if (!tokenInfo) { | ||
// console.error( | ||
// `Asset ${assetString} is not loaded. Use AssetValue.loadStaticAssets() to load it`, | ||
// ); | ||
// } | ||
@@ -120,7 +121,8 @@ const { tax, decimal, identifier } = tokenInfo || { | ||
if (isSynthetic) return createSyntheticAssetValue(assetString, value); | ||
if (!tokenInfo) { | ||
console.error( | ||
`Asset ${assetString} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`, | ||
); | ||
} | ||
// TODO: write logger that will only run in dev mode with some flag | ||
// if (!tokenInfo) { | ||
// console.error( | ||
// `Asset ${assetString} is not loaded. - Loading with base Chain. Use AssetValue.loadStaticAssets() to load it`, | ||
// ); | ||
// } | ||
@@ -127,0 +129,0 @@ const { tax, decimal, identifier } = tokenInfo || { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
416686
3901