Skip to content

Commit

Permalink
Merge pull request #603 from nevermined-io/fix/no-dispenser-no-token
Browse files Browse the repository at this point in the history
feat: make load dispenser optional
  • Loading branch information
eruizgar91 authored Oct 25, 2023
2 parents 4ddbf3d + 5cfe57d commit 47823bb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 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": "2.0.0",
"version": "2.0.1",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
12 changes: 2 additions & 10 deletions src/keeper/Keeper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,11 @@ export class Keeper extends Instantiable {
`Keeper could not connect to ${await this.getNetworkName()} - ${err.message} ${err.stack}`,
)
}
const chainId = Number((await this.web3.getNetwork()).chainId)

// Optionals
try {
if (KeeperUtils.isTestnet(chainId)) {
this.instances.dispenser = await Dispenser.getInstance(this.instantiableConfig)
} catch {
this.logger.debug('Dispenser not available on this network.')
}

try {
this.instances.token = await Token.getInstance(this.instantiableConfig)
} catch {
this.logger.debug('Token not available on this network.')
}

// Main contracts
Expand Down Expand Up @@ -218,7 +211,6 @@ export class Keeper extends Instantiable {
eventHandler: new EventHandler(),
}
// version
const chainId = Number((await this.web3.getNetwork()).chainId)
this.network = {
chainId,
version: this.didRegistry.version.replace('v', ''),
Expand Down
59 changes: 58 additions & 1 deletion src/keeper/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,64 @@ export async function getNetworkName(networkId: number): Promise<string> {
throw new KeeperError(`Network with id ${networkId} not supported.`)
}
}

export async function isTestnet(networkId: number): Promise<boolean> {
switch (networkId) {
case 1:
return false
case 2:
return true
case 3:
return true
case 4:
return true
case 5:
return true
case 77:
return false
case 99:
return false
case 42:
return true
case 100:
return false
case 137:
return false
case 1337:
return true
case 3141:
return true
case 10200:
return true
case 31337:
return true
case 8996:
return true
case 8997:
return true
case 8998:
return true
case 42220:
return false
case 44787:
return true
case 62320:
return true
case 80001:
return true
case 42161:
return false
case 421613:
return true
case 1313161554:
return false
case 1313161555:
return true
case 1313161556:
return true
default:
throw new KeeperError(`Network with id ${networkId} not supported.`)
}
}
// Wrapper for implementing web3 provider. Needed for OpenGSN
export interface JsonRpcPayload {
jsonrpc: string
Expand Down
4 changes: 3 additions & 1 deletion test/nevermined/Accounts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ use(spies)

describe('Accounts', () => {
let accounts: AccountsApi
let nevermined: Nevermined

before(async () => {
// eslint-disable-next-line @typescript-eslint/no-extra-semi
;({ accounts } = await Nevermined.getInstance(config))
nevermined = await Nevermined.getInstance(config)
accounts = nevermined.accounts
})

afterEach(() => {
Expand Down

0 comments on commit 47823bb

Please sign in to comment.