@swapkit/helpers
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -7,2 +7,3 @@ { | ||
"ky": "1.4.0", | ||
"picocolors": "1.0.1", | ||
"zod": "3.23.8" | ||
@@ -33,3 +34,3 @@ }, | ||
"types": "./src/index.ts", | ||
"version": "1.0.4" | ||
"version": "1.1.0" | ||
} |
@@ -177,3 +177,3 @@ import { describe, expect, test } from "bun:test"; | ||
describe("Radix", () => { | ||
test( | ||
test.todo( | ||
"returns proper decimal for radix and it's assets", | ||
@@ -222,3 +222,3 @@ async () => { | ||
test("should return the correct object for Radix resource", () => { | ||
test.todo("should return the correct object for Radix resource", () => { | ||
const assetString = | ||
@@ -225,0 +225,0 @@ "XRD.xwBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75"; |
@@ -48,3 +48,3 @@ import { type ErrorKeys, SwapKitError } from "../modules/swapKitError"; | ||
export const getChainIdentifier = (chain: Chain) => { | ||
export function getChainIdentifier<T extends Chain>(chain: T) { | ||
switch (chain) { | ||
@@ -63,2 +63,15 @@ case Chain.THORChain: | ||
} | ||
}; | ||
} | ||
const skipWarnings = ["production", "test"].includes(process.env.NODE_ENV || ""); | ||
const warnings = new Set(); | ||
export function warnOnce(condition: boolean, warning: string) { | ||
if (!skipWarnings && condition) { | ||
if (warnings.has(warning)) { | ||
return; | ||
} | ||
warnings.add(warning); | ||
console.warn(warning); | ||
} | ||
} |
@@ -45,12 +45,13 @@ import { describe, expect, test } from "bun:test"; | ||
const radixXWBTC = new AssetValue({ | ||
identifier: | ||
"RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
decimal: 8, | ||
value: 11112222, | ||
}); | ||
// TODO: | ||
// const radixXWBTC = new AssetValue({ | ||
// identifier: | ||
// "RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
// decimal: 8, | ||
// value: 11112222, | ||
// }); | ||
expect(radixXWBTC.toString()).toBe( | ||
"RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
); | ||
// expect(radixXWBTC.toString()).toBe( | ||
// "RADIX.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", | ||
// ) | ||
}); | ||
@@ -258,3 +259,3 @@ }); | ||
test("creates AssetValue with _ symbol", async () => { | ||
test.todo("creates AssetValue with _ symbol", async () => { | ||
const radixXWBTC = await AssetValue.from({ | ||
@@ -261,0 +262,0 @@ asset: "XRD.XWBTC-resource_rdx1t580qxc7upat7lww4l2c4jckacafjeudxj5wpjrrct0p3e82sq4y75", |
@@ -0,1 +1,2 @@ | ||
import { red, yellow } from "picocolors"; | ||
import { | ||
@@ -9,2 +10,3 @@ type CommonAssetString, | ||
} from "../helpers/asset.ts"; | ||
import { warnOnce } from "../helpers/others.ts"; | ||
import { validateIdentifier } from "../helpers/validators.ts"; | ||
@@ -116,5 +118,3 @@ import { BaseDecimal, Chain, type ChainId, ChainToChainId } from "../types/chains.ts"; | ||
const parsedValue = value instanceof BigIntArithmetics ? value.getValue("string") : value; | ||
const isFromChain = "chain" in fromAssetOrChain; | ||
const assetOrChain = isFromChain ? fromAssetOrChain.chain : fromAssetOrChain.asset; | ||
@@ -131,7 +131,17 @@ | ||
const { chain, isSynthetic } = getAssetInfo(unsafeIdentifier); | ||
const token = staticTokensMap.get(unsafeIdentifier.toUpperCase() as TokenNames); | ||
const tokenDecimal = token?.decimal || commonAssetDecimal; | ||
const { tax, decimal, identifier } = staticTokensMap.get( | ||
unsafeIdentifier.toUpperCase() as TokenNames, | ||
) || { | ||
decimal: commonAssetDecimal || BaseDecimal[chain], | ||
warnOnce( | ||
!(asyncTokenLookup || tokenDecimal), | ||
yellow( | ||
`Couldn't find static decimal for ${red(unsafeIdentifier)} (Using default ${red(BaseDecimal[chain])} decimal as fallback). | ||
This can result in incorrect calculations and mess with amount sent on transactions. | ||
You can load static assets by installing @swapkit/tokens package and calling AssetValue.loadStaticAssets() | ||
or by passing asyncTokenLookup: true to the from() function, which will make it async and return a promise.`, | ||
), | ||
); | ||
const { decimal, identifier, tax } = token || { | ||
decimal: tokenDecimal || BaseDecimal[chain], | ||
identifier: unsafeIdentifier, | ||
@@ -138,0 +148,0 @@ }; |
@@ -13,4 +13,7 @@ const errorCodes = { | ||
core_explorer_unsupported_chain: 10009, | ||
core_verify_message_not_supported: 10010, | ||
core_chain_halted: 10099, | ||
/** | ||
* Core - Wallet | ||
*/ | ||
core_wallet_connection_not_found: 10100, | ||
@@ -28,2 +31,3 @@ core_wallet_xdefi_not_installed: 10101, | ||
core_wallet_not_keypair_wallet: 10111, | ||
core_wallet_sign_message_not_supported: 10110, | ||
/** | ||
@@ -85,2 +89,3 @@ * Core - Swap | ||
wallet_talisman_not_found: 20602, | ||
wallet_polkadot_not_found: 20701, | ||
/** | ||
@@ -111,3 +116,2 @@ * Chainflip | ||
api_v2_invalid_response: 50001, | ||
/** | ||
@@ -118,2 +122,15 @@ * Toolboxes | ||
toolbox_cosmos_no_accounts_found: 90102, | ||
toolbox_cosmos_verify_signature_no_pubkey: 90103, | ||
toolbox_evm_no_abi_fragment: 90201, | ||
toolbox_evm_no_signer: 90202, | ||
toolbox_evm_no_signer_address: 90203, | ||
toolbox_evm_no_from_address: 90204, | ||
toolbox_evm_no_contract_address: 90205, | ||
toolbox_evm_no_fee_data: 90206, | ||
toolbox_evm_no_gas_price: 90207, | ||
toolbox_evm_no_to_address: 90208, | ||
toolbox_evm_invalid_gas_asset_address: 90209, | ||
toolbox_evm_provider_not_eip1193_compatible: 90210, | ||
toolbox_evm_error_estimating_gas_limit: 90211, | ||
toolbox_evm_error_sending_transaction: 90212, | ||
/** | ||
@@ -130,2 +147,6 @@ * Helpers | ||
helpers_not_found_provider: 99200, | ||
/** | ||
* Anything else | ||
*/ | ||
not_implemented: 99999, | ||
} as const; | ||
@@ -132,0 +153,0 @@ |
@@ -25,2 +25,3 @@ import type { Eip1193Provider } from "ethers"; | ||
PHANTOM = "PHANTOM", | ||
POLKADOT_JS = "POLKADOT_JS", | ||
RADIX_WALLET = "RADIX_WALLET", | ||
@@ -46,2 +47,3 @@ TREZOR = "TREZOR", | ||
disconnect?: () => void; | ||
signMessage?: (message: string) => Promise<string>; | ||
}; | ||
@@ -51,3 +53,4 @@ | ||
export type BaseWallet<T extends EmptyWallet | Record<string, unknown>> = { | ||
[key in Chain]: ChainWallet & (T extends EmptyWallet ? T[key] : unknown); | ||
[key in Chain]: ChainWallet & | ||
(T extends EmptyWallet ? T[key] : T[key] extends ChainWallet ? T[key] : never); | ||
}; | ||
@@ -54,0 +57,0 @@ |
Sorry, the diff of this file is too big to display
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
436025
5404
4
+ Addedpicocolors@1.0.1
+ Addedpicocolors@1.0.1(transitive)