Better docs

This commit is contained in:
Aleksandr Kraiz
2023-02-08 01:01:30 +04:00
parent 68c535103e
commit 1f19a50839
3 changed files with 34 additions and 4 deletions

View File

@@ -23,4 +23,25 @@ const orion = new Orion({
},
},
});
const orionUnit = orion.getUnit("bsc");
// OR
const orionUnit = orion.getUnit(SupportedChainId.BSC);
// OR
const orionUnit = new OrionUnit({
chainId: SupportedChainId.BSC,
nodeJsonRpc: "https://bsc-dataseed.binance.org/",
services: {
orionBlockchain: {
http: "https://orion-bsc-api.orionprotocol.io",
},
orionAggregator: {
http: "https://orion-bsc-api.orionprotocol.io/backend",
ws: "https://orion-bsc-api.orionprotocol.io/v1",
},
priceFeed: {
api: "https://orion-bsc-api.orionprotocol.io/price-feed",
},
},
});
```

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.17.0-rc.0",
"version": "0.17.0-rc.1",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -108,9 +108,18 @@ export default class Orion {
return Object.entries(this.units).map(([, unit]) => unit);
}
getUnit(networkCode: string) {
const unit = this.unitsArray.find((unit) => unit.networkCode === networkCode);
if (!unit) throw new Error(`Invalid network code: ${networkCode}. Available network codes: ${this.unitsArray.map((unit) => unit.networkCode).join(', ')}`);
getUnit(chainId: SupportedChainId): OrionUnit;
getUnit(networkCode: string): OrionUnit;
getUnit(networkCodeOrChainId: string): OrionUnit {
let unit: OrionUnit | undefined;
if (isValidChainId(networkCodeOrChainId)) {
unit = this.units[networkCodeOrChainId];
} else {
unit = this.unitsArray.find((unit) => unit.networkCode === networkCodeOrChainId);
}
if (!unit) throw new Error(`Invalid network code: ${networkCodeOrChainId}. Available network codes: ${this.unitsArray.map((unit) => unit.networkCode).join(', ')}`);
return unit;
}