Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug Tools Update #747

Merged
merged 25 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9d9639b
removed the loalStorage.clear() that was called in all sessions
Viterbo Nov 23, 2023
1d17e6d
avoiding local storage gets cleared every session
Viterbo Nov 25, 2023
0dbf5f4
adding enhanced debug tools for Antelope lib
Viterbo Nov 27, 2023
81ee7be
pull develop
Viterbo Nov 29, 2023
e8a6629
Merge branch 'develop' of https://github.com/telosnetwork/telos-walle…
Viterbo Nov 30, 2023
bde97d8
solving conflicts
Viterbo Nov 30, 2023
dbe7220
fix the home page style
Viterbo Nov 30, 2023
c54a0c8
Merge branch '703-the-home-page-needs-styling-adjustments' of https:/…
Viterbo Nov 30, 2023
02f9eec
pull from develop
Viterbo Nov 30, 2023
6c14bcb
minor temporal fix
Viterbo Nov 30, 2023
e1b9881
solving conflicts
Viterbo Jan 8, 2024
a9164de
Antlib stores dependency now are cleaner
Viterbo Jan 9, 2024
c43c023
remove console log
Viterbo Jan 9, 2024
e1c9bd4
to remove Account store dependencies we introduce onClear event
Viterbo Jan 9, 2024
fc5d827
solving tests
Viterbo Jan 9, 2024
22cf9dc
rename some debug functions
Viterbo Jan 9, 2024
cc94098
shortcut to get debug config
Viterbo Jan 9, 2024
302125b
adding some logouts to debug
Viterbo Jan 9, 2024
0b474c6
test 1
Viterbo Jan 9, 2024
383b73c
test 2
Viterbo Jan 9, 2024
e0a7d69
fixing when set Alow gets executed after set Debug mode
Viterbo Jan 9, 2024
a54cfd5
Update src/antelope/stores/chain.ts
Viterbo Jan 10, 2024
067879b
addressing team feedback
Viterbo Jan 10, 2024
cb1bcef
Merge pull request #690 from telosnetwork/689-debug-tools-for-antelop…
donnyquixotic Jan 10, 2024
f9a85a5
Bump follow-redirects from 1.15.2 to 1.15.4
dependabot[bot] Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 291 additions & 0 deletions src/antelope/config/AntelopeConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,291 @@
import { Authenticator } from 'universal-authenticator-library';
import { App } from 'vue';
import { getAntelope } from 'src/antelope';
import { AntelopeError, AntelopeErrorPayload } from 'src/antelope/types';
import { AntelopeDebug } from 'src/antelope/config/AntelopeDebug';

export interface ComplexMessage {
tag: string,
class: string,
text: string,
}

export const chainNetworkNames: Record<string, string> = {
telos: 'telos-evm',
'telos-testnet': 'telos-evm-testnet',
};

export const errorToString = (error: unknown) =>
getAntelope().config.errorToStringHandler(error);


export class AntelopeConfig {
transactionError(description: string, error: unknown): AntelopeError {
if (error instanceof AntelopeError) {
return error as AntelopeError;
}
const str = this.errorToStringHandler(error);
// if it matches antelope.*.error_*
if (str.match(/^antelope\.[a-z0-9_]+\.error_/)) {
return new AntelopeError(str, { error });
} else {
return new AntelopeError(description, { error: str });
}
}

// indexer health threshold --
private __indexer_health_threshold = 10; // 10 seconds

// indexer health check interval --
private __indexer_health_check_interval = 1000 * 60 * 5; // 5 minutes expressed in milliseconds

// notifucation handlers --
private __notify_error_handler: (message: string) => void = m => alert(`Error: ${m}`);
private __notify_success_handler: (message: string) => void = alert;
private __notify_warning_handler: (message: string) => void = alert;

// notification handlers --
private __notify_successful_trx_handler: (link: string) => void = alert;
private __notify_success_message_handler: (message: string, payload?: never) => void = alert;
private __notify_success_copy_handler: () => void = alert;
private __notify_failure_message_handler: (message: string, payload?: AntelopeErrorPayload) => void = alert;
private __notify_failure_action_handler: (message: string, payload?: AntelopeErrorPayload) => void = alert;
private __notify_warning_action_handler: (message: string, payload?: AntelopeErrorPayload) => void = alert;
private __notify_disconnected_handler: () => void = alert;
private __notify_neutral_message_handler: (message: string) => (() => void) = () => (() => void 0);
private __notify_remember_info_handler: (title: string, message: string | ComplexMessage[], payload: string, key: string) => (() => void) = () => (() => void 0);

// ual authenticators list getter --
private __authenticators_getter: () => Authenticator[] = () => [];

// localization handler --
private __localization_handler: (key: string, payload?: Record<string, unknown>) => string = (key: string) => key;

// transaction error handler --
private __transaction_error_handler: (err: AntelopeError, trxFailed: string) => void = () => void 0;

// error to string handler --
private __error_to_string_handler: (error: unknown) => string = (error: unknown) => {
try {

type EVMError = {code:string};
const evmErr = error as EVMError;

switch (evmErr.code) {
case 'CALL_EXCEPTION': return 'antelope.evm.error_call_exception';
case 'INSUFFICIENT_FUNDS': return 'antelope.evm.error_insufficient_funds';
case 'MISSING_NEW': return 'antelope.evm.error_missing_new';
case 'NONCE_EXPIRED': return 'antelope.evm.error_nonce_expired';
case 'NUMERIC_FAULT': return 'antelope.evm.error_numeric_fault';
case 'REPLACEMENT_UNDERPRICED': return 'antelope.evm.error_replacement_underpriced';
case 'TRANSACTION_REPLACED': return 'antelope.evm.error_transaction_replaced';
case 'UNPREDICTABLE_GAS_LIMIT': return 'antelope.evm.error_unpredictable_gas_limit';
case 'USER_REJECTED': return 'antelope.evm.error_user_rejected';
case 'ACTION_REJECTED': return 'antelope.evm.error_transaction_canceled';
}

if (typeof error === 'string') {
return error;
}
if (typeof error === 'number') {
return error.toString();
}
if (typeof error === 'boolean') {
return error.toString();
}
if (error instanceof Error) {
return error.message;
}
if (typeof error === 'undefined') {
return 'undefined';
}
if (typeof error === 'object') {
if (error === null) {
return 'null';
}
if (Array.isArray(error)) {
return error.map(a => this.__error_to_string_handler(a)).join(', ');
}
return JSON.stringify(error);
}
return 'unknown';
} catch (er) {
return 'error';
}
}

// Vue.App holder --
private __app: App | null = null;

constructor(
public debug: AntelopeDebug,
) {
//
}

init(app: App) {
this.__app = app;
this.debug.init();
}

get app() {
return this.__app;
}

get indexerHealthThresholdSeconds() {
return this.__indexer_health_threshold;
}

get indexerHealthCheckInterval() {
return this.__indexer_health_check_interval;
}

get notifyErrorHandler() {
return this.__notify_error_handler;
}

get notifySuccessHandler() {
return this.__notify_success_handler;
}

get notifyWarningHandler() {
return this.__notify_warning_handler;
}

get notifySuccessfulTrxHandler() {
return this.__notify_successful_trx_handler;
}

get notifySuccessMessageHandler() {
return this.__notify_success_message_handler;
}

get notifySuccessCopyHandler() {
return this.__notify_success_copy_handler;
}

get notifyFailureMessage() {
return this.__notify_failure_message_handler;
}

get notifyFailureWithAction() {
return this.__notify_failure_action_handler;
}

get notifyWarningWithAction() {
return this.__notify_warning_action_handler;
}

get notifyDisconnectedHandler() {
return this.__notify_disconnected_handler;
}

get notifyNeutralMessageHandler() {
return this.__notify_neutral_message_handler;
}

get notifyRememberInfoHandler() {
return this.__notify_remember_info_handler;
}

get authenticatorsGetter() {
return this.__authenticators_getter;
}

get localizationHandler() {
return this.__localization_handler;
}

get transactionErrorHandler() {
return this.__transaction_error_handler;
}

get errorToStringHandler() {
return this.__error_to_string_handler;
}

// setting indexer constants --
public setIndexerHealthThresholdSeconds(threshold: number) {
this.__indexer_health_threshold = threshold;
}

public setIndexerHealthCheckInterval(interval: number) {
this.__indexer_health_check_interval = interval;
}

// setting notification handlers --
public setNotifyErrorHandler(handler: (message: string) => void) {
this.__notify_error_handler = handler;
}

public setNotifySuccessHandler(handler: (message: string) => void) {
this.__notify_success_handler = handler;
}

public setNotifyWarningHandler(handler: (message: string) => void) {
this.__notify_warning_handler = handler;
}

public setNotifySuccessfulTrxHandler(handler: (link: string) => void) {
this.__notify_successful_trx_handler = handler;
}

public setNotifySuccessMessageHandler(handler: (message: string, payload?: never) => void) {
this.__notify_success_message_handler = handler;
}

public setNotifySuccessCopyHandler(handler: () => void) {
this.__notify_success_copy_handler = handler;
}

public setNotifyFailureMessage(handler: (message: string, payload?: AntelopeErrorPayload) => void) {
this.__notify_failure_message_handler = handler;
}

public setNotifyFailureWithAction(handler: (message: string, payload?: AntelopeErrorPayload) => void) {
this.__notify_failure_action_handler = handler;
}

public setNotifyWarningWithAction(handler: (message: string, payload?: AntelopeErrorPayload) => void) {
this.__notify_warning_action_handler = handler;
}

public setNotifyDisconnectedHandler(handler: () => void) {
this.__notify_disconnected_handler = handler;
}

public setNotifyNeutralMessageHandler(handler: (message: string) => (() => void)) {
this.__notify_neutral_message_handler = handler;
}

public setNotifyRememberInfoHandler(handler: (
title: string,
message: string | ComplexMessage[],
payload: string,
key: string,
) => (() => void)) {
this.__notify_remember_info_handler = handler;
}

// setting authenticators getter --
public setAuthenticatorsGetter(getter: () => Authenticator[]) {
this.__authenticators_getter = getter;
}

// setting translation handler --
public setLocalizationHandler(handler: (key: string, payload?: Record<string, unknown>) => string) {
this.__localization_handler = handler;
}

// setting transaction error handler --
public setTransactionErrorHandler(handler: (err: AntelopeError, trxFailed: string) => void) {
this.__transaction_error_handler = handler;
}

// setting error to string handler --
public setErrorToStringHandler(handler: (catched: unknown) => string) {
this.__error_to_string_handler = handler;
}

}

Loading
Loading