Skip to content

Commit

Permalink
feat: update nvm app for local
Browse files Browse the repository at this point in the history
  • Loading branch information
eruizgar91 committed Aug 26, 2024
1 parent 0c9a5a0 commit 35a5535
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "3.0.26",
"version": "3.0.27",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
42 changes: 28 additions & 14 deletions src/nevermined/NvmApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { DDO } from '../ddo/DDO'
import { Web3Error } from '../errors/NeverminedErrors'
import { AssetPrice } from '../models/AssetPrice'
import { NFTAttributes } from '../models/NFTAttributes'
import { NvmApiKey } from '../models/NvmApiKey'
import { NeverminedOptions } from '../models/NeverminedOptions'
import { NvmAccount } from '../models/NvmAccount'
import { NvmApiKey } from '../models/NvmApiKey'
import {
AppDeploymentArbitrum,
AppDeploymentBase,
Expand Down Expand Up @@ -76,8 +76,6 @@ export class NvmApp {
private zeroDevSignerAccount: SmartAccountSigner<'custom', `0x${string}`> | undefined
public assetProviders: NeverminedNodeInfo[] = []
private loginCredentials: string | undefined
private subscriptionNFTContractTimeAddress: string | undefined
private subscriptionNFTContractCreditsAddress: string | undefined
private networkFeeReceiver: string | undefined
private networkFee: bigint | undefined

Expand Down Expand Up @@ -195,15 +193,6 @@ export class NvmApp {
},
]

this.subscriptionNFTContractTimeAddress = this.configNVM.nftContractTimeAddress
this.subscriptionNFTContractCreditsAddress = this.configNVM.nftContractCreditsAddress

if (!isValidAddress(this.subscriptionNFTContractTimeAddress as string)) {
throw new Web3Error('Invalid Subscription NFT contract time address')
}
if (!isValidAddress(this.subscriptionNFTContractCreditsAddress as string)) {
throw new Web3Error('Invalid Subscription NFT contract credits address')
}
this.networkFeeReceiver = await this.fullSDK.keeper.nvmConfig.getFeeReceiver()
this.networkFee = await this.fullSDK.keeper.nvmConfig.getNetworkFee()
return {
Expand Down Expand Up @@ -329,6 +318,7 @@ export class NvmApp {
susbcriptionMetadata: MetaData,
subscriptionPrice: AssetPrice,
duration: number,
subscriptionNFTContractTimeAddress?: string,
): SubscribablePromise<CreateProgressStep, DDO> {
if (!this.fullSDK || !this.isWeb3Connected() || !this.userAccount)
throw new Web3Error('Web3 not connected, try calling the connect method first')
Expand All @@ -343,6 +333,18 @@ export class NvmApp {
}

this.fullSDK.services.node.getVersionInfo()

let nftContractAddress = subscriptionNFTContractTimeAddress
? subscriptionNFTContractTimeAddress
: this.configNVM.nftContractTimeAddress

if (!nftContractAddress) {
nftContractAddress = this.fullSDK.nfts1155.address
}
if (!isValidAddress(nftContractAddress as string)) {
throw new Web3Error('Invalid Subscription NFT contract time address')
}

const nftAttributes = NFTAttributes.getCreditsSubscriptionInstance({
metadata: susbcriptionMetadata,
services: [
Expand All @@ -357,7 +359,7 @@ export class NvmApp {
},
],
providers: this.getProviderAddresses(),
nftContractAddress: this.subscriptionNFTContractTimeAddress,
nftContractAddress: nftContractAddress,
preMint: false,
})

Expand Down Expand Up @@ -397,6 +399,7 @@ export class NvmApp {
susbcriptionMetadata: MetaData,
subscriptionPrice: AssetPrice,
numberCredits: bigint,
subscriptionNFTContractCreditsAddress?: string,
): SubscribablePromise<CreateProgressStep, DDO> {
if (!this.fullSDK || !this.isWeb3Connected() || !this.userAccount)
throw new Web3Error('Web3 not connected, try calling the connect method first')
Expand All @@ -410,6 +413,17 @@ export class NvmApp {
throw new Error(validationResult.messages.join(','))
}

let nftContractAddress = subscriptionNFTContractCreditsAddress
? subscriptionNFTContractCreditsAddress
: this.configNVM.nftContractTimeAddress

if (!nftContractAddress) {
nftContractAddress = this.fullSDK.nfts1155.address
}
if (!isValidAddress(nftContractAddress as string)) {
throw new Web3Error('Invalid Subscription NFT contract credits address')
}

const nftAttributes = NFTAttributes.getCreditsSubscriptionInstance({
metadata: susbcriptionMetadata,
services: [
Expand All @@ -423,7 +437,7 @@ export class NvmApp {
},
],
providers: this.getProviderAddresses(),
nftContractAddress: this.subscriptionNFTContractCreditsAddress,
nftContractAddress: nftContractAddress,
preMint: false,
})

Expand Down

0 comments on commit 35a5535

Please sign in to comment.