From 9d9639b861c6572d2df71239a48bb53b0b342d93 Mon Sep 17 00:00:00 2001 From: Viterbo Date: Thu, 23 Nov 2023 12:43:27 -0300 Subject: [PATCH 01/18] removed the loalStorage.clear() that was called in all sessions --- src/App.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index d90ca7715..6071fac9e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -31,7 +31,6 @@ export default { (this as any).$t('global.new_app_version'), ); } else if (userIsNew) { - localStorage.clear(); localStorage.setItem('appVersion', currentVersion); } else if (clientVersion !== currentVersion) { localStorage.clear(); From 1d17e6d9b15684a2cea0ba576fb1472807bca720 Mon Sep 17 00:00:00 2001 From: Viterbo Date: Sat, 25 Nov 2023 12:28:02 -0300 Subject: [PATCH 02/18] avoiding local storage gets cleared every session --- src/App.vue | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/App.vue b/src/App.vue index 6071fac9e..38c78796e 100644 --- a/src/App.vue +++ b/src/App.vue @@ -11,31 +11,33 @@ export default { const userIsNew = !localStorage.getItem('account'); const currentVersion = packageInfo.version; const clientVersion = localStorage.getItem('appVersion'); - console.info('Wallet version: ', packageInfo.version); - if (clientVersion && clientVersion !== appVersionJustUpdated) { - console.info('Client version: ', clientVersion); - } + if (clientVersion !== currentVersion) { + if (clientVersion && clientVersion !== appVersionJustUpdated) { + console.info('Client version: ', clientVersion); + } - // when localstorage is cleared, we need to reload the page for it to take effect. - // however if we immediately reload the page here we cannot show a notification to the user. - // so the const appVersionUpdated lets us know after the reload that we just cleared the old localStorage - // and need to notify the user that they need to log in again - if (clientVersion === appVersionJustUpdated) { - console.info('App version mismatch, local storage cleared'); - // App version was updated, localStorage was cleared, and the page reloaded - // Now inform the user that the app was updated & have them login again, and set the client app version - localStorage.setItem('appVersion', currentVersion); - (this as any).$notifySuccessMessage( - (this as any).$t('global.new_app_version'), - ); - } else if (userIsNew) { - localStorage.setItem('appVersion', currentVersion); - } else if (clientVersion !== currentVersion) { - localStorage.clear(); - localStorage.setItem('appVersion', appVersionJustUpdated); - window.location.reload(); + // when localstorage is cleared, we need to reload the page for it to take effect. + // however if we immediately reload the page here we cannot show a notification to the user. + // so the const appVersionUpdated lets us know after the reload that we just cleared the old localStorage + // and need to notify the user that they need to log in again + if (clientVersion === appVersionJustUpdated) { + console.info('App version mismatch, local storage cleared'); + // App version was updated, localStorage was cleared, and the page reloaded + // Now inform the user that the app was updated & have them login again, and set the client app version + localStorage.setItem('appVersion', currentVersion); + (this as any).$notifySuccessMessage( + (this as any).$t('global.new_app_version'), + ); + } else if (userIsNew) { + localStorage.clear(); + localStorage.setItem('appVersion', currentVersion); + } else { + localStorage.clear(); + localStorage.setItem('appVersion', appVersionJustUpdated); + window.location.reload(); + } } }, mounted() { From 0dbf5f4ec5c184172941e1ae43f8f391b439fe41 Mon Sep 17 00:00:00 2001 From: Viterbo Date: Sun, 26 Nov 2023 22:03:12 -0300 Subject: [PATCH 03/18] adding enhanced debug tools for Antelope lib --- src/antelope/config/AntelopeConfig.ts | 260 ++++++++++++++++++ src/antelope/config/AntelopeDebug.ts | 186 +++++++++++++ src/antelope/config/index.ts | 257 +---------------- src/antelope/index.ts | 37 ++- src/antelope/stores/account.ts | 4 +- src/antelope/stores/balances.ts | 5 +- src/antelope/stores/chain.ts | 7 +- src/antelope/stores/contract.ts | 4 +- src/antelope/stores/evm.ts | 3 +- src/antelope/stores/feedback.ts | 35 +-- src/antelope/stores/history.ts | 4 +- src/antelope/stores/nfts.ts | 4 +- src/antelope/stores/platform.ts | 7 +- src/antelope/stores/profile.ts | 3 +- src/antelope/stores/resources.ts | 3 +- src/antelope/stores/rex.ts | 4 +- src/antelope/stores/tokens.ts | 4 +- src/antelope/stores/user.ts | 7 +- src/antelope/wallets/AntelopeWallets.ts | 8 +- .../authenticators/EVMAuthenticator.ts | 5 +- src/boot/antelope.ts | 7 + .../__tests__/antelope/stores/profile.spec.ts | 3 +- .../antelope/wallets/AntelopeWallets.spec.ts | 35 +-- test/jest/utils/antelope/debug.ts | 3 + test/jest/utils/antelope/index.ts | 25 +- test/jest/utils/antelope/store-feedback.ts | 8 - 26 files changed, 526 insertions(+), 402 deletions(-) create mode 100644 src/antelope/config/AntelopeConfig.ts create mode 100644 src/antelope/config/AntelopeDebug.ts create mode 100644 test/jest/utils/antelope/debug.ts diff --git a/src/antelope/config/AntelopeConfig.ts b/src/antelope/config/AntelopeConfig.ts new file mode 100644 index 000000000..3aada95d5 --- /dev/null +++ b/src/antelope/config/AntelopeConfig.ts @@ -0,0 +1,260 @@ +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 const chainNetworkNames: Record = { + 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 + + // notification 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_disconnected_handler: () => void = alert; + private __notify_neutral_message_handler: (message: string) => (() => void) = () => (() => void 0); + + // ual authenticators list getter -- + private __authenticators_getter: () => Authenticator[] = () => []; + + // localization handler -- + private __localization_handler: (key: string, payload?: Record) => 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 notifyDisconnectedHandler() { + return this.__notify_disconnected_handler; + } + + get notifyNeutralMessageHandler() { + return this.__notify_neutral_message_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 setNotifyDisconnectedHandler(handler: () => void) { + this.__notify_disconnected_handler = handler; + } + + public setNotifyNeutralMessageHandler(handler: (message: string) => (() => void)) { + this.__notify_neutral_message_handler = handler; + } + + // setting authenticators getter -- + public setAuthenticatorsGetter(getter: () => Authenticator[]) { + this.__authenticators_getter = getter; + } + + // setting translation handler -- + public setLocalizationHandler(handler: (key: string, payload?: Record) => 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; + } +} + diff --git a/src/antelope/config/AntelopeDebug.ts b/src/antelope/config/AntelopeDebug.ts new file mode 100644 index 000000000..5b3935f8b --- /dev/null +++ b/src/antelope/config/AntelopeDebug.ts @@ -0,0 +1,186 @@ + + +// creamos una clase llamada AntelopeDebug que nos permita almacenar el estado de estar + +import { ethers } from 'ethers'; +import { getAntelope } from 'src/antelope'; + +export const localStorageKey = 'antelope.debug'; +export const localStorageKeyTurnedOff = 'antelope.debug.turnedOff'; + +// en debugMode o no y que permita o anule las funciones que se ejecutan en modo debug +export class AntelopeDebug { + private __debugModeAllowed = false; // this is set to false only on production and sensitive environments + private __debugMode = false; // this represents the current state of the debug mode, can be set to true only if __debugModeAllowed is true + private __filteringMode = false; // filtering mode is atemporal state where all call to trace get printed but filtered + private __filtered = new Map(); // this is a map of stores, functions of both that have been turned off for debugging purposes + constructor() { + // + } + init() { + // if we are in localhost, we can allow debug mode + if (document.location.hostname === 'localhost') { + this.allowDebugMode(true); + } + // try to recover the last state of debugMode from the localStorage + this.recoverDebugMode(); + + // if we find the trace flag in the url, we set the debug mode to true + if (document.location.search.includes('trace=true')) { + this.setDebugMode(true); + } + // but if we find the flag trace=false, we set the debug mode to false + if (document.location.search.includes('trace=false')) { + this.setDebugMode(false); + } + } + allowDebugMode(allow: boolean) { + this.__debugModeAllowed = allow; + } + isDebugging() { + return this.__debugMode && this.__debugModeAllowed; + } + setDebugMode(debug: boolean) { + if (!this.__debugModeAllowed) { + this.__debugMode = false; + return; + } + this.__debugMode = debug; + this.saveDebugConfig(); + if (this.isDebugging()) { + this.publishAntelopeAPItoWindow(); + } else { + this.removeAntelopeAPIfromWindow(); + } + } + + /** + * this function publishes the antelope API to the window object + */ + publishAntelopeAPItoWindow() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const _window = window as any; + const ant = getAntelope(); + _window.ant = ant; + _window.antelope = ant; + } + + /** + * this function removes the antelope API from the window object + */ + removeAntelopeAPIfromWindow() { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const _window = window as any; + delete _window.ant; + delete _window.antelope; + } + + /** + * In case of debugging, this function allows to turn off a specific store, action or both + * @param key the key to turn off, can be a store name, an action name or both separated by a dot + * @param value the value to set, true to turn off, false to turn on + */ + filterKey(key: string, value: boolean) { + if (value) { + this.__filtered.set(key.toLowerCase(), value); + } else { + this.__filtered.delete(key.toLowerCase()); + } + this.saveDebugConfig(); + return `key "${key}" turned ${value ? 'off' : 'on'}`; + } + + /** + * This function put the debugger in a mode where every call to the trace function will be printed in the console + * but also put as a turned off key in the localStorage. This helps to auto filter all update processes functions + */ + startFiltering() { + this.__filteringMode = true; + return 'filtering mode started'; + } + + finishFiltering() { + this.__filteringMode = false; + this.saveDebugConfig(); + return 'filtering mode finished'; + } + + /** + * this function checks if a specific store, action or both are allowed to be traced + * @param store the store name + * @param action the action name + * @returns true if the store, action or both are allowed to be traced + */ + isAllowedToTrace(store: string, action: string) { + if (!this.isDebugging()) { + return false; + } + const keyAction = `${action.toLowerCase()}`; + const keyStore = `${store.toLowerCase()}`; + const keyBoth = `${keyStore}.${keyAction}`; + if (this.__filtered.has(keyBoth)) { + return false; + } + if (this.__filtered.has(keyAction)) { + return false; + } + if (this.__filtered.has(keyStore)) { + return false; + } + return true; + } + + /** + * this functions saves the current state of debugMode and the turned off keys in the localStorage + */ + saveDebugConfig() { + localStorage.setItem(localStorageKey, this.__debugMode.toString()); + if (this.__filtered.size === 0) { + console.error('localStorage.removeItem(localStorageKeyTurnedOff);'); + localStorage.removeItem(localStorageKeyTurnedOff); + return; + } else { + localStorage.setItem(localStorageKeyTurnedOff, JSON.stringify(Array.from(this.__filtered.entries()))); + } + } + /** + * this function recovers the last state of debugMode and the turned off keys from the localStorage + */ + recoverDebugMode() { + const turnedOff = localStorage.getItem(localStorageKeyTurnedOff); + if (turnedOff) { + const turnedOffMap = new Map(JSON.parse(turnedOff)); + this.__filtered = turnedOffMap as Map; + } + const debugMode = localStorage.getItem(localStorageKey); + if (debugMode) { + this.setDebugMode(debugMode === 'true'); + } + } + + // auxiliar useful functions for debugging + getBigNumberFrom(value: string | number) { + return ethers.BigNumber.from(value); + } + + trace(store_name:string, action: string, args: unknown[]) { + if (this.isAllowedToTrace(store_name, action)) { + const titlecase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1); + const eventName = `${titlecase(store_name)}.${action}()`; + console.debug(eventName, [...args]); + } + if (this.__filteringMode) { + this.filterKey(`${store_name}.${action}`, true); + } + } +} + + + +export type AntelopeDebugTraceType = (message: string, ...args: unknown[]) => void; + +// auxiliary tracing functions +export const createTraceFunction = (store_name: string) => function(action: string, ...args: unknown[]) { + getAntelope().config.debug.trace(store_name, action, args); +} as AntelopeDebugTraceType; + diff --git a/src/antelope/config/index.ts b/src/antelope/config/index.ts index 32854cb15..965d94484 100644 --- a/src/antelope/config/index.ts +++ b/src/antelope/config/index.ts @@ -1,256 +1,3 @@ -import { Authenticator } from 'universal-authenticator-library'; -import { App } from 'vue'; -import { getAntelope } from 'src/antelope'; -import { AntelopeError, AntelopeErrorPayload } from 'src/antelope/types'; +export * from 'src/antelope/config/AntelopeDebug'; +export * from 'src/antelope/config/AntelopeConfig'; -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_disconnected_handler: () => void = alert; - private __notify_neutral_message_handler: (message: string) => (() => void) = () => (() => void 0); - - // ual authenticators list getter -- - private __authenticators_getter: () => Authenticator[] = () => []; - - // localization handler -- - private __localization_handler: (key: string, payload?: Record) => 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() { - // - } - - init(app: App) { - this.__app = app; - } - - 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 notifyDisconnectedHandler() { - return this.__notify_disconnected_handler; - } - - get notifyNeutralMessageHandler() { - return this.__notify_neutral_message_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 setNotifyDisconnectedHandler(handler: () => void) { - this.__notify_disconnected_handler = handler; - } - - public setNotifyNeutralMessageHandler(handler: (message: string) => (() => void)) { - this.__notify_neutral_message_handler = handler; - } - - // setting authenticators getter -- - public setAuthenticatorsGetter(getter: () => Authenticator[]) { - this.__authenticators_getter = getter; - } - - // setting translation handler -- - public setLocalizationHandler(handler: (key: string, payload?: Record) => 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; - } - -} - -export const errorToString = (error: unknown) => - getAntelope().config.errorToStringHandler(error); - -export const chainNetworkNames: Record = { - telos: 'telos-evm', - 'telos-testnet': 'telos-evm-testnet', -}; diff --git a/src/antelope/index.ts b/src/antelope/index.ts index f7c27e6d9..00a9bc3c5 100644 --- a/src/antelope/index.ts +++ b/src/antelope/index.ts @@ -1,8 +1,9 @@ -import { App } from 'vue'; +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { App, toRaw } from 'vue'; import { BehaviorSubject, Subject } from 'rxjs'; import { Store } from 'pinia'; -import { AntelopeConfig, chainNetworkNames } from 'src/antelope/config/'; +import { AntelopeConfig, AntelopeDebug, chainNetworkNames } from 'src/antelope/config/'; import installPinia from 'src/antelope/stores'; import { AccountModel } from 'src/antelope/stores/account'; @@ -111,9 +112,39 @@ export class Antelope { get events() { return events; } + + extractStoreState(store: Store) { + const state = store.$state; + const result: Record = {}; + Object.keys(state).forEach((key) => { + const value = toRaw((state as any)[key] as never); + if (key.substring(0, 2) === '__') { + result[key] = value; + } + }); + return result; + } + + /** + * This function prints the state of the store in the console + */ + print() { + if (this.config.debug.isDebugging()) { + console.log('--- Antelope lib ---'); + console.log('Config: ', [this.config]); + console.log('Wallets:', [this.wallets]); + console.log(' --- Stores --- '); + const stores = this.stores; + Object.keys(stores).forEach((key) => { + const titlecase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1); + const eventName = `${titlecase(key)}:`; + console.log(eventName.padEnd(10, ' '), [this.extractStoreState((stores as any)[key])]); + }); + } + } } -const antelope = new Antelope(new AntelopeConfig(), new AntelopeWallets()); +const antelope = new Antelope(new AntelopeConfig(new AntelopeDebug()), new AntelopeWallets()); export const getAntelope = () => antelope; export const installAntelope = (app: App) => { if (app.config.globalProperties.$antelope) { diff --git a/src/antelope/stores/account.ts b/src/antelope/stores/account.ts index 1ef84f283..91f656024 100644 --- a/src/antelope/stores/account.ts +++ b/src/antelope/stores/account.ts @@ -16,7 +16,6 @@ import { Authenticator, User } from 'universal-authenticator-library'; import { defineStore } from 'pinia'; import { API } from '@greymass/eosio'; -import { createInitFunction, createTraceFunction } from 'src/antelope/stores/feedback'; import { initFuelUserWrapper } from 'src/api/fuel'; import { CURRENT_CONTEXT, @@ -26,7 +25,7 @@ import { useNftsStore, } from 'src/antelope'; import { getAntelope, useChainStore } from 'src/antelope'; -import { errorToString } from 'src/antelope/config'; +import { createTraceFunction, errorToString } from 'src/antelope/config'; import NativeChainSettings from 'src/antelope/chains/NativeChainSettings'; import { Action, @@ -114,7 +113,6 @@ export const useAccountStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - init: createInitFunction(store_name), async loginNative({ authenticator, network }: LoginNativeActionData): Promise { this.trace('loginNative', authenticator, network); let success = false; diff --git a/src/antelope/stores/balances.ts b/src/antelope/stores/balances.ts index 26aebae86..a9f5887f7 100644 --- a/src/antelope/stores/balances.ts +++ b/src/antelope/stores/balances.ts @@ -26,7 +26,7 @@ import { AntelopeError, } from 'src/antelope/types'; -import { createTraceFunction, isTracingAll } from 'src/antelope/stores/feedback'; +import { createTraceFunction } from 'src/antelope/config'; import NativeChainSettings from 'src/antelope/chains/NativeChainSettings'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; import { @@ -72,7 +72,6 @@ export const useBalancesStore = defineStore(store_name, { trace: createTraceFunction(store_name), init: () => { const balanceStore = useBalancesStore(); - useFeedbackStore().setDebug(store_name, isTracingAll()); getAntelope().events.onAccountChanged.pipe( filter(({ label, account }) => !!label && !!account), ).subscribe({ @@ -478,7 +477,7 @@ export const useBalancesStore = defineStore(store_name, { } }, updateBalance(label: string, balance: TokenBalance): void { - this.trace('updateBalance', label, balance); + this.trace('updateBalance', label, balance.str, balance.token.symbol); const index = this.__balances[label].findIndex(b => b.token.id === balance.token.id); if (index >= 0) { if ( diff --git a/src/antelope/stores/chain.ts b/src/antelope/stores/chain.ts index 7c54e86d8..537ef5d10 100644 --- a/src/antelope/stores/chain.ts +++ b/src/antelope/stores/chain.ts @@ -41,6 +41,7 @@ import TelosEVMTestnet from 'src/antelope/chains/evm/telos-evm-testnet'; import { getAntelope } from 'src/antelope'; import NativeChainSettings from 'src/antelope/chains/NativeChainSettings'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; +import { createTraceFunction } from 'src/antelope/config'; import { AntelopeError, ChainSettings, @@ -48,8 +49,6 @@ import { TokenClass, } from 'src/antelope/types'; import { ethers } from 'ethers'; -import { createInitFunction, createTraceFunction } from 'src/antelope/stores/feedback'; - export const settings: { [key: string]: ChainSettings } = { @@ -103,6 +102,8 @@ const newChainModel = (network: string, isNative: boolean): ChainModel => { export interface ChainState { // chains mapped by label __chains: { [label: Label]: ChainModel }; + // notwork settings + __networks: { [network: string]: ChainSettings }; } const store_name = 'chain'; @@ -128,7 +129,6 @@ export const useChainStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - init: createInitFunction(store_name), // Updates ---- async updateChainData(label: string): Promise { this.trace('updateChainData'); @@ -298,4 +298,5 @@ export const useChainStore = defineStore(store_name, { const chainInitialState: ChainState = { __chains: {}, + __networks: settings, }; diff --git a/src/antelope/stores/contract.ts b/src/antelope/stores/contract.ts index 6015cd2a8..08a369df7 100644 --- a/src/antelope/stores/contract.ts +++ b/src/antelope/stores/contract.ts @@ -15,7 +15,6 @@ import { defineStore } from 'pinia'; import { useAccountStore, - useFeedbackStore, useChainStore, useEVMStore, getAntelope, @@ -35,7 +34,7 @@ import { EvmContractFactoryData, } from 'src/antelope/types'; -import { createTraceFunction, isTracingAll } from 'src/antelope/stores/feedback'; +import { createTraceFunction } from 'src/antelope/config'; import EvmContract, { Erc20Transfer } from 'src/antelope/stores/utils/contracts/EvmContract'; import EvmContractFactory from 'src/antelope/stores/utils/contracts/EvmContractFactory'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; @@ -80,7 +79,6 @@ export const useContractStore = defineStore(store_name, { actions: { trace: createTraceFunction(store_name), init() { - useFeedbackStore().setDebug(store_name, isTracingAll()); this.loadCache(); }, diff --git a/src/antelope/stores/evm.ts b/src/antelope/stores/evm.ts index a1a1ee39f..9b74ca284 100644 --- a/src/antelope/stores/evm.ts +++ b/src/antelope/stores/evm.ts @@ -13,7 +13,6 @@ import { ethers } from 'ethers'; import { defineStore } from 'pinia'; import { RpcEndpoint } from 'universal-authenticator-library'; import { BehaviorSubject, filter } from 'rxjs'; -import { createInitFunction, createTraceFunction } from 'src/antelope/stores/feedback'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; import { events_signatures, functions_overrides } from 'src/antelope/stores/utils'; @@ -33,6 +32,7 @@ import { useFeedbackStore, } from 'src/antelope'; import { EVMAuthenticator, InjectedProviderAuth } from 'src/antelope/wallets'; +import { createTraceFunction } from 'src/antelope/config'; const onEvmReady = new BehaviorSubject(false); @@ -60,7 +60,6 @@ export const useEVMStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - init: createInitFunction(store_name), // actions --- async initInjectedProvider(authenticator: InjectedProviderAuth): Promise { diff --git a/src/antelope/stores/feedback.ts b/src/antelope/stores/feedback.ts index f038b1a48..eb06d2788 100644 --- a/src/antelope/stores/feedback.ts +++ b/src/antelope/stores/feedback.ts @@ -25,29 +25,7 @@ import { defineStore } from 'pinia'; import { getAntelope } from 'src/antelope'; import { toRaw } from 'vue'; - - -// auxiliary tracing functions -export const createTraceFunction = (store_name: string) => function(action: string, ...args: unknown[]) { - if (useFeedbackStore().isDebugging(store_name)) { - const titlecase = (str: string) => str.charAt(0).toUpperCase() + str.slice(1); - const eventName = `${titlecase(store_name)}.${action}()`; - console.debug(eventName, [...args]); - } -}; - - -// only if we are NOT in production mode search in the url for the trace flag -// to turn on the Antelope trace mode -let trace = false; -if (document.location.hostname !== 'wallet.telos.net') { - const urlParams = new URLSearchParams(window.location.search); - trace = urlParams.get('trace') === 'true'; -} -export const isTracingAll = () => trace; -export const createInitFunction = (store_name: string, debug?: boolean) => function() { - useFeedbackStore().setDebug(store_name, debug ?? isTracingAll()); -}; +import { createTraceFunction } from 'src/antelope/config'; // ------------------------------------------- @@ -64,8 +42,6 @@ export interface FeedbackState { __errors: Map; // progress is a map of processes name and progress value __processes: Map; - // debug flags for each store - __debug: Map; } const store_name = 'feedback'; @@ -82,7 +58,6 @@ export const useFeedbackStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - init: createInitFunction(store_name), // Loading ---- setLoading(name: string) { if (!this.__loading.includes(name)) { @@ -112,13 +87,6 @@ export const useFeedbackStore = defineStore(store_name, { unsetProgress(name: string) { this.__processes.delete(name); }, - // Debug mode ---- - setDebug(store_name: string, value: boolean) { - this.__debug.set(store_name, value); - }, - isDebugging(store_name: string) { - return this.__debug.get(store_name) || false; - }, }, }); @@ -126,7 +94,6 @@ const feedbackiInitialState: FeedbackState = { __loading: [], __errors: new Map(), __processes: new Map(), - __debug: new Map(), }; diff --git a/src/antelope/stores/history.ts b/src/antelope/stores/history.ts index 5778cc886..fec057f2f 100644 --- a/src/antelope/stores/history.ts +++ b/src/antelope/stores/history.ts @@ -15,8 +15,6 @@ import { defineStore } from 'pinia'; import { - createTraceFunction, - isTracingAll, useFeedbackStore, } from 'src/antelope/stores/feedback'; import { @@ -49,6 +47,7 @@ import { formatUnits } from 'ethers/lib/utils'; import { getGasInTlos, WEI_PRECISION } from 'src/antelope/stores/utils'; import { convertCurrency } from 'src/antelope/stores/utils/currency-utils'; import { dateIsWithinXMinutes } from 'src/antelope/stores/utils/date-utils'; +import { createTraceFunction } from 'src/antelope/config'; export const transfers_filter_limit = 10000; @@ -101,7 +100,6 @@ export const useHistoryStore = defineStore(store_name, { const self = useHistoryStore(); self.clearEvmNftTransfers(); self.clearEvmTransactions(); - useFeedbackStore().setDebug(store_name, isTracingAll()); getAntelope().events.onAccountChanged.subscribe({ next: ({ account }) => { if (account) { diff --git a/src/antelope/stores/nfts.ts b/src/antelope/stores/nfts.ts index 8655d26d6..c611149ec 100644 --- a/src/antelope/stores/nfts.ts +++ b/src/antelope/stores/nfts.ts @@ -17,11 +17,10 @@ import { } from 'src/antelope/types'; import { useFeedbackStore, getAntelope, useChainStore, useEVMStore, CURRENT_CONTEXT } from 'src/antelope'; -import { createTraceFunction, isTracingAll } from 'src/antelope/stores/feedback'; import { toRaw } from 'vue'; import { EvmAccountModel, useAccountStore } from 'src/antelope/stores/account'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; -import { errorToString } from 'src/antelope/config'; +import { createTraceFunction, errorToString } from 'src/antelope/config'; import { truncateAddress } from 'src/antelope/stores/utils/text-utils'; import { subscribeForTransactionReceipt } from 'src/antelope/stores/utils/trx-utils'; @@ -122,7 +121,6 @@ export const useNftsStore = defineStore(store_name, { trace: createTraceFunction(store_name), init: () => { const self = useNftsStore(); - useFeedbackStore().setDebug(store_name, isTracingAll()); getAntelope().events.onAccountChanged.subscribe({ next: async ({ label, account }) => { if (label) { diff --git a/src/antelope/stores/platform.ts b/src/antelope/stores/platform.ts index 2a3355808..b28bf09d3 100644 --- a/src/antelope/stores/platform.ts +++ b/src/antelope/stores/platform.ts @@ -15,11 +15,7 @@ import { defineStore } from 'pinia'; -import { - useFeedbackStore, -} from 'src/antelope'; -import { errorToString } from 'src/antelope/config'; -import { createTraceFunction, isTracingAll } from 'src/antelope/stores/feedback'; +import { createTraceFunction, errorToString } from 'src/antelope/config'; export interface PlatformState { __is_browser: boolean; @@ -42,7 +38,6 @@ export const usePlatformStore = defineStore(store_name, { actions: { trace: createTraceFunction(store_name), init: () => { - useFeedbackStore().setDebug(store_name, isTracingAll()); const platform = usePlatformStore(); // detect brave browser diff --git a/src/antelope/stores/profile.ts b/src/antelope/stores/profile.ts index 198bf304d..7ed437ee9 100644 --- a/src/antelope/stores/profile.ts +++ b/src/antelope/stores/profile.ts @@ -6,7 +6,7 @@ import { defineStore } from 'pinia'; -import { createInitFunction, createTraceFunction } from 'src/antelope/stores/feedback'; +import { createTraceFunction } from 'src/antelope/config'; export interface ProfileState { @@ -21,7 +21,6 @@ export const useProfileStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - init: createInitFunction(store_name), }, }); diff --git a/src/antelope/stores/resources.ts b/src/antelope/stores/resources.ts index f992a3c8c..01ecd530e 100644 --- a/src/antelope/stores/resources.ts +++ b/src/antelope/stores/resources.ts @@ -11,7 +11,7 @@ import { defineStore } from 'pinia'; -import { createInitFunction, createTraceFunction } from 'src/antelope/stores/feedback'; +import { createTraceFunction } from 'src/antelope/config'; export interface ResourcesState { __: string; @@ -25,7 +25,6 @@ export const useResourcesStore = defineStore(store_name, { }, actions: { trace: createTraceFunction(store_name), - init: createInitFunction(store_name), }, }); diff --git a/src/antelope/stores/rex.ts b/src/antelope/stores/rex.ts index 8edfe51f8..db370ef21 100644 --- a/src/antelope/stores/rex.ts +++ b/src/antelope/stores/rex.ts @@ -9,8 +9,6 @@ import { ethers } from 'ethers'; import { defineStore } from 'pinia'; import { filter } from 'rxjs'; import { - isTracingAll, - createTraceFunction, useFeedbackStore, } from 'src/antelope/stores/feedback'; import { AntelopeError, EvmRexDeposit, Label, TransactionResponse } from 'src/antelope/types'; @@ -21,6 +19,7 @@ import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; import { WEI_PRECISION } from 'src/antelope/stores/utils'; import { subscribeForTransactionReceipt } from 'src/antelope/stores/utils/trx-utils'; import { formatUnstakePeriod } from 'src/antelope/stores/utils/date-utils'; +import { createTraceFunction } from 'src/antelope/config'; export interface RexModel { @@ -66,7 +65,6 @@ export const useRexStore = defineStore(store_name, { actions: { trace: createTraceFunction(store_name), init: () => { - useFeedbackStore().setDebug(store_name, isTracingAll()); getAntelope().events.onAccountChanged.pipe( filter(({ label, account }) => !!label && !!account), ).subscribe({ diff --git a/src/antelope/stores/tokens.ts b/src/antelope/stores/tokens.ts index 88f17adb4..274c2f929 100644 --- a/src/antelope/stores/tokens.ts +++ b/src/antelope/stores/tokens.ts @@ -11,9 +11,8 @@ import { } from 'src/antelope/types'; import { getAntelope, useFeedbackStore, useChainStore, CURRENT_CONTEXT } from 'src/antelope'; import { toRaw } from 'vue'; -import { errorToString } from 'src/antelope/config'; +import { createTraceFunction, errorToString } from 'src/antelope/config'; import { filter } from 'rxjs'; -import { createTraceFunction, isTracingAll } from 'src/antelope/stores/feedback'; import { ChainModel } from 'src/antelope/stores/chain'; import { dateIsWithinXMinutes } from 'src/antelope/stores/utils/date-utils'; import { getTokenPriceDataFromIndexer } from 'src/api/price'; @@ -50,7 +49,6 @@ export const useTokensStore = defineStore(store_name, { actions: { trace: createTraceFunction(store_name), init: () => { - useFeedbackStore().setDebug(store_name, isTracingAll()); getAntelope().events.onNetworkChanged.pipe( filter(e => e.label === CURRENT_CONTEXT), ).subscribe({ diff --git a/src/antelope/stores/user.ts b/src/antelope/stores/user.ts index d0cb971c6..e66e63327 100644 --- a/src/antelope/stores/user.ts +++ b/src/antelope/stores/user.ts @@ -13,12 +13,8 @@ */ import { defineStore } from 'pinia'; -import { errorToString } from 'src/antelope/config'; +import { createTraceFunction, errorToString } from 'src/antelope/config'; import { AccountModel } from 'src/antelope/stores/account'; -import { - createTraceFunction, - isTracingAll, -} from 'src/antelope/stores/feedback'; import { getAntelope, useFeedbackStore } from 'src/antelope'; export type AccountList = Array; @@ -84,7 +80,6 @@ export const useUserStore = defineStore(store_name, { actions: { trace: createTraceFunction(store_name), init: () => { - useFeedbackStore().setDebug(store_name, isTracingAll()); const ant = getAntelope(); // we want to react when the logged account changes ant.events.onLoggedIn.subscribe((acc: AccountModel) => useUserStore().handleAccountLoggedIn(acc)); diff --git a/src/antelope/wallets/AntelopeWallets.ts b/src/antelope/wallets/AntelopeWallets.ts index 69bf429d8..26fca5477 100644 --- a/src/antelope/wallets/AntelopeWallets.ts +++ b/src/antelope/wallets/AntelopeWallets.ts @@ -1,6 +1,3 @@ -import { isTracingAll } from 'src/antelope/stores/feedback'; -import { useFeedbackStore } from 'src/antelope/stores/feedback'; -import { createTraceFunction } from 'src/antelope/stores/feedback'; import { EVMAuthenticator } from 'src/antelope/wallets/authenticators/EVMAuthenticator'; import { useAccountStore } from 'src/antelope/stores/account'; import { CURRENT_CONTEXT, useChainStore } from 'src/antelope'; @@ -8,19 +5,20 @@ import { RpcEndpoint } from 'universal-authenticator-library'; import { ethers } from 'ethers'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; import { AntelopeError } from 'src/antelope/types'; +import { AntelopeDebugTraceType, createTraceFunction } from 'src/antelope/config'; const name = 'AntelopeWallets'; export class AntelopeWallets { - private trace: (message: string, ...args: unknown[]) => void; + private trace: AntelopeDebugTraceType; private authenticators: Map = new Map(); constructor() { this.trace = createTraceFunction(name); } init() { - useFeedbackStore().setDebug(name, isTracingAll()); + this.trace('init'); } addEVMAuthenticator(authenticator: EVMAuthenticator) { diff --git a/src/antelope/wallets/authenticators/EVMAuthenticator.ts b/src/antelope/wallets/authenticators/EVMAuthenticator.ts index 559bbc799..3840be83a 100644 --- a/src/antelope/wallets/authenticators/EVMAuthenticator.ts +++ b/src/antelope/wallets/authenticators/EVMAuthenticator.ts @@ -4,22 +4,21 @@ import { SendTransactionResult, WriteContractResult } from '@wagmi/core'; import { BigNumber, ethers } from 'ethers'; import { CURRENT_CONTEXT, getAntelope, useAccountStore, useContractStore } from 'src/antelope'; import EVMChainSettings from 'src/antelope/chains/EVMChainSettings'; +import { AntelopeDebugTraceType, createTraceFunction } from 'src/antelope/config'; import { useChainStore } from 'src/antelope/stores/chain'; import { useEVMStore } from 'src/antelope/stores/evm'; -import { createTraceFunction, isTracingAll, useFeedbackStore } from 'src/antelope/stores/feedback'; import { usePlatformStore } from 'src/antelope/stores/platform'; import { AntelopeError, NftTokenInterface, ERC1155_TYPE, ERC721_TYPE, EvmABI, EvmABIEntry, EvmFunctionParam, EvmTransactionResponse, ExceptionError, TokenClass, addressString, erc20Abi, erc721Abi, escrowAbiWithdraw, stlosAbiDeposit, stlosAbiWithdraw, wtlosAbiDeposit, wtlosAbiWithdraw, erc1155Abi } from 'src/antelope/types'; export abstract class EVMAuthenticator { readonly label: string; - readonly trace: (message: string, ...args: unknown[]) => void; + readonly trace: AntelopeDebugTraceType; constructor(label: string) { this.label = label; const name = `${this.getName()}(${label})`; this.trace = createTraceFunction(name); - useFeedbackStore().setDebug(name, isTracingAll()); } /** diff --git a/src/boot/antelope.ts b/src/boot/antelope.ts index 7ebcf3461..edfb828f1 100644 --- a/src/boot/antelope.ts +++ b/src/boot/antelope.ts @@ -93,6 +93,13 @@ export default boot(({ app }) => { ant.config.setIndexerHealthThresholdSeconds(10); ant.config.setIndexerHealthCheckInterval(5000); + // We only allow debug mode if we are not in production or in a sensitive environment + ant.config.debug.allowDebugMode( + process.env.NODE_ENV !== 'production' || + document.location.hostname === 'localhost' || + document.location.hostname.includes('netlify'), + ); + // Finally, we check if the url has the network parameter and if so, we connect to that network // Otherwise we just let the store decide which network to connect to const network = new URLSearchParams(window.location.search).get('network'); diff --git a/test/jest/__tests__/antelope/stores/profile.spec.ts b/test/jest/__tests__/antelope/stores/profile.spec.ts index 5e16ee0c3..5ec5f8d10 100644 --- a/test/jest/__tests__/antelope/stores/profile.spec.ts +++ b/test/jest/__tests__/antelope/stores/profile.spec.ts @@ -1,8 +1,7 @@ import { setActivePinia, createPinia } from 'pinia'; // Mockups -jest.mock('src/antelope/stores/feedback', () => ({ - createInitFunction: jest.fn(), +jest.mock('src/antelope/config', () => ({ createTraceFunction: jest.fn(), })); diff --git a/test/jest/__tests__/antelope/wallets/AntelopeWallets.spec.ts b/test/jest/__tests__/antelope/wallets/AntelopeWallets.spec.ts index 39bd6d326..263d47ffc 100644 --- a/test/jest/__tests__/antelope/wallets/AntelopeWallets.spec.ts +++ b/test/jest/__tests__/antelope/wallets/AntelopeWallets.spec.ts @@ -8,15 +8,20 @@ import { jest } from '@jest/globals'; import { useFeedbackStore, - createTraceFunction, - isTracingAll, } from 'test/jest/utils/antelope/store-feedback'; // Mocking the createTraceFunction jest.mock('src/antelope/stores/feedback', () => ({ useFeedbackStore, +})); + +import { + createTraceFunction, +} from 'test/jest/utils/antelope/debug'; + +// Mocking the createTraceFunction +jest.mock('src/antelope/config', () => ({ createTraceFunction, - isTracingAll, })); import { @@ -51,22 +56,6 @@ describe('AntelopeWallets', () => { wallets = new AntelopeWallets(); }); - /* - // Code to test: - export class AntelopeWallets { - - private trace: (message: string, ...args: unknown[]) => void; - private authenticators: Map = new Map(); - constructor() { - this.trace = createTraceFunction(name); - } - - init() { - useFeedbackStore().setDebug(name, isTracingAll()); - } - } - */ - describe('Initial state', () => { it('should have the correct initial state', () => { // trace should be a function @@ -78,14 +67,6 @@ describe('AntelopeWallets', () => { }); }); - describe('init function', () => { - it('should initialize the feedback store', () => { - const setDebugSpy = jest.spyOn(useFeedbackStore(), 'setDebug'); - wallets.init(); - expect(setDebugSpy).toHaveBeenCalledWith('AntelopeWallets', false); - }); - }); - /* // Code to test: diff --git a/test/jest/utils/antelope/debug.ts b/test/jest/utils/antelope/debug.ts new file mode 100644 index 000000000..1df3a0632 --- /dev/null +++ b/test/jest/utils/antelope/debug.ts @@ -0,0 +1,3 @@ + +export const createTraceFunction = jest.fn().mockImplementation(() => jest.fn()); +export const errorToString = jest.fn().mockImplementation(e => e); diff --git a/test/jest/utils/antelope/index.ts b/test/jest/utils/antelope/index.ts index 3b3a2d2f4..1ef4ebe81 100644 --- a/test/jest/utils/antelope/index.ts +++ b/test/jest/utils/antelope/index.ts @@ -1,9 +1,3 @@ -import { useChainStore } from 'test/jest/utils/antelope/store-chain'; -import { useAccountStore } from 'test/jest/utils/antelope/store-account'; -import { useEVMStore } from 'test/jest/utils/antelope/store-evm'; -import { useFeedbackStore } from 'test/jest/utils/antelope/store-feedback'; -import { usePlatformStore } from 'test/jest/utils/antelope/store-platform'; - // -------- Core -------- export const getAntelope = jest.fn().mockImplementation(() => ({ events: { @@ -27,24 +21,9 @@ export const getAntelope = jest.fn().mockImplementation(() => ({ }, })); -const CURRENT_CONTEXT = 'current'; - -/* -jest.mock('src/antelope', () => ({ - useChainStore, - useAccountStore, - useEVMStore, - useFeedbackStore, - usePlatformStore, - getAntelope, - CURRENT_CONTEXT, -})); -*/ - -jest.mock('src/antelope/config', () => ({ - errorToString: jest.fn().mockImplementation(e => e), -})); +export const CURRENT_CONTEXT = 'current'; +export * from 'test/jest/utils/antelope/debug'; export * from 'test/jest/utils/antelope/ethers'; export * from 'test/jest/utils/antelope/mockData'; export * from 'test/jest/utils/antelope/store-account'; diff --git a/test/jest/utils/antelope/store-feedback.ts b/test/jest/utils/antelope/store-feedback.ts index d5d010908..8dac10709 100644 --- a/test/jest/utils/antelope/store-feedback.ts +++ b/test/jest/utils/antelope/store-feedback.ts @@ -15,14 +15,8 @@ const FeedbackStore = { ...FeedbackGetters, ...FeedbackActions }; const useFeedbackStore = jest.fn().mockImplementation(() => FeedbackStore); -const createTraceFunction = jest.fn().mockImplementation(() => jest.fn()); - -const isTracingAll = jest.fn().mockImplementation(() => false); - jest.mock('src/antelope/stores/feedback', () => ({ useFeedbackStore, - createTraceFunction, - isTracingAll, })); export { @@ -30,6 +24,4 @@ export { FeedbackGetters, FeedbackActions, useFeedbackStore, - createTraceFunction, - isTracingAll, }; From bde97d87efd0ab3cbbda1c7e7168a575465a4adc Mon Sep 17 00:00:00 2001 From: Viterbo Date: Thu, 30 Nov 2023 10:38:33 -0300 Subject: [PATCH 04/18] solving conflicts --- src/App.vue | 1 - src/antelope/config/AntelopeConfig.ts | 22 +++++++++++++++++++++- src/antelope/config/AntelopeDebug.ts | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index e1547eaa5..5950ecb07 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,6 +1,5 @@