Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/swap-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov committed May 16, 2024
2 parents 8f1072b + 4597330 commit c10d362
Show file tree
Hide file tree
Showing 29 changed files with 663 additions and 529 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.33.0",
"version": "1.34.0",
"repository": {
"type": "git",
"url": "https://github.com/sora-xor/polkaswap-exchange-web.git"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<template>
<dialog-base :visible.sync="isVisible" title="Reserve KEN token" custom-class="dialog--confirm-burn">
<dialog-base :visible.sync="isVisible" :title="title" custom-class="dialog--confirm-burn">
<token-input
class="token-input"
max="10000"
title="HOW MUCH KEN DO YOU WANT?"
:max="max"
:title="receivedPlaceholder"
:is-fiat-editable="false"
:token="ken"
:token="receivedAsset"
:value="value"
@input="handleInputField"
/>
<info-line
label="XOR TO BE BURNED"
:key="getKey('xor-burned')"
:value="formattedXorWillBeBurned"
:asset-symbol="xor.symbol"
:fiat-value="formattedFiatXorWillBeBurned"
:label="toBeBurnedLabel"
:key="toBeBurnedKey"
:value="formattedWillBeBurned"
:asset-symbol="burnedAsset.symbol"
:fiat-value="formattedFiatWillBeBurned"
is-formatted
/>
<info-line
label="YOUR XOR BALANCE LEFT"
:key="getKey('xor-left')"
:value="formattedXorLeft"
:asset-symbol="xor.symbol"
:fiat-value="formattedFiatXorLeft"
:label="yourBalanceLeftLabel"
:key="yourBalanceLeftKey"
:value="formattedTokensLeft"
:asset-symbol="burnedAsset.symbol"
:fiat-value="formattedFiatTokensLeft"
is-formatted
value-can-be-hidden
/>
Expand All @@ -37,8 +37,9 @@
/>
<div class="disclaimer s-flex">
<p class="disclaimer__text p3">
Disclaimer: Burning your XOR tokens is an irreversible action that permanently removes them from your wallet.
Please proceed with caution and ensure you fully understand the implications of this transaction
Disclaimer: Burning your {{ burnedAsset.symbol }} tokens is an irreversible action that permanently removes them
from your wallet. Please proceed with caution and ensure you fully understand the implications of this
transaction
</p>
<div class="disclaimer__badge s-flex">
<s-icon class="disclaimer__icon" name="notifications-alert-triangle-24" size="24" />
Expand All @@ -51,7 +52,7 @@
</template>
<template v-else-if="isAmountLessThanOne">NEED TO RESERVE MORE THAN 1</template>
<template v-else-if="isInsufficientBalance">
{{ t('insufficientBalanceText', { tokenSymbol: xor.symbol }) }}
{{ t('insufficientBalanceText', { tokenSymbol: burnedAsset.symbol }) }}
</template>
<template v-else>RESERVE</template>
</s-button>
Expand All @@ -63,7 +64,7 @@
import { Operation } from '@sora-substrate/util';
import { XOR } from '@sora-substrate/util/build/assets/consts';
import { api, components, mixins } from '@soramitsu/soraneo-wallet-web';
import { Component, Mixins, Watch } from 'vue-property-decorator';
import { Component, Mixins, Watch, Prop } from 'vue-property-decorator';
import { Components } from '@/consts';
import { lazyComponent } from '@/router';
Expand All @@ -86,15 +87,12 @@ export default class BurnDialog extends Mixins(
mixins.DialogMixin,
mixins.FormattedAmountMixin
) {
private readonly million = 1_000_000;
readonly xor = XOR;
readonly ken: Asset = {
address: '',
decimals: 18,
isMintable: true,
name: 'KEN',
symbol: 'KEN',
} as const;
@Prop({ type: Object, required: true }) readonly receivedAsset!: Asset;
@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;
@state.wallet.settings.networkFees private networkFees!: NetworkFeesObject;
@getter.assets.xor private accountXor!: Nullable<AccountAsset>;
Expand All @@ -115,20 +113,44 @@ export default class BurnDialog extends Mixins(
return this.isVisible ? `${key}-opened` : `${key}-closed`;
}
private get xorWillBeBurned() {
return this.getFPNumber(+(this.value || '0') * this.million);
private get willBeBurned() {
return this.getFPNumber(+(this.value || '0') * this.rate);
}
get title(): string {
return `Reserve ${this.receivedAsset.symbol} token`;
}
get receivedPlaceholder(): string {
return `HOW MUCH ${this.receivedAsset.symbol} DO YOU WANT?`;
}
get toBeBurnedLabel(): string {
return `${this.burnedAsset.symbol} TO BE BURNED`;
}
get toBeBurnedKey(): string {
return this.getKey(`${this.burnedAsset.symbol}-burned`);
}
get yourBalanceLeftLabel(): string {
return `YOUR ${this.burnedAsset.symbol} BALANCE LEFT`;
}
get yourBalanceLeftKey(): string {
return this.getKey(`${this.burnedAsset.symbol}-left`);
}
get isAmountLessThanOne(): boolean {
return +(this.value || '0') < 1;
}
get formattedXorWillBeBurned(): string {
return this.xorWillBeBurned.toLocaleString();
get formattedWillBeBurned(): string {
return this.willBeBurned.toLocaleString();
}
get formattedFiatXorWillBeBurned(): Nullable<string> {
return this.getFiatAmountByFPNumber(this.xorWillBeBurned, this.xor);
get formattedFiatWillBeBurned(): Nullable<string> {
return this.getFiatAmountByFPNumber(this.willBeBurned, this.burnedAsset);
}
get networkFee(): CodecString {
Expand All @@ -140,28 +162,30 @@ export default class BurnDialog extends Mixins(
}
private get xorBalance() {
// Replace with burnedAsset if needed
return this.getFPNumberFromCodec(this.accountXor?.balance?.transferable ?? '0');
}
private get xorLeft() {
return this.xorBalance.gte(this.xorWillBeBurned) ? this.xorBalance.sub(this.xorWillBeBurned) : this.Zero;
private get tokensLeft() {
return this.xorBalance.gte(this.willBeBurned) ? this.xorBalance.sub(this.willBeBurned) : this.Zero;
}
get formattedXorLeft(): string {
return this.xorLeft.toLocaleString();
get formattedTokensLeft(): string {
return this.tokensLeft.toLocaleString();
}
get formattedFiatXorLeft(): Nullable<string> {
return this.getFiatAmountByFPNumber(this.xorLeft, this.xor);
get formattedFiatTokensLeft(): Nullable<string> {
return this.getFiatAmountByFPNumber(this.tokensLeft, this.burnedAsset);
}
get isZeroAmount(): boolean {
return asZeroValue(this.value);
}
get isInsufficientBalance(): boolean {
const xorLeft = this.xorBalance.sub(this.xorWillBeBurned).sub(this.getFPNumberFromCodec(this.networkFee));
return xorLeft.isLtZero();
// Replace with burnedAsset and add networkFee check with xor balance if needed
const left = this.xorBalance.sub(this.willBeBurned).sub(this.getFPNumberFromCodec(this.networkFee));
return left.isLtZero();
}
get isBurnDisabled(): boolean {
Expand All @@ -176,14 +200,14 @@ export default class BurnDialog extends Mixins(
async handleConfirmBurn(): Promise<void> {
if (this.isInsufficientBalance) {
this.$alert(this.t('insufficientBalanceText', { tokenSymbol: this.xor.symbol }), {
this.$alert(this.t('insufficientBalanceText', { tokenSymbol: this.burnedAsset.symbol }), {
title: this.t('errorText'),
});
this.$emit('confirm');
} else {
try {
await this.withNotifications(async () => {
await api.assets.burn(this.xor, this.xorWillBeBurned.toString());
await api.assets.burn(this.burnedAsset, this.willBeBurned.toString());
});
this.$emit('confirm', true);
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export enum PageNames {
LimitOrderBuy = 'OrderBook/LimitOrderBuy',
LimitOrderSell = 'OrderBook/LimitOrderSell',
SoraCard = 'SoraCard',
Kensetsu = 'Kensetsu',
Burn = 'Burn',
}

export enum Components {
Expand Down Expand Up @@ -374,8 +374,8 @@ const OtherPagesMenu: Array<SidebarMenuItemLink> = [
},
{
icon: 'basic-flame-24',
title: PageNames.Kensetsu,
href: '/#/kensetsu',
title: PageNames.Burn,
href: '/#/burn',
},
{
icon: 'music-eject-24',
Expand Down
5 changes: 0 additions & 5 deletions src/consts/sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,6 @@ export const SUB_NETWORKS: Partial<Record<SubNetwork, NetworkData>> = {
name: 'Dwellir',
address: 'wss://liberland-rpc.dwellir.com',
},
{
chain: 'Liberland',
name: 'Liberland Governance',
address: 'wss://mainnet.liberland.org',
},
],
blockExplorerUrls: ['https://chainscan.mainnet.liberland.org'],
shortName: 'Liberland',
Expand Down
58 changes: 37 additions & 21 deletions src/indexer/queries/kensetsu.ts → src/indexer/queries/burnXor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FPNumber } from '@sora-substrate/util';
import { getCurrentIndexer, WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web';
import { SubqueryIndexer, SubsquidIndexer } from '@soramitsu/soraneo-wallet-web/lib/services/indexer';
import { SubqueryIndexer } from '@soramitsu/soraneo-wallet-web/lib/services/indexer';
import { gql } from '@urql/core';

import type {
Expand All @@ -11,77 +11,88 @@ import type {

const { IndexerType } = WALLET_CONSTS;

type KensetsuBurn = {
type XorBurn = {
address: string;
amount: FPNumber;
blockHeight: number;
};

/**
* 1) https://sora.subscan.io/extrinsic/0x626147716deb3059bfb4d0f3f564cb8d336e7d99dbf1d6a99125d852cb449046
* 2) https://sora.subscan.io/extrinsic/0xc3319a9bfd7ea92d19b2910d16df189f8cbd81aa7809e8febc2c10a376996ec9
* 3) https://sora.subscan.io/extrinsic/0xf1caed8923c9412f682a0181073358c1d0559219831693d9bf37ef6c77f33b6c
* 4) https://sora.subscan.io/extrinsic/0xa0fd341cbdb2c6de2873dd3edb2e59a5fbb3e6cdcd056a2f4f8f3ba4663cf68f
* 5) https://sora.subscan.io/extrinsic/0xc51f24899e5d89765647bef5663a58db873bffbd4af26b9a6e39787e762bbeb7
* 6) https://sora.subscan.io/extrinsic/0x733da9635badd2692ff9c76b4ad761e7460fd88b72f04edb5f7e844dc6ce188e
* 7) https://sora.subscan.io/extrinsic/0x580f85275b21e43a2923d4a0e3af9d92832bb8f63c2a9f0b2fa17dd9e97d1533
* 8) https://sora.subscan.io/extrinsic/0x6290185892566e17fdc70e29ac0227819d67e9ac85da6981c2036724ffa15dcd
* 9) https://sora.subscan.io/extrinsic/0x2db91f8192e84d38956f4335acc3e98a6085be5d3d1ec645e3588854ac6970a0
* 10) https://sora.subscan.io/extrinsic/0xb90cb95d71bc43d7c4212b1aa7b97b199436e706cd6ff1a73a9cd81ed8842df9
* 11) https://sora.subscan.io/extrinsic/0x2727e182d531ad890f9937beded0527d4a6d68018977b484658391fdd1e80880
* 12) https://sora.subscan.io/extrinsic/0xa072a5c6c0d847cef807e57c303fd60fdde67d8e10b1c080de428ba15b78bdb6
*/
const dataBeforeIndexing: KensetsuBurn[] = [
const dataBeforeIndexing: XorBurn[] = [
// https://sora.subscan.io/extrinsic/0xa072a5c6c0d847cef807e57c303fd60fdde67d8e10b1c080de428ba15b78bdb6
{
address: 'cnV21a8zn14wUTuxUK6wy5Fmus8PXaGrsBUchz33MqavYqxHE',
amount: FPNumber.fromCodecValue('2000000000000000000000000'),
blockHeight: 14496081,
},
// https://sora.subscan.io/extrinsic/0x2727e182d531ad890f9937beded0527d4a6d68018977b484658391fdd1e80880
{
address: 'cnXES5tPEMkhLmhG57v55aYW4x1DtqHFM9Ft8rBcLNyHHFVSm',
amount: FPNumber.fromCodecValue('1000000000000000000000000'),
blockHeight: 14488966,
},
// https://sora.subscan.io/extrinsic/0xb90cb95d71bc43d7c4212b1aa7b97b199436e706cd6ff1a73a9cd81ed8842df9
{
address: 'cnTkiF9YpNT8uzwQvJFJHf7Vr3KtFppF2VGxE22C1MTMbHEmN',
amount: FPNumber.fromCodecValue('25000000000000000000000000'),
blockHeight: 14482098,
},
// https://sora.subscan.io/extrinsic/0x2db91f8192e84d38956f4335acc3e98a6085be5d3d1ec645e3588854ac6970a0
{
address: 'cnRdTJwjwpn67KgnWGcbBJpMipryNNos15NEFWV4sEfSnNnM6',
amount: FPNumber.fromCodecValue('4000000000000000000000000'),
blockHeight: 14473177,
},
// https://sora.subscan.io/extrinsic/0x6290185892566e17fdc70e29ac0227819d67e9ac85da6981c2036724ffa15dcd
{
address: 'cnW4cSTA6CB3zDw2kLknDwZRqPPwPDdFURN2nhHVg8C2SnrNX',
amount: FPNumber.fromCodecValue('1000000000000000000000000'),
blockHeight: 14471099,
},
// https://sora.subscan.io/extrinsic/0x580f85275b21e43a2923d4a0e3af9d92832bb8f63c2a9f0b2fa17dd9e97d1533
{
address: 'cnTmBrrR4CFs3GDA1DjWhAMsXXAJQJwUCkFtbsRsXhXJWTB3J',
amount: FPNumber.fromCodecValue('1000000000000000000000000'),
blockHeight: 14467209,
},
// https://sora.subscan.io/extrinsic/0x733da9635badd2692ff9c76b4ad761e7460fd88b72f04edb5f7e844dc6ce188e
{
address: 'cnTYLL7UNk9tak7gRZnZXxfor5UvMSEebBUsSLwwhyZvDdKWB',
amount: FPNumber.fromCodecValue('1500000000000000000000000'),
blockHeight: 14467173,
},
// https://sora.subscan.io/extrinsic/0xc51f24899e5d89765647bef5663a58db873bffbd4af26b9a6e39787e762bbeb7
{
address: 'cnVA8S2CNn2h4CjW2vTnqnSRqEL4P2ShvPWYA46TYEdTtao3S',
amount: FPNumber.fromCodecValue('1000000000000000000000000'),
blockHeight: 14467085,
},
// https://sora.subscan.io/extrinsic/0xa0fd341cbdb2c6de2873dd3edb2e59a5fbb3e6cdcd056a2f4f8f3ba4663cf68f
{
address: 'cnTdA96vs4okPqpfSaPwSCPunkEn6AYTLek6rBvP9LbXbinAh',
amount: FPNumber.fromCodecValue('10000000000000000000000000'),
blockHeight: 14466510,
},
// https://sora.subscan.io/extrinsic/0xf1caed8923c9412f682a0181073358c1d0559219831693d9bf37ef6c77f33b6c
{
address: 'cnV5d93J89p5kC4dRqF5WWtDNCk1XZ3HQo9dEhGUxBQnohxEB',
amount: FPNumber.fromCodecValue('1500000000000000000000000'),
blockHeight: 14465935,
},
// https://sora.subscan.io/extrinsic/0xc3319a9bfd7ea92d19b2910d16df189f8cbd81aa7809e8febc2c10a376996ec9
{
address: 'cnV5d93J89p5kC4dRqF5WWtDNCk1XZ3HQo9dEhGUxBQnohxEB',
amount: FPNumber.fromCodecValue('10000000000000000000000000'),
blockHeight: 14464669,
},
// https://sora.subscan.io/extrinsic/0x626147716deb3059bfb4d0f3f564cb8d336e7d99dbf1d6a99125d852cb449046
{
address: 'cnTkiF9YpNT8uzwQvJFJHf7Vr3KtFppF2VGxE22C1MTMbHEmN',
amount: FPNumber.fromCodecValue('1000000000000000000000000'),
blockHeight: 14464111,
},
];

const KensetsuQuery = gql<ConnectionQueryResponse<HistoryElement>>`
const XorBurnQuery = gql<ConnectionQueryResponse<HistoryElement>>`
query ($start: Int = 0, $end: Int = 0, $after: Cursor = "", $first: Int = 100) {
data: historyElements(
first: $first
Expand All @@ -104,31 +115,36 @@ const KensetsuQuery = gql<ConnectionQueryResponse<HistoryElement>>`
node {
address
data
blockHeight
}
}
}
}
`;

const parse = (item: HistoryElement): KensetsuBurn => {
const parse = (item: HistoryElement): XorBurn => {
const data = item.data as HistoryElementAssetBurn;

return {
address: item.address,
amount: new FPNumber(data.amount),
blockHeight: +item.blockHeight,
};
};

export async function fetchData(start: number, end: number): Promise<KensetsuBurn[]> {
export async function fetchData(start: number, end: number): Promise<XorBurn[]> {
const indexer = getCurrentIndexer();

switch (indexer.type) {
case IndexerType.SUBQUERY: {
const variables = { start, end };
const subqueryIndexer = indexer as SubqueryIndexer;
const items = await subqueryIndexer.services.explorer.fetchAllEntities(KensetsuQuery, variables, parse);
const items = await subqueryIndexer.services.explorer.fetchAllEntities(XorBurnQuery, variables, parse);
return [...(items ?? []), ...dataBeforeIndexing];
}
case IndexerType.SUBSQUID: {
return [];
}
}

return [];
Expand Down
Loading

0 comments on commit c10d362

Please sign in to comment.