1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/src/keeper/Keeper.ts

63 lines
2.1 KiB
TypeScript
Raw Normal View History

import OceanAuth from "./contracts/Auth"
import AccessConditions from "./contracts/conditions/AccessConditions"
import DIDRegistry from "./contracts/DIDRegistry"
import OceanMarket from "./contracts/Market"
import ServiceAgreement from "./contracts/ServiceAgreement"
import OceanToken from "./contracts/Token"
2018-10-16 14:56:18 +02:00
import Web3Provider from "./Web3Provider"
export default class Keeper {
2018-10-16 14:56:18 +02:00
public static async getInstance() {
2018-10-16 14:56:18 +02:00
if (Keeper.instance === null) {
Keeper.instance = new Keeper()
2018-10-16 14:56:18 +02:00
Keeper.instance.market = await OceanMarket.getInstance()
Keeper.instance.auth = await OceanAuth.getInstance()
Keeper.instance.token = await OceanToken.getInstance()
Keeper.instance.serviceAgreement = await ServiceAgreement.getInstance()
Keeper.instance.accessConditions = await AccessConditions.getInstance()
Keeper.instance.didRegistry = await DIDRegistry.getInstance()
2018-10-16 14:56:18 +02:00
}
return Keeper.instance
}
2018-10-16 14:56:18 +02:00
private static instance: Keeper = null
2018-10-02 10:06:26 +02:00
public token: OceanToken
public market: OceanMarket
public auth: OceanAuth
public serviceAgreement: ServiceAgreement
public accessConditions: AccessConditions
public didRegistry: DIDRegistry
2018-10-16 14:56:18 +02:00
public async getNetworkName(): Promise<string> {
return Web3Provider.getWeb3().eth.net.getId()
.then((networkId) => {
let network: string = "unknown"
switch (networkId) {
case 1:
network = "Main"
break
case 2:
network = "Morden"
break
case 3:
network = "Ropsten"
break
case 4:
network = "Rinkeby"
break
case 42:
network = "Kovan"
break
default:
network = "development"
}
return network
})
}
}