From 5b9f63e68f3aaec1cb1ae35ce8e1d8fab5f46f35 Mon Sep 17 00:00:00 2001 From: hassnian <44554284+hassnian@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:42:53 +0500 Subject: [PATCH 1/2] fix(swaps): trader address validation is not reactive - fix: AddressChecker.vue emitting isValid when addresss is '' - ref: adapt Transfer.vue check if address is empty - ref: AddressInput.vue dont show error input if address is empty with address check --- components/shared/AddressChecker.vue | 6 +----- components/shared/AddressInput.vue | 21 +++++++++------------ components/swap/landing.vue | 28 +++++++++++++++++++++++----- components/transfer/Transfer.vue | 2 +- locales/en.json | 1 + 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/components/shared/AddressChecker.vue b/components/shared/AddressChecker.vue index 475aebfb2c..3790485194 100644 --- a/components/shared/AddressChecker.vue +++ b/components/shared/AddressChecker.vue @@ -221,11 +221,7 @@ watch(showAddressCheck, () => { }) watch(addressCheck, (check) => { - let isValid = !check - - if (!isValid) { - isValid = check ? check.valid : false - } + const isValid = check ? check.valid : false emit('check', isValid) }) diff --git a/components/shared/AddressInput.vue b/components/shared/AddressInput.vue index 0b2d17f682..604587c7f7 100644 --- a/components/shared/AddressInput.vue +++ b/components/shared/AddressInput.vue @@ -55,25 +55,22 @@ const props = withDefaults( const { chainProperties } = useChain() const error = ref('') -const isAddressCheckValid = ref(true) +const isAddressCheckValid = ref() const ss58Format = computed(() => chainProperties.value?.ss58Format) const variant = computed(() => { - if (props.isInvalid || error.value || !isAddressCheckValid.value) { + const isNotEmpty = Boolean(inputValue.value) + const isInvalidWithAddressCheck = props.withAddressCheck && !isAddressCheckValid.value && isNotEmpty + + if (props.isInvalid || error.value || isInvalidWithAddressCheck) { return 'danger' } - const isNotEmpty = !!inputValue.value const isValidAddress = isAddress(inputValue.value) - const isSuccessWithAddressCheck - = props.withAddressCheck && (!props.isInvalid || isAddressCheckValid.value) - const isSuccesssWithoutAddressCheck - = !props.withAddressCheck && isValidAddress - - if ( - isNotEmpty - && (isSuccessWithAddressCheck || isSuccesssWithoutAddressCheck) - ) { + const isSuccessWithAddressCheck = props.withAddressCheck && (!props.isInvalid || isAddressCheckValid.value) + const isSuccesssWithoutAddressCheck = !props.withAddressCheck && isValidAddress + + if (isNotEmpty && (isSuccessWithAddressCheck || isSuccesssWithoutAddressCheck)) { return 'success' } diff --git a/components/swap/landing.vue b/components/swap/landing.vue index fea924305e..b02420c860 100644 --- a/components/swap/landing.vue +++ b/components/swap/landing.vue @@ -37,19 +37,19 @@
@@ -61,9 +61,27 @@