Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

refactor: adjust business transaction form validation #1736

Merged
merged 16 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('TransactionFormBusinessUpdate', () => {
it('should be enabled if form is valid', async () => {
wrapper.vm.$v.form.fee.$model = (0.1 * 1e8).toString()
wrapper.vm.$v.form.passphrase.$model = 'passphrase'
wrapper.vm.$v.form.asset.name.$model = 'business'
wrapper.vm.$v.form.asset.name.$model = 'new business'
wrapper.vm.$v.form.asset.website.$model = 'https://ark.io'
wrapper.vm.$v.form.asset.vat.$model = 'GB12345678'
wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import installI18n from '../../../../__utils__/i18n'
import TransactionFormBusinessRegistration from '@/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessRegistration'
import TransactionFormBusinessUpdate from '@/components/Transaction/TransactionForm/TransactionFormBusiness/TransactionFormBusinessUpdate'
import CurrencyMixin from '@/mixins/currency'
import StringMixin from '@/mixins/strings'
import BigNumber from '@/plugins/bignumber'

const localVue = createLocalVue()
Expand Down Expand Up @@ -42,6 +43,7 @@ const createWrapper = (component, wallet_fromRoute) => {
i18n,
localVue,
sync: false,
mixins: [StringMixin],
mocks: {
$client: {
buildBusinessRegistration: jest.fn((transactionData) => transactionData),
Expand Down Expand Up @@ -195,7 +197,7 @@ describe.each([
it('should be enabled if form is valid', async () => {
wrapper.vm.$v.form.fee.$model = (0.1 * 1e8).toString()
wrapper.vm.$v.form.passphrase.$model = 'passphrase'
wrapper.vm.$v.form.asset.name.$model = 'business'
wrapper.vm.$v.form.asset.name.$model = 'new business'
wrapper.vm.$v.form.asset.website.$model = 'https://ark.io'
wrapper.vm.$v.form.asset.vat.$model = 'GB12345678'
wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git'
Expand Down Expand Up @@ -497,14 +499,20 @@ describe.each([
wrapper.vm.$v.form.asset.vat.$model = 'GB12345678'
wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git'

let expectedAsset = {
name: 'business',
website: 'https://ark.io',
vat: 'GB12345678',
repository: 'https://github.com/arkecosystem/desktop-wallet.git'
}

if (componentName === 'TransactionFormBusinessUpdate') {
expectedAsset = {}
}

expect(wrapper.vm.getTransactionData()).toEqual({
address: 'address-1',
asset: {
name: 'business',
website: 'https://ark.io',
vat: 'GB12345678',
repository: 'https://github.com/arkecosystem/desktop-wallet.git'
},
asset: expectedAsset,
passphrase: 'passphrase',
fee: new BigNumber(0.1 * 1e8),
wif: undefined,
Expand All @@ -528,14 +536,20 @@ describe.each([
wrapper.vm.$v.form.asset.vat.$model = 'GB12345678'
wrapper.vm.$v.form.asset.repository.$model = 'https://github.com/arkecosystem/desktop-wallet.git'

let expectedAsset = {
name: 'business',
website: 'https://ark.io',
vat: 'GB12345678',
repository: 'https://github.com/arkecosystem/desktop-wallet.git'
}

if (componentName === 'TransactionFormBusinessUpdate') {
expectedAsset = {}
}

expect(wrapper.vm.getTransactionData()).toEqual({
address: 'address-1',
asset: {
name: 'business',
website: 'https://ark.io',
vat: 'GB12345678',
repository: 'https://github.com/arkecosystem/desktop-wallet.git'
},
asset: expectedAsset,
passphrase: 'passphrase',
secondPassphrase: 'second passphrase',
fee: new BigNumber(0.1 * 1e8),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
</ListDividedItem>

<ListDividedItem
v-if="transaction.asset.businessUpdate.name"
class="TransactionConfirmBusinessUpdate__name"
:label="$t('WALLET_BUSINESS.NAME')"
>
{{ transaction.asset.businessUpdate.name }}
</ListDividedItem>

<ListDividedItem
v-if="transaction.asset.businessUpdate.website"
class="TransactionConfirmBusinessUpdate__website"
:label="$t('WALLET_BUSINESS.WEBSITE')"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
/>

<button
:disabled="$v.form.$invalid"
:disabled="!isFormValid"
class="TransactionFormBusiness__next blue-button mt-10 ml-0"
@click="onSubmit"
>
Expand Down Expand Up @@ -161,10 +161,53 @@ export default {
}),

computed: {
business () {
return this.wallet_fromRoute.business
},

isUpdate () {
return !!this.business
},

hasSameName () {
return this.form.asset.name === this.business.name
},

hasSameWebsite () {
return this.form.asset.website === this.business.website
},

hasSameVat () {
return (
this.form.asset.vat === this.business.vat ||
!!this.form.asset.vat === !!this.business.vat
)
},

hasSameRepository () {
return (
this.form.asset.repository === this.business.repository ||
!!this.form.asset.repository === !!this.business.repository
)
},

nameLabel () {
return `${this.$t('WALLET_BUSINESS.NAME')} - ${this.$t('VALIDATION.MAX_LENGTH', [maxNameLength])}`
},

isFormValid () {
if (this.isUpdate) {
return !this.$v.form.$invalid && !(
this.hasSameName &&
this.hasSameWebsite &&
this.hasSameVat &&
this.hasSameRepository
alexbarnsley marked this conversation as resolved.
Show resolved Hide resolved
)
}

return !this.$v.form.$invalid
},

nameError () {
if (this.$v.form.asset.name.$dirty && this.$v.form.asset.name.$invalid) {
if (!this.$v.form.asset.name.required) {
Expand Down Expand Up @@ -226,9 +269,19 @@ export default {

methods: {
getTransactionData () {
const businessAsset = Object.assign({}, this.form.asset)

if (this.isUpdate) {
for (const property of Object.keys(this.form.asset)) {
if (this[`hasSame${this.strings_capitalizeFirst(property)}`]) {
delete businessAsset[property]
}
}
}

const transactionData = {
address: this.currentWallet.address,
asset: this.form.asset,
asset: businessAsset,
passphrase: this.form.passphrase,
fee: this.getFee(),
wif: this.form.wif,
Expand Down