Docs improvements. Orion default env

This commit is contained in:
Aleksandr Kraiz
2023-02-08 14:10:38 +04:00
parent 2ac5b58f43
commit d2db95866f
5 changed files with 14 additions and 7 deletions

View File

@@ -57,7 +57,7 @@ npm i @orionprotocol/sdk
import { OrionUnit, Orion } from "@orionprotocol/sdk";
import { Wallet } from "ethers";
const orion = new Orion("production");
const orion = new Orion();
const orionUnit = orion.getUnit("bsc"); // eth, bsc, ftm, polygon, okc available
const wallet = new Wallet("0x...", orionUnit.provider);
// OrionUnit is chain-in-environment abstraction
@@ -74,7 +74,7 @@ const startApp = async (provider: BaseProvider) => {
const web3Provider = new providers.Web3Provider(provider);
await web3Provider.ready;
const signer = web3Provider.getSigner(); // ready to go
const orion = new Orion("production");
const orion = new Orion();
const orionUnit = orion.getUnit("eth"); // ready to go
};

View File

@@ -7,8 +7,10 @@ Let's consider integration of Orion Protocol with your UI.
Orion Protocol's SDK operate with OrionUnit — chain-in-environment abstraction. "Ethereum-in-production", "bsc-in-production", "fantom-in-testing", etc.
```ts
import { OrionUnit } from "@orionprotocol/sdk";
const orionUnit = new OrionUnit("bsc", "production"); // eth, bsc, ftm available
import { Orion } from "@orionprotocol/sdk";
const orion = new Orion();
const bscOrionUnit = orion.getUnit("bsc"); // eth, bsc, ftm, polygon, okc available
const ethOrionUnit = orion.getUnit("eth");
```
## 2. Signer accessing

View File

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

View File

@@ -20,12 +20,15 @@ type EnvConfig = {
// type KnownEnv = 'testing' | 'staging' | 'production';
export default class Orion {
public readonly env?: string;
public readonly units: Partial<Record<SupportedChainId, OrionUnit>>;
public readonly orionAnalytics: OrionAnalytics;
public readonly referralSystem: ReferralSystem;
constructor();
constructor(
env: string,
overrides?: DeepPartial<EnvConfig>
@@ -40,13 +43,14 @@ export default class Orion {
// TODO: bridge
constructor(
envOrConfig: string | EnvConfig,
envOrConfig: string | EnvConfig = 'production',
overrides?: DeepPartial<EnvConfig>
) {
let config: EnvConfig;
if (typeof envOrConfig === 'string') {
const envConfig = envs[envOrConfig];
if (!envConfig) throw new Error(`Invalid environment: ${envOrConfig}. Available environments: ${Object.keys(envs).join(', ')}`);
this.env = envOrConfig;
config = {
analyticsAPI: envConfig.analyticsAPI,
referralAPI: envConfig.referralAPI,

View File

@@ -95,7 +95,8 @@ describe('Orion', () => {
});
test('Init Orion production', () => {
const orion = new Orion('production');
const orion = new Orion();
expect(orion.env).toBe('production');
expect(orion.orionAnalytics).toBeInstanceOf(OrionAnalytics);
expect(orion.referralSystem).toBeInstanceOf(ReferralSystem);
expect(orion.unitsArray.length).toBe(5); // eth, bsc, polygon, fantom, okc