diff --git a/src/boot/errorHandling.js b/src/boot/errorHandling.js index a00beaf9..0308ab84 100644 --- a/src/boot/errorHandling.js +++ b/src/boot/errorHandling.js @@ -23,7 +23,7 @@ const errorNotification = function(error, dismiss = false) { timeout: dismiss ? 0 : 5000, message: `${errorStr}`, actions: dismiss ? [ - { label: this.$t('notification.dismiss_label'), color: 'white' }, + { label: $t('notification.dismiss_label'), color: 'white' }, ] : [], }); }; @@ -54,6 +54,10 @@ const successNotification = function(message) { // ---------- new notification layouts --------------- +let $t = function(message) { + return message; +}; + class NotificationAction { constructor(payload) { this.label = payload.label; @@ -70,6 +74,13 @@ const infoIcon = require('src/assets/icon--info.svg'); const checkIcon = require('src/assets/icon--check.svg'); const discoIcon = require('src/assets/icon--disconnected.svg'); const warningIcon = require('src/assets/icon--warning.svg'); +const icons = { + cross: crossIcon, + info: infoIcon, + check: checkIcon, + disco: discoIcon, + warning: warningIcon, +}; const html = `
@@ -92,11 +103,11 @@ const notifyMessage = function(type, icon, title, message, payload, remember = ' // action buttons const actions = []; const dismiss_btn = { - label: this.$t('notification.dismiss_label'), + label: $t('notification.dismiss_label'), class: 'c-notify__action-btn', }; const link_btn = { - label: this.$t('notification.success_see_trx_label'), + label: $t('notification.success_see_trx_label'), color: 'positive', iconRight: 'launch', class: 'c-notify__action-btn', @@ -105,7 +116,7 @@ const notifyMessage = function(type, icon, title, message, payload, remember = ' }, }; const details_btn = { - label: this.$t('notification.error_see_details_label'), + label: $t('notification.error_see_details_label'), class: 'c-notify__action-btn ', handler: () => { let content = ''; @@ -135,14 +146,14 @@ const notifyMessage = function(type, icon, title, message, payload, remember = ' Dialog.create({ class: 'c-notify__dialog', - title: this.$t('notification.error_details_title'), + title: $t('notification.error_details_title'), message: '' + content + '', html: true, }); }, }; const action_btn = { - label: this.$t(payload?.label ?? '') ?? this.$t('notification.error_see_details_label'), + label: $t(payload?.label ?? '') ?? $t('notification.error_see_details_label'), color: payload?.color ?? type === 'error' ? 'negative' : 'positive', iconRight: payload?.iconRight, class: 'c-notify__action-btn ' + payload?.class ? payload?.class : '', @@ -172,7 +183,7 @@ const notifyMessage = function(type, icon, title, message, payload, remember = ' actions.splice(0, actions.length); } - let final_message = '' + this.$t(message.toString() ?? '') + ''; + let final_message = '' + $t(message.toString() ?? '') + ''; if (Array.isArray(message)) { final_message = message.map( m => ` <${m.tag ?? 'span'} class="${m.class}">${m.text} `, @@ -208,7 +219,7 @@ const notifyMessage = function(type, icon, title, message, payload, remember = ' '{random}': random, '{remember}': remember, '{message}': final_message, - '{remember-my-choice}': this.$t('notification.dont_show_message_again'), + '{remember-my-choice}': $t('notification.dont_show_message_again'), }; const finalHtml = replaceAllOccurrences(html, replacements); @@ -225,75 +236,75 @@ const notifyMessage = function(type, icon, title, message, payload, remember = ' }; const notifySuccessTransaction = function(link) { - return notifyMessage.bind(this)( + return notifyMessage ( 'success', checkIcon, - this.$t('notification.success_title_trx').toUpperCase(), - this.$t('notification.success_message_trx'), + $t('notification.success_title_trx').toUpperCase(), + $t('notification.success_message_trx'), link, ); }; const notifySuccessMessage = function(message, payload) { - return notifyMessage.bind(this)( + return notifyMessage ( 'success', checkIcon, - this.$t('notification.success_title_trx').toUpperCase(), + $t('notification.success_title_trx').toUpperCase(), message, payload, ); }; const notifySuccessCopy = function() { - return notifyMessage.bind(this)( + return notifyMessage ( 'success', checkIcon, - this.$t('notification.success_title_copied').toUpperCase(), - this.$t('notification.success_message_copied'), + $t('notification.success_title_copied').toUpperCase(), + $t('notification.success_message_copied'), ); }; const notifyFailure = function(message, payload) { - return notifyMessage.bind(this)( + return notifyMessage ( 'error', crossIcon, - this.$t('notification.error_title').toUpperCase(), + $t('notification.error_title').toUpperCase(), message, payload, ); }; const notifyFailureWithAction = function(message, payload) { - return notifyMessage.bind(this)( + return notifyMessage ( 'error', crossIcon, - this.$t('notification.error_title').toUpperCase(), + $t('notification.error_title').toUpperCase(), message, new NotificationAction(payload), ); }; const notifyWarningWithAction = function(message, payload) { - return notifyMessage.bind(this)( + return notifyMessage ( 'error', warningIcon, - this.$t('notification.warning_title').toUpperCase(), + $t('notification.warning_title').toUpperCase(), message, new NotificationAction(payload), ); }; const notifyDisconnected = function() { - return notifyMessage.bind(this)( + return notifyMessage ( 'error', discoIcon, - this.$t('notification.error_title_disconnect'), - this.$t('notification.error_message_disconnect'), + $t('notification.error_title_disconnect'), + $t('notification.error_message_disconnect'), ); }; const notifyNeutralMessage = function(message) { - return notifyMessage.bind(this)( + return notifyMessage ( 'neutral', null, null, @@ -308,7 +319,7 @@ const notifyRememberInfo = function(title, message, payload, key) { if (dismissed[id]) { return; } - const notification = notifyMessage.bind(this)( + const notification = notifyMessage ( 'info', infoIcon, title, @@ -342,25 +353,25 @@ const notifyRememberInfo = function(title, message, payload, key) { export default boot(({ app, store }) => { - app.config.globalProperties.$errorNotification = errorNotification.bind(store); - app.config.globalProperties.$unexpectedErrorNotification = unexpectedErrorNotification.bind(store); - app.config.globalProperties.$warningNotification = warningNotification.bind(store); - app.config.globalProperties.$successNotification = successNotification.bind(store); + app.config.globalProperties.$errorNotification = errorNotification; + app.config.globalProperties.$unexpectedErrorNotification = unexpectedErrorNotification; + app.config.globalProperties.$warningNotification = warningNotification; + app.config.globalProperties.$successNotification = successNotification; store['$errorNotification'] = app.config.globalProperties.$errorNotification; store['$unexpectedErrorNotification'] = app.config.globalProperties.$unexpectedErrorNotification; store['$warningNotification'] = app.config.globalProperties.$warningNotification; store['$successNotification'] = app.config.globalProperties.$successNotification; // new Message notifications handlers - app.config.globalProperties.$notifySuccessTransaction = notifySuccessTransaction.bind(store); - app.config.globalProperties.$notifySuccessMessage = notifySuccessMessage.bind(store); - app.config.globalProperties.$notifySuccessCopy = notifySuccessCopy.bind(store); - app.config.globalProperties.$notifyFailure = notifyFailure.bind(store); - app.config.globalProperties.$notifyFailureWithAction = notifyFailureWithAction.bind(store); - app.config.globalProperties.$notifyWarningWithAction = notifyWarningWithAction.bind(store); - app.config.globalProperties.$notifyDisconnected = notifyDisconnected.bind(store); - app.config.globalProperties.$notifyNeutralMessage = notifyNeutralMessage.bind(store); - app.config.globalProperties.$notifyRememberInfo = notifyRememberInfo.bind(store); + app.config.globalProperties.$notifySuccessTransaction = notifySuccessTransaction; + app.config.globalProperties.$notifySuccessMessage = notifySuccessMessage; + app.config.globalProperties.$notifySuccessCopy = notifySuccessCopy; + app.config.globalProperties.$notifyFailure = notifyFailure; + app.config.globalProperties.$notifyFailureWithAction = notifyFailureWithAction; + app.config.globalProperties.$notifyWarningWithAction = notifyWarningWithAction; + app.config.globalProperties.$notifyDisconnected = notifyDisconnected; + app.config.globalProperties.$notifyNeutralMessage = notifyNeutralMessage; + app.config.globalProperties.$notifyRememberInfo = notifyRememberInfo; store['$notifySuccessTransaction'] = app.config.globalProperties.$notifySuccessTransaction; store['$notifySuccessMessage'] = app.config.globalProperties.$notifySuccessMessage; store['$notifySuccessCopy'] = app.config.globalProperties.$notifySuccessCopy; @@ -373,7 +384,7 @@ export default boot(({ app, store }) => { // transaction notifications handlers store['$t'] = app.config.globalProperties.$t; - + $t = app.config.globalProperties.$t; }); export { @@ -386,7 +397,11 @@ export { notifySuccessCopy, notifyFailure, notifyFailureWithAction, + notifyWarningWithAction, notifyDisconnected, notifyNeutralMessage, notifyRememberInfo, + notifyMessage, + icons, + NotificationAction, }; diff --git a/src/components/AddressField.vue b/src/components/AddressField.vue index d23f71aa..d2f63945 100644 --- a/src/components/AddressField.vue +++ b/src/components/AddressField.vue @@ -7,13 +7,9 @@ import { getIcon } from 'src/lib/token-utils'; import { toChecksumAddress } from 'src/lib/utils'; import CopyButton from 'components/CopyButton.vue'; +import { useStore } from 'vuex'; const props = defineProps({ - highlightAddress: { - type: String, - required: false, - default: '', - }, address: { type: String, required: true, @@ -38,9 +34,12 @@ const props = defineProps({ type: Boolean, default: false, }, + useHighlight: { + type: Boolean, + default: true, + }, }); -const emit = defineEmits(['highlight']); const displayName = ref(''); const fullName = ref(toChecksumAddress(props.address)); @@ -61,7 +60,9 @@ const restart = async () => { await getDisplay(); }; - +const $store = useStore(); +const setHighlightAddress = (method: string) => props.useHighlight ? $store.dispatch('general/setHighlightAddress', method) : null; +const highlightAddress = computed(() => props.useHighlight ? $store.state.general.highlightAddress : ''); watch(() => props.address, async () => { restart(); @@ -90,6 +91,7 @@ const getDisplay = async () => { return; } let address = toChecksumAddress(props.address); + fullName.value = address; if (contractName.value) { if(tokenList.value?.tokens){ tokenList.value.tokens.forEach((token: any) => { @@ -125,18 +127,14 @@ const loadContract = async () => { } }; -function emitHighlight(val: string) { - emit('highlight', val); -} -