1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-07-01 06:11:43 +02:00

shorten getAccessDetailsFromTokenPrice() a bit

This commit is contained in:
Matthias Kretschmann 2022-06-22 12:05:35 +01:00
parent b09dc6b953
commit c8ab4b18c5
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 10 additions and 18 deletions

View File

@ -173,22 +173,21 @@ function getAccessDetailsFromTokenPrice(
): AccessDetails {
const accessDetails = {} as AccessDetails
if (tokenPrice && tokenPrice.orders && tokenPrice.orders.length > 0) {
if (tokenPrice?.orders?.length > 0) {
const order = tokenPrice.orders[0]
const reusedOrder =
order && order.reuses && order.reuses.length > 0 ? order.reuses[0] : null
const reusedOrder = order?.reuses?.length > 0 ? order.reuses[0] : null
// asset is owned if there is an order and asset has timeout 0 (forever) or if the condition is valid
accessDetails.isOwned =
timeout === 0 || Date.now() / 1000 - order.createdTimestamp < timeout
timeout === 0 || Date.now() / 1000 - order?.createdTimestamp < timeout
// the last valid order should be the last reuse order tx id if there is one
accessDetails.validOrderTx = reusedOrder ? reusedOrder.tx : order.tx
accessDetails.validOrderTx = reusedOrder?.tx || order?.tx
}
// TODO: fetch order fee from sub query
accessDetails.publisherMarketOrderFee = tokenPrice.publishMarketFeeAmount
accessDetails.publisherMarketOrderFee = tokenPrice?.publishMarketFeeAmount
// free is always the best price
if (tokenPrice.dispensers && tokenPrice.dispensers.length > 0) {
if (tokenPrice?.dispensers?.length > 0) {
const dispenser = tokenPrice.dispensers[0]
accessDetails.type = 'free'
accessDetails.addressOrId = dispenser.token.id
@ -203,10 +202,7 @@ function getAccessDetailsFromTokenPrice(
}
// checking for fixed price
if (
tokenPrice.fixedRateExchanges &&
tokenPrice.fixedRateExchanges.length > 0
) {
if (tokenPrice?.fixedRateExchanges?.length > 0) {
const fixed = tokenPrice.fixedRateExchanges[0]
accessDetails.type = 'fixed'
accessDetails.addressOrId = fixed.exchangeId
@ -227,7 +223,7 @@ function getAccessDetailsFromTokenPrice(
}
// checking for pools
if (tokenPrice.pools && tokenPrice.pools.length > 0) {
if (tokenPrice?.pools?.length > 0) {
const pool = tokenPrice.pools[0]
accessDetails.type = 'dynamic'
accessDetails.addressOrId = pool.id
@ -256,7 +252,6 @@ function getAccessDetailsFromTokenPrice(
* @return {Promise<OrdePriceAndFee>}
*/
export async function getOrderPriceAndFees(
web3: Web3,
asset: AssetExtended,
accountId?: string,
paramsForPool?: CalcInGivenOutParams,
@ -283,10 +278,10 @@ export async function getOrderPriceAndFees(
!providerFees &&
(await ProviderInstance.initialize(
asset?.id,
asset.services[0].id,
asset?.services[0].id,
0,
accountId,
asset.services[0].serviceEndpoint
asset?.services[0].serviceEndpoint
))
orderPriceAndFee.providerFee = providerFees || initializeData.providerFee

View File

@ -181,7 +181,6 @@ export default function Compute({
}
: null
const datasetPriceAndFees = await getOrderPriceAndFees(
web3,
asset,
ZERO_ADDRESS,
poolParams,
@ -229,7 +228,6 @@ export default function Compute({
}
}
const algorithmOrderPriceAndFees = await getOrderPriceAndFees(
web3,
selectedAlgorithmAsset,
ZERO_ADDRESS,
algoPoolParams,

View File

@ -83,7 +83,6 @@ export default function Download({
consumeMarketSwapFee: '0'
}
const _orderPriceAndFees = await getOrderPriceAndFees(
web3,
asset,
ZERO_ADDRESS,
paramsForPool