Skip to content

Commit

Permalink
fix compute stop & uptade order helper to be reused also for c2d ored…
Browse files Browse the repository at this point in the history
…er methods (#1761)
  • Loading branch information
bogdanfazakas authored Sep 4, 2023
1 parent 01822d8 commit cf0c122
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/services/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ export class Provider {
payload.signature = signature
payload.documentId = this.noZeroX(did)
payload.consumerAddress = consumerAddress
payload.nonce = nonce
if (jobId) payload.jobId = jobId

if (!computeStopUrl) return null
Expand Down
32 changes: 22 additions & 10 deletions src/utils/OrderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
FreOrderParams,
approve,
FixedRateExchange,
ConsumeMarketFee
ConsumeMarketFee,
ProviderFees
} from '../index'
import Decimal from 'decimal.js'

Expand All @@ -19,7 +20,10 @@ import Decimal from 'decimal.js'
* @param {Signer} consumerAccount - The signer account of the consumer.
* @param {Config} config - The configuration settings.
* @param {Datatoken} datatoken - The Datatoken instance.
* @param {string} [providerUrl] - Optional the consumer address
* @param {string} [consumerAccount] - Optional the consumer address
* @param {ConsumeMarketFee} [consumeMarketOrderFee] - Optional consume market fee.
* @param {ProviderFees} [providerFees] - Optional provider fees
* @param {string} [consumeMarketFixedSwapFee='0'] - Fixed swap fee for consuming the market.
* @param {number} [datatokenIndex=0] - Index of the datatoken within the asset.
* @param {number} [serviceIndex=0] - Index of the service within the asset.
Expand All @@ -32,7 +36,10 @@ export async function orderAsset(
consumerAccount: Signer,
config: Config,
datatoken: Datatoken,
providerUrl?: string,
consumerAddress?: string,
consumeMarketOrderFee?: ConsumeMarketFee,
providerFees?: ProviderFees,
consumeMarketFixedSwapFee: string = '0',
datatokenIndex: number = 0,
serviceIndex: number = 0,
Expand Down Expand Up @@ -68,18 +75,23 @@ export async function orderAsset(
)
const pricingType =
fixedRates.length > 0 ? 'fixed' : dispensers.length > 0 ? 'free' : 'NOT_ALLOWED'
const initializeData = await ProviderInstance.initialize(
asset.id,
asset.services[serviceIndex].id,
0,
await consumerAccount.getAddress(),
config.providerUri
)

const fees =
providerFees ||
(
await ProviderInstance.initialize(
asset.id,
asset.services[serviceIndex].id,
0,
await consumerAccount.getAddress(),
providerUrl || config.providerUri
)
).providerFee

const orderParams = {
consumer: await consumerAccount.getAddress(),
consumer: consumerAddress || (await consumerAccount.getAddress()),
serviceIndex,
_providerFee: initializeData.providerFee,
_providerFee: fees,
_consumeMarketFee: consumeMarketOrderFee
} as OrderParams

Expand Down

0 comments on commit cf0c122

Please sign in to comment.