mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-05-30 05:51:04 +00:00
add new type in api - settings in order to support different types of… (#476)
* add new type in api - settings in order to support different types of 'urls' - json-rpc and substrate-connect; This makes the previous used apiURL deprecated * Alter name from apiTypeUrl to apiType * export types of possible endpoints * minor fix on sequence of vars * Fix lint error concerning imports * Fix lint error concerning imports * Fix PR comments: import types instead of import; seperate types from settings * fix lint error * Update packages/ui-settings/src/types.ts Co-authored-by: Jaco <jacogr@gmail.com> Co-authored-by: Jaco <jacogr@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/ui-settings authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Option, SettingsStruct } from './types';
|
||||
import type { Endpoint, EndpointType, Option, SettingsStruct } from './types';
|
||||
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import store from 'store';
|
||||
@@ -24,6 +24,9 @@ function withDefault (options: Option[], option: string | undefined, fallback: s
|
||||
export class Settings implements SettingsStruct {
|
||||
readonly #emitter: EventEmitter;
|
||||
|
||||
#apiType: Endpoint;
|
||||
|
||||
// will become deprecated for supporting substrate connect light clients. apiType structure should be used instead
|
||||
#apiUrl: string;
|
||||
|
||||
#camera: string;
|
||||
@@ -47,7 +50,9 @@ export class Settings implements SettingsStruct {
|
||||
|
||||
this.#emitter = new EventEmitter();
|
||||
|
||||
// will become deprecated for supporting substrate connect light clients. apiType structure should be used instead
|
||||
this.#apiUrl = (typeof settings.apiUrl === 'string' && settings.apiUrl) || process.env.WS_URL || (ENDPOINT_DEFAULT.value as string);
|
||||
this.#apiType = { param: this.#apiUrl, type: 'json-rpc' as EndpointType };
|
||||
this.#camera = withDefault(CAMERA, settings.camera, CAMERA_DEFAULT);
|
||||
this.#ledgerConn = withDefault(LEDGER_CONN, settings.ledgerConn, LEDGER_CONN_DEFAULT);
|
||||
this.#i18nLang = settings.i18nLang || LANGUAGE_DEFAULT;
|
||||
@@ -62,6 +67,10 @@ export class Settings implements SettingsStruct {
|
||||
return this.#camera;
|
||||
}
|
||||
|
||||
public get apiType (): Endpoint {
|
||||
return this.#apiType;
|
||||
}
|
||||
|
||||
public get apiUrl (): string {
|
||||
return this.#apiUrl;
|
||||
}
|
||||
@@ -140,6 +149,7 @@ export class Settings implements SettingsStruct {
|
||||
|
||||
public get (): SettingsStruct {
|
||||
return {
|
||||
apiType: this.#apiType,
|
||||
apiUrl: this.#apiUrl,
|
||||
camera: this.#camera,
|
||||
i18nLang: this.#i18nLang,
|
||||
@@ -153,6 +163,7 @@ export class Settings implements SettingsStruct {
|
||||
}
|
||||
|
||||
public set (settings: Partial<SettingsStruct>): void {
|
||||
this.#apiType = settings.apiType || this.#apiType;
|
||||
this.#apiUrl = settings.apiUrl || this.#apiUrl;
|
||||
this.#camera = settings.camera || this.#camera;
|
||||
this.#ledgerConn = settings.ledgerConn || this.#ledgerConn;
|
||||
|
||||
@@ -9,6 +9,7 @@ export type Option = {
|
||||
}
|
||||
|
||||
export interface SettingsStruct {
|
||||
apiType: Endpoint;
|
||||
apiUrl: string;
|
||||
camera: string;
|
||||
i18nLang: string;
|
||||
@@ -28,3 +29,10 @@ export interface NetworkSpecsStruct {
|
||||
title: string;
|
||||
unit: string;
|
||||
}
|
||||
|
||||
export interface Endpoint {
|
||||
type: EndpointType;
|
||||
param: string;
|
||||
}
|
||||
|
||||
export type EndpointType = 'json-rpc' | 'substrate-connect';
|
||||
|
||||
Reference in New Issue
Block a user