Skip to content

Commit

Permalink
Merge pull request #645 from Cryptorubic/develop
Browse files Browse the repository at this point in the history
New wallets
  • Loading branch information
siandreev authored Aug 16, 2021
2 parents 50f9bd7 + 37f0edd commit e2dab15
Show file tree
Hide file tree
Showing 137 changed files with 2,579 additions and 5,706 deletions.
1 change: 1 addition & 0 deletions .browserslistrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
last 2 versions
Firefox ESR
not dead
not IE 11
19 changes: 7 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions scripts/patch-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,18 @@ fs.readFile(maticFile, 'utf8', function (err, data) {
}
});
});

/* patch walletlink */
const walletLinkFile = 'node_modules/walletlink/dist/relay/WalletLinkRelay.js';

fs.readFile(walletLinkFile, 'utf8', function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/this\.ui\.reloadUI\(\);/, '// this.ui.reloadUI();');
fs.writeFile(walletLinkFile, result, 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
});
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class AppComponent {
try {
this.queryParamsService.setupQueryParams(queryParams);
} catch (err) {
this.errorService.catch$(err);
this.errorService.catch(err);
}
}
);
Expand Down
40 changes: 11 additions & 29 deletions src/app/core/errors/errors.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PolymorpheusComponent } from '@tinkoff/ng-polymorpheus';
import { TranslateService } from '@ngx-translate/core';
import { UndefinedErrorComponent } from 'src/app/core/errors/components/undefined-error/undefined-error.component';
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';
import { NotificationsService } from 'src/app/core/services/notifications/notifications.service';

@Injectable({
Expand All @@ -13,39 +14,20 @@ export class ErrorsService {
constructor(
private readonly notificationsService: NotificationsService,
@Inject(Injector) private injector: Injector,
private readonly translateService: TranslateService
private translateService: TranslateService
) {}

public throw$(error: RubicError): never {
// tslint:disable-next-line:no-console
console.debug(error);

const options = {
label: this.translateService.instant('common.error'),
status: TuiNotification.Error,
data: {},
autoClose: 7000
};

if (error?.type === 'component') {
const errorComponent = new PolymorpheusComponent(
error.component || UndefinedErrorComponent,
this.injector
);
options.data = error?.data;
this.notificationsService.show(errorComponent, options);
throw error;
}

const text = error?.translateKey
? this.translateService.instant(error.translateKey)
: error.message;
this.notificationsService.show(text, options);
/**
* @deprecated
* @param error
*/
public throw(error: RubicError<ERROR_TYPE>): never {
this.catch(error);

throw error;
}

public catch$(error: RubicError): void {
public catch(error: RubicError<ERROR_TYPE>): void {
console.debug(error);

if (error.displayError === false || error.message.includes('Attempt to use a destroyed view')) {
Expand All @@ -59,7 +41,7 @@ export class ErrorsService {
autoClose: 7000
};

if (error?.type === 'component') {
if (error?.type === ERROR_TYPE.COMPONENT) {
const errorComponent = new PolymorpheusComponent(
error.component || UndefinedErrorComponent,
this.injector
Expand All @@ -72,7 +54,7 @@ export class ErrorsService {
}

const text = error?.translateKey
? this.translateService.instant(error.translateKey)
? this.translateService.instant(error.translateKey, error?.data)
: error.message;
this.notificationsService.show(text, options);
}
Expand Down
46 changes: 31 additions & 15 deletions src/app/core/errors/models/RubicError.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
import { ErrorType } from 'src/app/core/errors/models/error-type';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';
import { Type } from '@angular/core';

export abstract class RubicError extends Error {
public translateKey: string;
type TranslationKey = string;

public type: ErrorType;
type Component = Type<object>;

public component: Type<object>;
export abstract class RubicError<T extends ERROR_TYPE> extends Error {
public translateKey: TranslationKey;

public type: ERROR_TYPE;

public component: Component;

public data: object;

public displayError: boolean;
public displayError = true;

protected constructor(
errorType: ErrorType,
translateKey?: string,
message?: string,
component?: Type<object>,
data?: object
contentProvider: T extends ERROR_TYPE.TEXT
? TranslationKey
: T extends ERROR_TYPE.COMPONENT
? Component
: null,
data?: object,
message?: string
) {
super(message);
this.translateKey = translateKey;
this.type = errorType;
this.component = component;
this.data = data;
this.displayError = true;

if (!contentProvider) {
this.type = ERROR_TYPE.RAW_MESSAGE;
return;
}

if (typeof contentProvider === 'string') {
this.translateKey = contentProvider;
this.type = ERROR_TYPE.TEXT;
return;
}

this.component = contentProvider;
this.type = ERROR_TYPE.COMPONENT;
}
}
5 changes: 3 additions & 2 deletions src/app/core/errors/models/bridge/NotSupportedBridgeError.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class NotSupportedBridgeError extends RubicError {
export class NotSupportedBridgeError extends RubicError<ERROR_TYPE.TEXT> {
public comment: string;

constructor() {
super('text', 'errors.notSupportedBridge');
super('errors.notSupportedBridge');
Object.setPrototypeOf(this, NotSupportedBridgeError.prototype);
}
}
5 changes: 3 additions & 2 deletions src/app/core/errors/models/bridge/OverQueryLimitError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { OverQueryLimitErrorComponent } from 'src/app/core/errors/components/over-query-limit-error/over-query-limit-error.component';
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class OverQueryLimitError extends RubicError {
export class OverQueryLimitError extends RubicError<ERROR_TYPE.COMPONENT> {
constructor() {
super('component', null, null, OverQueryLimitErrorComponent);
super(OverQueryLimitErrorComponent);
Object.setPrototypeOf(this, OverQueryLimitError.prototype);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

class TransactionRevertedError extends RubicError {
class TransactionRevertedError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.cancelDeadline');
super('errors.cancelDeadline');
Object.setPrototypeOf(this, TransactionRevertedError.prototype);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/errors/models/custom-error.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

class CustomError extends RubicError {
class CustomError extends RubicError<ERROR_TYPE.RAW_MESSAGE> {
constructor(message: string) {
super('text', null, message.charAt(0).toUpperCase() + message.slice(1));
super(null, null, message.charAt(0).toUpperCase() + message.slice(1));
Object.setPrototypeOf(this, CustomError.prototype);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/app/core/errors/models/error-type.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export type ErrorType = 'component' | 'text';
export enum ERROR_TYPE {
TEXT = 'TEXT',
COMPONENT = 'COMPONENT',
RAW_MESSAGE = 'RAW_MESSAGE'
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// tslint:disable-next-line:max-line-length
import { InsufficientFundsErrorComponent } from 'src/app/core/errors/components/insufficient-funds-error/insufficient-funds-error.component';
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

class InsufficientFundsError extends RubicError {
class InsufficientFundsError extends RubicError<ERROR_TYPE.COMPONENT> {
constructor(tokenSymbol: string, balance: string, requiredBalance: string) {
super('component', null, null, InsufficientFundsErrorComponent, {
super(InsufficientFundsErrorComponent, {
tokenSymbol,
balance,
requiredBalance
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

class InsufficientLiquidityError extends RubicError {
class InsufficientLiquidityError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.insufficientLiquidity');
super('errors.insufficientLiquidity');
Object.setPrototypeOf(this, InsufficientLiquidityError.prototype);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

class NoSelectedProviderError extends RubicError {
class NoSelectedProviderError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.noSelectedProvider');
super('errors.noSelectedProvider');
Object.setPrototypeOf(this, NoSelectedProviderError.prototype);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class NotSupportedItNetwork extends RubicError {
export class NotSupportedItNetwork extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.notSupportedItNetwork');
super('errors.notSupportedItNetwork');
Object.setPrototypeOf(this, NotSupportedItNetwork.prototype);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class OneinchRefreshError extends RubicError {
export class OneinchRefreshError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.oneinchRefreshError');
super('errors.oneinchRefreshError');
Object.setPrototypeOf(this, OneinchRefreshError.prototype);
}
}
5 changes: 3 additions & 2 deletions src/app/core/errors/models/provider/AccountError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class AccountError extends RubicError {
export class AccountError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.noMetamaskAccess');
super('errors.noMetamaskAccess');
Object.setPrototypeOf(this, AccountError.prototype);
}
}
9 changes: 9 additions & 0 deletions src/app/core/errors/models/provider/CoinbaseExtensionError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class CoinbaseExtensionError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('errors.removeCoinbaseExtension');
Object.setPrototypeOf(this, CoinbaseExtensionError.prototype);
}
}
5 changes: 3 additions & 2 deletions src/app/core/errors/models/provider/LowGasError.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class LowGasError extends RubicError {
export class LowGasError extends RubicError<ERROR_TYPE.TEXT> {
constructor() {
super('text', 'errors.lowGas');
super('errors.lowGas');
Object.setPrototypeOf(this, LowGasError.prototype);
}
}
5 changes: 3 additions & 2 deletions src/app/core/errors/models/provider/MetamaskError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MetamaskErrorComponent } from 'src/app/core/errors/components/metamask-error/metamask-error.component';
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class MetamaskError extends RubicError {
export class MetamaskError extends RubicError<ERROR_TYPE.COMPONENT> {
constructor() {
super('component', null, null, MetamaskErrorComponent);
super(MetamaskErrorComponent);
Object.setPrototypeOf(this, MetamaskError.prototype);
}
}
5 changes: 3 additions & 2 deletions src/app/core/errors/models/provider/NetworkError.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { NetworkErrorComponent } from 'src/app/core/errors/components/network-error/network-error.component';
import { RubicError } from 'src/app/core/errors/models/RubicError';
import { ERROR_TYPE } from 'src/app/core/errors/models/error-type';

export class NetworkError extends RubicError {
export class NetworkError extends RubicError<ERROR_TYPE.COMPONENT> {
constructor(public readonly networkToChoose: string) {
super('component', null, null, NetworkErrorComponent, { networkToChoose });
super(NetworkErrorComponent, { networkToChoose });
Object.setPrototypeOf(this, NetworkError.prototype);
}
}
Loading

0 comments on commit e2dab15

Please sign in to comment.