Skip to content

Commit

Permalink
Set configurable min limit for burn (#1432)
Browse files Browse the repository at this point in the history
* Add configurable min limit for Burn page

* Set 1.36 version

---------

Co-authored-by: Stefan Popov <17688105+stefashkaa@users.noreply.github.com>
  • Loading branch information
stefashkaa and stefashkaa authored May 31, 2024
1 parent 5b946ba commit 0efd046
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkaswap-exchange-web",
"version": "1.35.1",
"version": "1.36.0",
"repository": {
"type": "git",
"url": "https://github.com/sora-xor/polkaswap-exchange-web.git"
Expand Down
9 changes: 5 additions & 4 deletions src/components/pages/Burn/BurnDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<template v-if="isZeroAmount">
{{ t('buttons.enterAmount') }}
</template>
<template v-else-if="isAmountLessThanOne">NEED TO RESERVE MORE THAN 1</template>
<template v-else-if="isAmountLessThanMin">NEED TO RESERVE MORE THAN {{ min }}</template>
<template v-else-if="isInsufficientBalance">
{{ t('insufficientBalanceText', { tokenSymbol: burnedAsset.symbol }) }}
</template>
Expand Down Expand Up @@ -94,6 +94,7 @@ export default class BurnDialog extends Mixins(
@Prop({ type: Object, required: true }) readonly burnedAsset!: Asset;
@Prop({ type: Number, default: 1_000_000 }) readonly rate!: number;
@Prop({ type: Number, default: 10_000 }) readonly max!: number;
@Prop({ type: Number, default: 1 }) readonly min!: number;
@state.wallet.settings.networkFees private networkFees!: NetworkFeesObject;
@getter.assets.xor private accountXor!: Nullable<AccountAsset>;
Expand Down Expand Up @@ -142,8 +143,8 @@ export default class BurnDialog extends Mixins(
return this.getKey(`${this.burnedAsset.symbol}-left`);
}
get isAmountLessThanOne(): boolean {
return +(this.value || '0') < 1;
get isAmountLessThanMin(): boolean {
return +(this.value || '0') < this.min;
}
get formattedWillBeBurned(): string {
Expand Down Expand Up @@ -190,7 +191,7 @@ export default class BurnDialog extends Mixins(
}
get isBurnDisabled(): boolean {
return this.loading || this.isZeroAmount || this.isAmountLessThanOne || this.isInsufficientBalance;
return this.loading || this.isZeroAmount || this.isAmountLessThanMin || this.isInsufficientBalance;
}
handleInputField(value: string): void {
Expand Down
10 changes: 8 additions & 2 deletions src/views/Burn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
:burned-asset="selectedBurnedAsset"
:rate="selectedRate"
:max="selectedMax"
:min="selectedMin"
@confirm="handleBurnConfirm"
/>
</div>
Expand Down Expand Up @@ -134,6 +135,7 @@ type Campaign = {
receivedAsset: Asset;
rate: number;
max: number;
min: number;
from: number;
fromTimestamp: number;
to: number;
Expand Down Expand Up @@ -166,6 +168,7 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
receivedAsset: { symbol: 'KARMA', address: '', name: 'Chameleon', decimals: 18 } as Asset,
rate: 100_000_000,
max: 1000,
min: 0.1,
from: 15_739_737,
fromTimestamp: 1715791500000, // May 15 2024 16:45:00 GMT+0000
to: 16_056_666,
Expand All @@ -180,6 +183,7 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
receivedAsset: KEN,
rate: 1_000_000,
max: 10_000,
min: 1,
from: 14_464_000,
fromTimestamp: 1708097280000, // Feb 16 2024 15:28:00 GMT+0000
to: 14_939_200,
Expand Down Expand Up @@ -209,6 +213,7 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
selectedBurnedAsset = XOR;
selectedRate = this.campaigns[0].rate;
selectedMax = this.campaigns[0].max;
selectedMin = this.campaigns[0].min;
@state.settings.blockNumber private blockNumber!: number;
@state.wallet.account.address soraAccountAddress!: string;
Expand Down Expand Up @@ -288,10 +293,10 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
return acc;
}, {});
const fpRate = new FPNumber(campaign.rate);
const minBurned = new FPNumber(campaign.rate * campaign.min);
Object.entries(accountsBurned).forEach(([addr, amount]) => {
if (amount.gte(fpRate)) {
if (amount.gte(minBurned)) {
totalXorBurned[campaign.id] = totalXorBurned[campaign.id].add(amount);
if (address === addr) {
accountXorBurned[campaign.id] = accountXorBurned[campaign.id].add(amount);
Expand Down Expand Up @@ -320,6 +325,7 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
this.selectedReceivedAsset = campaign.receivedAsset;
this.selectedRate = campaign.rate;
this.selectedMax = campaign.max;
this.selectedMin = campaign.min;
this.burnDialogVisible = true;
}
Expand Down

0 comments on commit 0efd046

Please sign in to comment.