@exodus/models
Advanced tools
Comparing version 8.8.0 to 8.9.0
@@ -16,2 +16,4 @@ "use strict"; | ||
var _accountState = require("../account-state"); | ||
var _walletAccount = _interopRequireDefault(require("../wallet-account")); | ||
@@ -55,5 +57,7 @@ | ||
const OPTIMISTIC_STATUSES = ['optimistic-complete', 'potential-complete']; | ||
const FACTORY_SYMBOL = Symbol('Order'); | ||
class Order { | ||
constructor(props = {}) { | ||
if (props.initSymbol !== FACTORY_SYMBOL) throw new Error('please use Order.fromJSON()'); | ||
this.orderId = props.orderId; | ||
@@ -72,19 +76,7 @@ | ||
if (props.toTxId) this.toTxId = props.toTxId; | ||
if (props.fromAsset) { | ||
this.fromAsset = String(props.fromAsset); | ||
if (props.fromAmount) { | ||
this.fromAmount = (0, _currency.isNumberUnit)(props.fromAmount) ? props.fromAmount : _assets.default[this.fromAsset].currency.parse(props.fromAmount); | ||
} | ||
} | ||
if (props.toAsset) { | ||
this.toAsset = String(props.toAsset); | ||
if (props.toAmount) { | ||
this.toAmount = (0, _currency.isNumberUnit)(props.toAmount) ? props.toAmount : _assets.default[this.toAsset].currency.parse(props.toAmount); | ||
} | ||
} | ||
if (props.txIds) this.txIds = props.txIds; | ||
if (props.fromAsset) this.fromAsset = String(props.fromAsset); | ||
if (props.fromAmount) this.fromAmount = props.fromAmount; | ||
if (props.toAsset) this.toAsset = String(props.toAsset); | ||
if (props.toAmount) this.toAmount = props.toAmount; | ||
this.fromWalletAccount = props.fromWalletAccount || _walletAccount.default.DEFAULT_NAME; | ||
@@ -101,2 +93,3 @@ this.toWalletAccount = props.toWalletAccount || _walletAccount.default.DEFAULT_NAME; | ||
this.potentialToTxIds = props.potentialToTxIds || []; | ||
this._version = 1; | ||
} | ||
@@ -106,6 +99,30 @@ | ||
if (typeof json === 'string') json = JSON.parse(json); | ||
const ex = new Order(json); | ||
return ex; | ||
let { | ||
_version, | ||
fromAmount, | ||
fromAsset, | ||
toAmount, | ||
toAsset | ||
} = json; | ||
if (fromAmount) { | ||
fromAmount = _version === 1 ? (0, _accountState.deserialize)(fromAmount) : Order._legacyParse(fromAsset, fromAmount); | ||
} | ||
if (toAmount) { | ||
toAmount = _version === 1 ? (0, _accountState.deserialize)(toAmount) : Order._legacyParse(toAsset, toAmount); | ||
} | ||
const order = new Order({ ...json, | ||
fromAmount, | ||
toAmount, | ||
initSymbol: FACTORY_SYMBOL | ||
}); | ||
return order; | ||
} | ||
static _legacyParse(assetName, amount) { | ||
return (0, _currency.isNumberUnit)(amount) ? amount : assetName ? _assets.default[assetName].currency.parse(amount) : undefined; | ||
} | ||
inspect() { | ||
@@ -119,4 +136,5 @@ return `[Order ${this.orderId}]`; | ||
}; | ||
if (obj.fromAmount) obj.fromAmount = obj.fromAmount.toString(); | ||
if (obj.toAmount) obj.toAmount = obj.toAmount.toString(); | ||
if (obj.fromAmount) obj.fromAmount = (0, _accountState.serialize)(obj.fromAmount); | ||
if (obj.toAmount) obj.toAmount = (0, _accountState.serialize)(obj.toAmount); | ||
obj._version = 1; | ||
return obj; | ||
@@ -123,0 +141,0 @@ } |
@@ -45,14 +45,22 @@ "use strict"; | ||
if (json.coinAmount && json.coinName) { | ||
tx.coinAmount = parseCurrency(json.coinAmount, json.coinName, assets); | ||
tx.coinName = json.coinName; | ||
} else if (json.coinAmount && !json.coinName && (0, _currency.isNumberUnit)(json.coinAmount)) { | ||
tx.coinAmount = json.coinAmount; | ||
if (json.coinAmount) { | ||
if (json.coinName) { | ||
tx.coinAmount = parseCurrency(json.coinAmount, json.coinName, assets); | ||
tx.coinName = json.coinName; | ||
} else if ((0, _currency.isNumberUnit)(json.coinAmount)) { | ||
tx.coinAmount = json.coinAmount; | ||
} | ||
} | ||
if (json.feeAmount && json.coinName) { | ||
const feeAssetName = assets[json.coinName].feeAsset.name; | ||
tx.feeAmount = parseCurrency(json.feeAmount, feeAssetName, assets); | ||
} else if (json.feeAmount && !json.coinName && (0, _currency.isNumberUnit)(json.feeAmount)) { | ||
tx.feeAmount = json.feeAmount; | ||
if (json.feeAmount) { | ||
if (json.feeCoinName) { | ||
tx.feeAmount = parseCurrency(json.feeAmount, json.feeCoinName, assets); | ||
tx.feeCoinName = json.feeCoinName; | ||
} else if (json.coinName) { | ||
const feeAssetName = assets[json.coinName].feeAsset.name; | ||
tx.feeAmount = parseCurrency(json.feeAmount, feeAssetName, assets); | ||
tx.feeCoinName = feeAssetName; | ||
} else if ((0, _currency.isNumberUnit)(json.feeAmount)) { | ||
tx.feeAmount = json.feeAmount; | ||
} | ||
} | ||
@@ -59,0 +67,0 @@ |
{ | ||
"name": "@exodus/models", | ||
"version": "8.8.0", | ||
"version": "8.9.0", | ||
"description": "Exodus models", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
64234
1700
1