@mutants/cardano
Advanced tools
Comparing version 1.8.1 to 1.8.2
@@ -5,2 +5,3 @@ import { CardanoUTXO } from "./utxos"; | ||
asset: string; | ||
quantity: number; | ||
}; | ||
@@ -23,3 +24,3 @@ export declare type Multiasset = { | ||
}[]) => Multiasset; | ||
toCardanoAsset: (asset: string | { | ||
toCardanoAsset: (asset: { | ||
unit: string; | ||
@@ -26,0 +27,0 @@ quantity: string; |
@@ -23,2 +23,5 @@ "use strict"; | ||
}; | ||
var isNumber = function (value) { | ||
return typeof value === "number"; | ||
}; | ||
var getAssetsFromPolicyMap = function (policyKey, policyMap) { | ||
@@ -30,2 +33,5 @@ return policyMap | ||
asset: assetName, | ||
quantity: (isNumber(policyMap[assetName]) | ||
? policyMap[assetName] | ||
: 1), | ||
}, | ||
@@ -38,3 +44,3 @@ ], false); }, []) | ||
var _b; | ||
var policy = _a.policy, asset = _a.asset; | ||
var policy = _a.policy, asset = _a.asset, quantity = _a.quantity; | ||
if (acc[policy]) { | ||
@@ -45,3 +51,3 @@ acc[policy][asset] = 1; | ||
acc[policy] = (_b = {}, | ||
_b[asset] = 1, | ||
_b[asset] = quantity, | ||
_b); | ||
@@ -54,3 +60,3 @@ } | ||
return assets.reduce(function (acc, _a) { | ||
var unit = _a.unit; | ||
var unit = _a.unit, quantity = _a.quantity; | ||
if (unit === "lovelace") | ||
@@ -63,2 +69,3 @@ return acc; | ||
asset: details.assetName, | ||
quantity: parseInt(quantity), | ||
}, | ||
@@ -69,8 +76,7 @@ ], false); | ||
var toCardanoAsset = function (asset) { | ||
var details = typeof asset === "string" | ||
? getAssetDetails(asset) | ||
: getAssetDetails(asset.unit); | ||
var details = getAssetDetails(asset.unit); | ||
return { | ||
policy: details.assetPolicy, | ||
asset: details.assetName, | ||
quantity: parseInt(asset.quantity), | ||
}; | ||
@@ -77,0 +83,0 @@ }; |
{ | ||
"name": "@mutants/cardano", | ||
"version": "1.8.1", | ||
"version": "1.8.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -6,2 +6,3 @@ import { CardanoUTXO } from "./utxos"; | ||
asset: string; | ||
quantity: number; | ||
}; | ||
@@ -35,2 +36,6 @@ | ||
const isNumber = (value: unknown): value is number => { | ||
return typeof value === "number"; | ||
}; | ||
const getAssetsFromPolicyMap = ( | ||
@@ -47,2 +52,5 @@ policyKey: string, | ||
asset: assetName, | ||
quantity: (isNumber(policyMap[assetName]) | ||
? policyMap[assetName] | ||
: 1) as number, | ||
}, | ||
@@ -56,3 +64,3 @@ ], | ||
const fromAssetsToPolicyMap = (assets: CardanoAsset[]): Multiasset => { | ||
return assets.reduce((acc, { policy, asset }) => { | ||
return assets.reduce((acc, { policy, asset, quantity }) => { | ||
if (acc[policy]) { | ||
@@ -62,3 +70,3 @@ (acc[policy] as Multiasset)[asset] = 1; | ||
acc[policy] = { | ||
[asset]: 1, | ||
[asset]: quantity, | ||
}; | ||
@@ -74,3 +82,3 @@ } | ||
): CardanoAsset[] => { | ||
return assets.reduce((acc, { unit }) => { | ||
return assets.reduce((acc, { unit, quantity }) => { | ||
if (unit === "lovelace") return acc; | ||
@@ -85,2 +93,3 @@ | ||
asset: details.assetName, | ||
quantity: parseInt(quantity), | ||
}, | ||
@@ -91,9 +100,7 @@ ]; | ||
const toCardanoAsset = ( | ||
asset: string | { unit: string; quantity: string } | ||
): CardanoAsset => { | ||
const details = | ||
typeof asset === "string" | ||
? getAssetDetails(asset) | ||
: getAssetDetails(asset.unit); | ||
const toCardanoAsset = (asset: { | ||
unit: string; | ||
quantity: string; | ||
}): CardanoAsset => { | ||
const details = getAssetDetails(asset.unit); | ||
@@ -103,2 +110,3 @@ return { | ||
asset: details.assetName, | ||
quantity: parseInt(asset.quantity), | ||
}; | ||
@@ -105,0 +113,0 @@ }; |
@@ -14,2 +14,3 @@ import { CardanoAsset } from "../assets"; | ||
asset: "4d7574616e7443726f633032", | ||
quantity: 1, | ||
}, | ||
@@ -32,2 +33,3 @@ ]; | ||
asset: "4d7574616e7443726f633032", | ||
quantity: 1, | ||
}, | ||
@@ -37,2 +39,3 @@ { | ||
asset: "4d7574616e7443726f63", | ||
quantity: 1, | ||
}, | ||
@@ -42,2 +45,3 @@ { | ||
asset: "4d7574616e7443726f63", | ||
quantity: 1, | ||
}, | ||
@@ -60,2 +64,3 @@ ]; | ||
asset: "4d7574616e7443726f633032", | ||
quantity: 1, | ||
}, | ||
@@ -65,2 +70,3 @@ { | ||
asset: "4d7574616e7443726f63", | ||
quantity: 1, | ||
}, | ||
@@ -70,2 +76,3 @@ { | ||
asset: "4d7574616e7443726f63", | ||
quantity: 1, | ||
}, | ||
@@ -72,0 +79,0 @@ ]; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
405680
9066