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

#3278 Limit input for user could not submit lower than minimum offer … #3324

Merged
merged 7 commits into from
Jul 9, 2022
Merged
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
13 changes: 9 additions & 4 deletions components/bsx/Gallery/Item/AvailableActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
:tooltipOfferLabel="tooltipOfferLabel"
@click="handleAction" />
<component
ref="balanceInput"
class="mb-4"
v-if="showMeta"
:min="minimumOfferAmount"
:max="balance"
:is="showMeta"
@input="updateMeta"
emptyOnError />
<SubmitButton v-if="showSubmit" @click="submit">
<SubmitButton v-if="showSubmit" @click="submit" :disabled="!isActionValid">
{{ $t('nft.action.submit', [selectedAction]) }}
</SubmitButton>
</div>
Expand Down Expand Up @@ -41,6 +44,7 @@ import Connector from '@kodadot1/sub-api'
import { Component, mixins, Prop } from 'nuxt-property-decorator'
import formatBalance from '@/utils/formatBalance'
import onApiConnect from '@/utils/api/general'
import BalanceInput from '@/components/shared/BalanceInput.vue'

const components = {
ActionList: () => import('@/components/rmrk/Gallery/Item/ActionList.vue'),
Expand All @@ -66,10 +70,10 @@ export default class AvailableActions extends mixins(

private selectedAction: ShoppingActions | '' = ''
private meta: string | number = ''

public minimumOfferAmount = 0
public isMakeOffersDisabled = true
public tooltipOfferLabel = {}
public isActionValid = false
public tooltipOfferLabel = this.$t('tooltip.makeOfferDisabled')

get balance(): number {
return Number(this.$store.getters.getAuthBalance)
Expand Down Expand Up @@ -119,7 +123,6 @@ export default class AvailableActions extends mixins(
false
).replace(/,/g, '')
)

this.isMakeOffersDisabled =
!this.isMakeOffersAllowed || this.minimumOfferAmount > this.balance

Expand Down Expand Up @@ -154,6 +157,8 @@ export default class AvailableActions extends mixins(
}

protected updateMeta(value: string | number) {
const balanceInputComponent = this.$refs.balanceInput as BalanceInput
this.isActionValid = balanceInputComponent.checkValidity()
this.$consola.log(typeof value, value)
this.meta = value
}
Expand Down
9 changes: 8 additions & 1 deletion components/shared/BalanceInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
v-model="inputValue"
type="number"
:step="step"
min="0"
:min="min"
:max="max"
:expanded="expanded"
@input="handleInput" />
<p class="control balance">
Expand Down Expand Up @@ -37,6 +38,8 @@ export default class BalanceInput extends mixins(ChainMixin) {
@Prop({ default: true }) public calculate!: boolean
@Prop(Boolean) public expanded!: boolean
@Prop({ default: 0.001 }) public step!: number
@Prop(Number) public min!: number
@Prop(Number) public max!: number
protected units: Unit[] = defaultUnits
private selectedUnit = 1

Expand Down Expand Up @@ -78,5 +81,9 @@ export default class BalanceInput extends mixins(ChainMixin) {
public handleInput(value: number) {
return this.calculate ? this.formatSelectedValue(value) : value
}

public checkValidity() {
return this.balance.checkHtml5Validity()
}
}
</script>