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

fix: Swap landing not disabling submit button on wrong address #11255

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 1 addition & 5 deletions components/shared/AddressChecker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
21 changes: 9 additions & 12 deletions components/shared/AddressInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,22 @@ const props = withDefaults(

const { chainProperties } = useChain()
const error = ref<string | null>('')
const isAddressCheckValid = ref<boolean>(true)
const isAddressCheckValid = ref<boolean>()
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'
}

Expand Down
37 changes: 32 additions & 5 deletions components/swap/landing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@
<form @submit.prevent="handleSubmit">
<AddressInput
v-model="traderAddress"
:is-invalid="isYourAddress"
placeholder="Enter wallet address"
:strict="false"
empty-on-error
with-address-check
@check="handleAddressCheck"
/>

<NeoButton
type="submit"
:label="$t('swap.beginSwap')"
:label="label"
size="large"
class="text-base my-5 capitalize"
expanded
:disabled="traderAddress === '' || traderAddress === accountId"
:disabled="disabled"
native-type="submit"
variant="primary"
/>
Expand All @@ -61,9 +61,36 @@
<script lang="ts" setup>
import { NeoButton } from '@kodadot1/brick'

const { accountId } = useAuth()
const { isCurrentOwner } = useAuth()
const { $i18n } = useNuxtApp()

const traderAddress = ref('')
const isTraderAddressValid = ref(false)
const isYourAddress = ref(false)

const isAddressEmpty = computed(() => !traderAddress.value)
const disabled = computed(() => isAddressEmpty.value || isYourAddress.value || !isTraderAddressValid.value)

const label = computed(() => {
if (isYourAddress.value) {
return $i18n.t('swap.cantSwapWithYourself')
}

if (isAddressEmpty.value) {
return $i18n.t('transaction.inputAddressFirst')
}

if (!isTraderAddressValid.value) {
return $i18n.t('transaction.addressIncorrect')
}

return $i18n.t('swap.beginSwap')
})

const handleAddressCheck = (isValid: boolean) => {
isTraderAddressValid.value = isValid
isYourAddress.value = isTraderAddressValid.value ? isCurrentOwner(traderAddress.value) : false
}

const handleSubmit = async () => {
await navigateTo({ name: 'prefix-swap-id', params: { id: traderAddress.value } })
Expand Down
2 changes: 1 addition & 1 deletion components/transfer/Transfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ const onUsdFieldChange = (target: TargetAddress) => {
}

const handleAddressCheck = (target: TargetAddress, isValid: boolean) => {
target.isInvalid = !isValid
target.isInvalid = !target.address ? undefined : !isValid

targetAddresses.value = [...targetAddresses.value]
}
Expand Down
1 change: 1 addition & 0 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,7 @@
"acceptSwap": "Accepting Swap",
"addToken": "Add Token",
"beginSwap": "Begin Swap offer",
"cantSwapWithYourself": "You can't swap with yourself",
"clickOnNft": "Click on any NFT to add it to your swap list.",
"connectTrader": "Connect with a trader",
"connectTraderInfo": "Enter the wallet address of the trader you want to engage with, and we’ll guide you through the secure process of making a swap offer.",
Expand Down
Loading