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 Jul 16, 2024
2 parents b28031a + a21d6a8 commit e70b000
Show file tree
Hide file tree
Showing 40 changed files with 349 additions and 112 deletions.
1 change: 1 addition & 0 deletions env.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"SUBQUERY_ENDPOINT": "https://api.subquery.network/sq/sora-xor/sora-prod",
"SUBSQUID_ENDPOINT": "https://squid.subsquid.io/sora/graphql",
"TG_BOT_URL": "t.me/polkaswap_io_bot",
"DEFAULT_NETWORKS": [
{
"chain": "SORA",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polkaswap-exchange-web",
"version": "1.38.2",
"version": "1.38.3",
"repository": {
"type": "git",
"url": "https://github.com/sora-xor/polkaswap-exchange-web.git"
Expand Down Expand Up @@ -28,8 +28,8 @@
"dependencies": {
"@cedelabs/widgets-universal": "^1.3.1",
"@metamask/detect-provider": "^2.0.0",
"@soramitsu/soraneo-wallet-web": "1.38.6",
"@tma.js/sdk": "^2.4.0",
"@soramitsu/soraneo-wallet-web": "1.38.9",
"@tma.js/sdk": "^2.7.0",
"@walletconnect/ethereum-provider": "^2.13.3",
"@walletconnect/modal": "^2.6.2",
"core-js": "^3.37.1",
Expand Down
1 change: 1 addition & 0 deletions public/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"assetOwner": false
},
"FAUCET_URL": "https://faucet.dev.sora2.tachi.soramitsu.co.jp/",
"TG_BOT_URL": "t.me/PolkaswapDevBot",
"DEFAULT_NETWORKS": [
{
"chain": "SORA-dev Testnet #1",
Expand Down
29 changes: 15 additions & 14 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
initWallet,
waitForCore,
} from '@soramitsu/soraneo-wallet-web';
import { isTMA, setDebug } from '@tma.js/sdk';
import { isTMA } from '@tma.js/sdk';
import debounce from 'lodash/debounce';
import { Component, Mixins, Watch } from 'vue-property-decorator';
Expand All @@ -70,6 +70,7 @@ import router, { goTo, lazyComponent } from '@/router';
import { action, getter, mutation, state } from '@/store/decorators';
import { getMobileCssClasses, preloadFontFace, updateDocumentTitle } from '@/utils';
import type { NodesConnection } from '@/utils/connection';
import { TmaSdk } from '@/utils/telegram';
import type { FeatureFlags } from './store/settings/types';
import type { EthBridgeSettings, SubNetworkApps } from './store/web3/types';
Expand Down Expand Up @@ -111,6 +112,7 @@ export default class App extends Mixins(mixins.TransactionMixin, NodeErrorMixin)
@state.settings.browserNotifPopupBlockedVisibility private browserNotifPopupBlocked!: boolean;
@state.wallet.account.assetsToNotifyQueue private assetsToNotifyQueue!: Array<WhitelistArrayItem>;
@state.referrals.storageReferrer private storageReferrer!: string;
@state.referrals.referrer private referrer!: string;
@state.settings.disclaimerVisibility disclaimerVisibility!: boolean;
@state.router.loading pageLoading!: boolean;
Expand Down Expand Up @@ -155,9 +157,10 @@ export default class App extends Mixins(mixins.TransactionMixin, NodeErrorMixin)
@state.wallet.transactions.isSignTxDialogVisible public isSignTxDialogVisible!: boolean;
@mutation.wallet.transactions.setSignTxDialogVisibility public setSignTxDialogVisibility!: (flag: boolean) => void;
// [DESKTOP] To Enable Desktop
@mutation.wallet.account.setIsDesktop private setIsDesktop!: (v: boolean) => void;
// [TMA] To Enable TMA
@mutation.settings.enableTMA private enableTMA!: FnWithoutArgs;
@Watch('assetsToNotifyQueue')
private handleNotifyOnDeposit(whitelistAssetArray: WhitelistArrayItem[]): void {
Expand Down Expand Up @@ -198,16 +201,17 @@ export default class App extends Mixins(mixins.TransactionMixin, NodeErrorMixin)
}
private async confirmInvititation(): Promise<void> {
await this.getReferrer();
if (this.storageReferrer) {
await this.withApi(async () => {
await this.getReferrer();
if (!this.storageReferrer) {
return;
}
if (this.storageReferrer === this.account.address) {
this.resetStorageReferrer();
} else {
this.withApi(() => {
this.showConfirmInviteUser = true;
});
} else if (!this.referrer) {
this.showConfirmInviteUser = true;
}
}
});
}
private setResponsiveClass(): void {
Expand All @@ -217,9 +221,6 @@ export default class App extends Mixins(mixins.TransactionMixin, NodeErrorMixin)
private setResponsiveClassDebounced = debounce(this.setResponsiveClass, 250);
async created() {
// [DESKTOP] To Enable Desktop
// this.setIsDesktop(true);
// element-icons is not common used, but should be visible after network connection lost
preloadFontFace('element-icons');
this.setResponsiveClass();
Expand All @@ -237,9 +238,9 @@ export default class App extends Mixins(mixins.TransactionMixin, NodeErrorMixin)
// To start running as Telegram Web App (desktop capabilities)
if (await isTMA()) {
this.enableTMA();
this.setIsDesktop(true);
// sets debug mode in twa
if (data.NETWORK_TYPE === WALLET_CONSTS.SoraNetwork.Dev) setDebug(true);
await TmaSdk.init(data?.TG_BOT_URL, data.NETWORK_TYPE === WALLET_CONSTS.SoraNetwork.Dev);
}
await this.setApiKeys(data?.API_KEYS);
Expand Down
7 changes: 5 additions & 2 deletions src/components/App/Header/AppHeaderMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { Component, Mixins } from 'vue-property-decorator';
import TranslationMixin from '@/components/mixins/TranslationMixin';
import { getter, mutation, state } from '@/store/decorators';
import { TmaSdk } from '@/utils/telegram';
import type { Currency } from '@soramitsu/soraneo-wallet-web/lib/types/currency';
Expand Down Expand Up @@ -177,13 +178,15 @@ export default class AppHeaderMenu extends Mixins(TranslationMixin) {
dropdown.visible ? dropdown.hide() : dropdown.show();
}
handleSelectHeaderMenu(value: HeaderMenuType): void {
async handleSelectHeaderMenu(value: HeaderMenuType): Promise<void> {
switch (value) {
case HeaderMenuType.HideBalances:
this.toggleHideBalance();
break;
case HeaderMenuType.Theme:
switchTheme();
await switchTheme();
await this.$nextTick();
TmaSdk.updateTheme();
break;
case HeaderMenuType.Language:
this.setLanguageDialogVisibility(true);
Expand Down
1 change: 1 addition & 0 deletions src/components/App/Menu/AppMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ export default class AppMenu extends Mixins(TranslationMixin) {
@include large-mobile(true) {
position: fixed;
right: 0;
z-index: $app-above-loader-layer;
&.visible {
visibility: visible;
Expand Down
1 change: 1 addition & 0 deletions src/components/pages/Referrals/ConfirmInviteUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Component, Mixins, Watch } from 'vue-property-decorator';
import { state, mutation } from '@/store/decorators';
// TODO: [Rustem] remove hasReferrer logic (localise)
@Component({
components: { DialogBase: components.DialogBase },
})
Expand Down
62 changes: 50 additions & 12 deletions src/components/shared/Widget/PriceChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ type ChartDataItem = [number, ...OCLH, number];
type LastUpdates = Record<string, SnapshotItem>;
type Snapshot = {
nodes: SnapshotItem[];
hasNextPage: boolean;
endCursor: string | undefined;
};
enum CHART_TYPES {
LINE = 'line',
CANDLE = 'candlestick',
Expand Down Expand Up @@ -222,13 +228,11 @@ const mergeSnapshots = (a: Nullable<SnapshotItem>, b: Nullable<SnapshotItem>): S
const normalizeSnapshots = (collection: SnapshotItem[], difference: number, lastTimestamp: number): SnapshotItem[] => {
const sample: SnapshotItem[] = [];
for (const item of collection) {
const buffer: SnapshotItem[] = [];
const prevTimestamp = last(sample)?.timestamp ?? lastTimestamp;
let currentTimestamp = item.timestamp;
while ((currentTimestamp += difference) < prevTimestamp) {
buffer.push({
timestamp: currentTimestamp,
Expand Down Expand Up @@ -321,6 +325,10 @@ export default class PriceChartWidget extends Mixins(
private priceUpdateSubscription: Nullable<FnWithoutArgs> = null;
private priceUpdateTimestampSync: Nullable<NodeJS.Timer | number> = null;
private snapshotBuffer: Record<string, Snapshot> = {};
private loadDataWhenReverse = false;
chartType: CHART_TYPES = CHART_TYPES.LINE;
selectedFilter: SnapshotFilter = LINE_CHART_FILTERS[0];
isReversedChart = false;
Expand Down Expand Up @@ -711,7 +719,7 @@ export default class PriceChartWidget extends Mixins(
count: number,
hasNextPage = true,
endCursor?: string
) {
): Promise<Snapshot> {
const handler = this.isOrderBook ? fetchOrderBookData : fetchAssetData;
const nodes: SnapshotItem[] = [];
Expand All @@ -734,13 +742,16 @@ export default class PriceChartWidget extends Mixins(
}
// ordered ty timestamp DESC
private async fetchData(entityId: string) {
private async fetchData(entityId: string): Promise<Snapshot> {
const { type, count } = this.selectedFilter;
const pageInfo = this.pageInfos[entityId];
const hasNextPage = pageInfo?.hasNextPage ?? true;
const endCursor = pageInfo?.endCursor ?? undefined;
if (this.loadDataWhenReverse) {
return this.snapshotBuffer[entityId] || { nodes: [], hasNextPage: false, endCursor: undefined };
}
const buffer = this.samplesBuffer[entityId] ?? [];
if (buffer.length >= count) {
Expand All @@ -756,7 +767,6 @@ export default class PriceChartWidget extends Mixins(
private async fetchDataLastUpdates(entities: string[]): Promise<Nullable<LastUpdates>> {
const lastUpdates: LastUpdates = {};
await Promise.all(
entities.map(async (entityId) => {
try {
Expand Down Expand Up @@ -791,25 +801,24 @@ export default class PriceChartWidget extends Mixins(
const lastTimestamp = last(this.dataset)?.timestamp ?? Date.now();
this.priceUpdateRequestId = requestId;
await this.withApi(async () => {
try {
const snapshots = await Promise.all(addresses.map((address) => this.fetchData(address)));
const snapshots: Snapshot[] = await Promise.all(addresses.map((address) => this.fetchData(address)));
// if no response, or tokens were changed, return
if (!(snapshots && isEqual(addresses)(this.entities) && isEqual(requestId)(this.priceUpdateRequestId))) return;
const pageInfos: Record<string, Partial<PageInfo>> = {};
const dataset: SnapshotItem[] = [];
const groups: SnapshotItem[][] = [];
const timestamp =
lastTimestamp ??
Math.max(snapshots[0]?.nodes[0]?.timestamp ?? 0, snapshots[1]?.nodes[0]?.timestamp ?? 0) * 1000;
snapshots.forEach(({ hasNextPage, endCursor, nodes }, index) => {
snapshots.forEach(async ({ hasNextPage, endCursor, nodes }, index) => {
const address = addresses[index];
const buffer = this.samplesBuffer[address] ?? [];
const normalized = normalizeSnapshots(buffer.concat(nodes), this.timeDifference, timestamp);
this.fillSnapshotBuffer(address, normalized, hasNextPage, endCursor);
groups.push(normalized);
pageInfos[address] = { hasNextPage, endCursor };
});
Expand Down Expand Up @@ -847,10 +856,35 @@ export default class PriceChartWidget extends Mixins(
} catch (error) {
this.isFetchingError = true;
console.error(error);
} finally {
this.loadDataWhenReverse = false;
}
});
}
private fillSnapshotBuffer(
address: string,
normalized: SnapshotItem[],
hasNextPage: boolean,
endCursor: string | undefined
): void {
if (!this.snapshotBuffer[address]) {
this.snapshotBuffer[address] = {
nodes: [],
hasNextPage: false,
endCursor: undefined,
};
}
const existingNodes = this.snapshotBuffer[address].nodes;
const normalizedTimestamps = new Set(normalized.map((item) => item.timestamp));
const filteredExistingNodes = existingNodes.filter((item) => !normalizedTimestamps.has(item.timestamp));
this.snapshotBuffer[address].nodes = [...filteredExistingNodes, ...normalized];
this.snapshotBuffer[address].hasNextPage = hasNextPage;
this.snapshotBuffer[address].endCursor = endCursor;
}
// common
private async subscribeToPriceUpdates(): Promise<void> {
this.unsubscribeFromPriceUpdates();
Expand Down Expand Up @@ -966,6 +1000,9 @@ export default class PriceChartWidget extends Mixins(
if (!saveReversedState) {
this.isReversedChart = false;
}
if (!this.loadDataWhenReverse) {
this.snapshotBuffer = {};
}
}
private updateDataset(items: SnapshotItem[]): void {
Expand Down Expand Up @@ -1041,6 +1078,7 @@ export default class PriceChartWidget extends Mixins(
revertChart(): void {
this.isReversedChart = !this.isReversedChart;
this.loadDataWhenReverse = true;
this.forceUpdatePrices(true);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,6 @@ export const TranslationConsts = {
VAL: 'VAL',
Kensetsu: 'Kensetsu',
LTV: 'LTV',
Telegram: 'Telegram',
DEX: 'DEX',
} as const;
7 changes: 5 additions & 2 deletions src/lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@
"bondMore": "Vázat více",
"bond": "Vázat",
"unbond": "Zrušit vazbu",
"copyLink": "Kopírovat odkaz"
"copyLink": "Kopírovat odkaz",
"shareLink": "Sdílet"
},
"transactionDetails": "Detaily transakce",
"receivedRewards": "Přijaté odměny",
Expand Down Expand Up @@ -970,7 +971,9 @@
"info": "Když zaplatíte poplatek za transakci,<br\/>10% dostane váš referrer",
"referredLablel": "Doporučená adresa"
},
"insufficientBondedAmount": "Chcete-li pozvat více doporučení, spojte alespoň {inviteUserFee} XOR"
"insufficientBondedAmount": "Chcete-li pozvat více doporučení, spojte alespoň {inviteUserFee} XOR",
"inviteViaTelegram": "Pozvat přes {Telegram}",
"welcomeMessage": "\nPřipojte se ke mně na {Polkaswap}!\n\nObjevte stylový {DEX}, který vám umožní vyměňovat desítky tokenů s křížovými řetězovými swapmi, knihou objednávek a spoustou odměn!\n\n🎁 Pozvěte přátele a získejte 10% z jejich obchodních poplatků\n\nUvidíme se tam!"
},
"transactionDetailsText": "Detaily transakce",
"code": {
Expand Down
7 changes: 5 additions & 2 deletions src/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@
"bondMore": "Mehr bonden",
"bond": "Bond",
"unbond": "Unbond",
"copyLink": "Link kopieren"
"copyLink": "Link kopieren",
"shareLink": "Teilen"
},
"transactionDetails": "Transaktionsdetails",
"receivedRewards": "Erhaltene Belohnungen",
Expand Down Expand Up @@ -970,7 +971,9 @@
"info": "Wenn du eine Transaktionsgebühr zahlst,<br\/>gehen 10% an deinen Referrer",
"referredLablel": "Empfohlene Adresse"
},
"insufficientBondedAmount": "Um weitere Empfehlungen zu veschicken, bonde mindestens {inviteUserFee} XOR"
"insufficientBondedAmount": "Um weitere Empfehlungen zu veschicken, bonde mindestens {inviteUserFee} XOR",
"inviteViaTelegram": "Einladen über {Telegram}",
"welcomeMessage": "\nKomm zu mir auf {Polkaswap}!\n\nEntdecke den stylischen {DEX}, mit dem du Dutzende Token mit Cross-Chain-Swaps, Orderbuch und vielen Belohnungen tauschen kannst!\n\n🎁 Lade Freunde ein und verdiene 10% ihrer Handelsgebühren\n\nBis dann!"
},
"transactionDetailsText": "Transaktionsdetails",
"code": {
Expand Down
7 changes: 5 additions & 2 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,8 @@
"bondMore": "Bond More",
"bond": "Bond",
"unbond": "Unbond",
"copyLink": "Copy link"
"copyLink": "Copy link",
"shareLink": "Share"
},
"transactionDetails": "Transaction Details",
"receivedRewards": "Received rewards",
Expand Down Expand Up @@ -970,7 +971,9 @@
"info": "When you’ll pay a fee for transaction,<br\/>10% will go to your referrer",
"referredLablel": "Referred address"
},
"insufficientBondedAmount": "To invite more referrals, bond at least {inviteUserFee} XOR"
"insufficientBondedAmount": "To invite more referrals, bond at least {inviteUserFee} XOR",
"inviteViaTelegram": "Invite via {Telegram}",
"welcomeMessage": "\nJoin me on {Polkaswap}!\n\nDiscover the stylish {DEX} that lets you swap over dozens tokens with cross-chain swaps, order book, and plenty of rewards!\n\n🎁 Invite friends and earn 10% of their trading fees\n\nSee you there!"
},
"transactionDetailsText": "Transaction Details",
"code": {
Expand Down
Loading

0 comments on commit e70b000

Please sign in to comment.