Skip to content

Commit

Permalink
fix approve if needed only + v2 additional assets
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Nov 5, 2024
1 parent af486e3 commit 9d022b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ export class Commands {
" with additional datasets:" +
(!additionalDatasets ? "none" : additionalDatasets[0].documentId)
);
if(additionalDatasets!==null) {
console.log('Adding additional datasets to dataset, according to C2D V2 specs')
assets.push(additionalDatasets)
}

const output: ComputeOutput = {
metadataUri: await getMetadataURI()
Expand All @@ -420,12 +424,14 @@ export class Commands {
providerURI,
this.signer,
computeEnv.id,
assets[0],
assets, // assets[0] // only c2d v1,
algo,
null,
additionalDatasets,
output
// additionalDatasets, only c2d v1
output,
computeEnv.free ? true : false //
);

if (computeJobs && computeJobs[0]) {
const { jobId, agreementId } = computeJobs[0];
console.log("Compute started. JobID: " + jobId);
Expand Down
8 changes: 6 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ export async function createAsset(
datatokenParams
);
} else if (ddo?.stats?.price?.value === "0") {

const dispenserParams: DispenserCreationParams = {
dispenserAddress: config.dispenserAddress,
maxTokens: "1",
maxBalance: "100000000",
withMint: true,
allowedSwapper: ZERO_ADDRESS,
};

bundleNFT = await nftFactory.createNftWithDatatokenWithDispenser(
nftParamsAsset,
datatokenParams,
Expand Down Expand Up @@ -299,7 +299,10 @@ export async function handleComputeOrder(
- have validOrder and providerFees -> then order is valid but providerFees are not valid, we need to call reuseOrder and pay only providerFees
- no validOrder -> we need to call startOrder, to pay 1 DT & providerFees
*/
if (order.providerFee && order.providerFee.providerFeeAmount) {
const hasProviderFees = order.providerFee && order.providerFee.providerFeeAmount
// no need to approve if it is 0
if (hasProviderFees && Number(order.providerFee.providerFeeAmount) > 0) {

await approveWei(
payerAccount,
config,
Expand All @@ -308,6 +311,7 @@ export async function handleComputeOrder(
asset.services[0].datatokenAddress,
order.providerFee.providerFeeAmount
);

}
if (order.validOrder) {
if (!order.providerFee) return order.validOrder;
Expand Down

0 comments on commit 9d022b3

Please sign in to comment.