Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update nvm app for local #707

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading