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 22, 2024
2 parents 462491a + 5cbcffa commit ed7c6fa
Show file tree
Hide file tree
Showing 51 changed files with 868 additions and 972 deletions.
2 changes: 0 additions & 2 deletions env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
"BASE_API_URL": "",
"API_KEYS": {
"moonpay": "pk_live_LEyw9bsfK0n0v3cdHUaZS1z0qYdDRDu6",
"x1ex": "sprkwdgt-WUQBA5U2",
"etherscan": "XBS98SSP8J5FNS7EKQHMHRU94Z2YG7HFFK",
"nftStorage": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDBmMzgwOTMyQTNDODM3ZDNiN2JEYzBBNTc0NmNkMDlBRGIyNUZGMzQiLCJpc3MiOiJuZnQtc3RvcmFnZSIsImlhdCI6MTY0NTU0MDQ4MTQ5OSwibmFtZSI6Im5mdC1zdG9yYWdlLXByb2QifQ.CnW1bq8eWEYQxA6cggGMeAqCTozCJZ6s2oL_bssqnmc",
"googleApi": "AIzaSyCazdRheGfy7_bwVi0m5UgUYjz7l0c54nM",
"googleClientId": "728106973134-pfmcagr0t4lchepajcp7llp7f1t09lf0.apps.googleusercontent.com"
},
"FEATURE_FLAGS": {
"moonpay": true,
"x1ex": false,
"charts": true,
"soraCard": false,
"orderBook": true,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test:all": "yarn test:unit --coverage"
},
"dependencies": {
"@cedelabs/widgets-universal": "^1.3.1",
"@metamask/detect-provider": "^2.0.0",
"@soramitsu/soraneo-wallet-web": "1.34.7",
"@walletconnect/ethereum-provider": "^2.12.2",
Expand Down
6 changes: 2 additions & 4 deletions public/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
"BASE_API_URL": "",
"API_KEYS": {
"moonpay": "pk_test_4ASGxHKGpLPE6sdQq1V3QjtpUFSpWLk",
"x1ex": "sprkwdgt-WYL6QBNC",
"nftStorage": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDBmMzgwOTMyQTNDODM3ZDNiN2JEYzBBNTc0NmNkMDlBRGIyNUZGMzQiLCJpc3MiOiJuZnQtc3RvcmFnZSIsImlhdCI6MTY0MjU4OTQ2ODA4MSwibmFtZSI6Im5mdC1zdG9yYWdlLWRldiJ9.hkvzea9ltcriXXHKoYd3F2Iu1Y8X5H-zunAQboC_3vw",
"etherscan": "YBR7IWEBEXFICT8M7GRV77NBX4AXJ9T53H",
"googleApi": "AIzaSyAzj7JxB-j8pJixtt6JSqLPhG0y02CGYOU",
"googleClientId": "498393666682-9eeiioee0a2sgb1671e9qir645f9n6cv.apps.googleusercontent.com"
},
"FEATURE_FLAGS": {
"moonpay": true,
"x1ex": false,
"charts": true,
"soraCard": false,
"orderBook": true,
Expand Down Expand Up @@ -43,7 +41,7 @@
}
],
"SUBQUERY_ENDPOINT": "https://api.subquery.network/sq/sora-xor/sora-dev",
"SUBSQUID_ENDPOINT": "https://squid.subsquid.io/sora-dev/v/v1/graphql",
"SUBSQUID_ENDPOINT": "https://sora.squids.live/sora-dev/v/v1/graphql",
"NETWORK_TYPE": "Dev",
"CHAIN_GENESIS_HASH": "",
"EVM_NETWORKS_IDS": [97, 1001],
Expand Down Expand Up @@ -78,4 +76,4 @@
"OTHER": "0x401c6A23a44f72151D90878DF0aa86E77fBde0e2"
}
}
}
}
127 changes: 127 additions & 0 deletions src/components/mixins/IndexerDataFetchMixin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { mixins, WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web';
import isEqual from 'lodash/fp/isEqual';
import { Component, Mixins } from 'vue-property-decorator';

import { type FetchVariables } from '@/types/indexers';
import { debouncedInputHandler } from '@/utils';

@Component
export default class IndexerDataFetchMixin extends Mixins(mixins.LoadingMixin, mixins.PaginationSearchMixin) {
totalCount = 0;
items: any[] = [];

intervalTimestamp = 0;
private interval: Nullable<ReturnType<typeof setInterval>> = null;
private updateItems = debouncedInputHandler(this.updateData, 250, { leading: false });

updateInterval = 24_000; // 4 blocks

get loadingState(): boolean {
return this.parentLoading || this.loading;
}

// override PaginationSearchMixin
get total(): number {
return this.totalCount;
}

get hasItems(): boolean {
return this.total > 0;
}

get dataVariables(): FetchVariables {
return {};
}

get updateVariables(): FetchVariables {
return {};
}

checkTriggerUpdate(current: any, prev: any) {
if (!isEqual(current)(prev)) {
this.resetPage();
this.updateItems();
}
}

async requestData(variables: FetchVariables): Promise<{ items: any[]; totalCount: number }> {
console.info('[IndexerDataFetchMixin]: requestData is not implemented');
return { items: [], totalCount: 0 };
}

getItemTimestamp(item: any): number {
console.info('[IndexerDataFetchMixin]: getItemTimestamp is not implemented');
return 0;
}

async onPaginationClick(button: WALLET_CONSTS.PaginationButton): Promise<void> {
this.handlePaginationClick(button);
this.updateItems();
}

public handlePaginationClick(button: WALLET_CONSTS.PaginationButton): void {
let current = 1;

switch (button) {
case WALLET_CONSTS.PaginationButton.Prev:
current = this.currentPage - 1;
break;
case WALLET_CONSTS.PaginationButton.Next:
current = this.currentPage + 1;
break;
case WALLET_CONSTS.PaginationButton.Last:
current = this.lastPage;
break;
}

this.currentPage = current;
}

private async updateData(): Promise<void> {
this.resetDataSubscription();

await this.fetchData();

if (this.currentPage === 1) {
this.updateIntervalTimestamp();
this.subscribeOnData();
}
}

private async fetchData(): Promise<void> {
await this.withLoading(async () => {
await this.withParentLoading(async () => {
const { totalCount, items } = await this.requestData(this.dataVariables);
this.totalCount = totalCount;
this.items = items;
});
});
}

private async fetchDataUpdates(): Promise<void> {
const { items, totalCount } = await this.requestData(this.updateVariables);
this.items = [...items, ...this.items].slice(0, this.pageAmount);
this.totalCount = this.totalCount + totalCount;
this.updateIntervalTimestamp();
}

private updateIntervalTimestamp(): void {
this.intervalTimestamp = Math.floor(this.getItemTimestamp(this.items[0]) / 1000);
}

private subscribeOnData(): void {
this.resetDataSubscription();
this.interval = setInterval(() => this.fetchDataUpdates(), this.updateInterval);
}

private resetDataSubscription(): void {
if (this.interval) {
clearInterval(this.interval);
}
this.interval = null;
}

beforeDestroy(): void {
this.resetDataSubscription();
}
}
60 changes: 60 additions & 0 deletions src/components/pages/CedeStore/CedeStoreWidget.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template>
<dialog-base :visible.sync="isVisible">
<div id="cede-widget" />
</dialog-base>
</template>

<script lang="ts">
import { renderSendWidget } from '@cedelabs/widgets-universal';
import { components, mixins, WALLET_CONSTS } from '@soramitsu/soraneo-wallet-web';
import Theme from '@soramitsu-ui/ui-vue2/lib/types/Theme';
import { Component, Mixins, Watch } from 'vue-property-decorator';
import { getter, state } from '@/store/decorators';
@Component({
components: {
DialogBase: components.DialogBase,
},
})
export default class CedeStoreWidget extends Mixins(mixins.DialogMixin, mixins.LoadingMixin, mixins.TranslationMixin) {
@state.wallet.settings.soraNetwork soraNetwork!: Nullable<WALLET_CONSTS.SoraNetwork>;
@state.wallet.account.address accountAddress!: string;
@getter.libraryTheme libraryTheme!: Theme;
rootSelector = '#cede-widget';
@Watch('isVisible', { immediate: true })
private loadCedeWidget(): void {
if (this.isVisible) {
// NOTE: the line should be removed after extension update.
localStorage.removeItem('SendStore');
try {
this.$nextTick(() => {
renderSendWidget(this.rootSelector, {
config: {
tokenSymbol: 'XOR',
network: 'sora',
address: this.accountAddress,
lockNetwork: true,
},
theme: {
mode: this.libraryTheme,
logoTheme: this.libraryTheme,
fontFamily: 'Sora',
width: '450px',
accentColor: '#f8087b',
logoBorderColor: '#f8087b',
warningColor: '#eba332',
errorColor: '#f754a3',
},
});
});
} catch (error) {
console.error("[CEDE STORE] wasn't loaded.", error);
}
}
}
}
</script>
2 changes: 0 additions & 2 deletions src/components/pages/Moonpay/MoonpayHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ import { Component, Mixins } from 'vue-property-decorator';
import MoonpayBridgeInitMixin from '../../../components/pages/Moonpay/BridgeInitMixin';
import MoonpayLogo from '../../../components/shared/Logo/Moonpay.vue';
import X1exLogo from '../../../components/shared/Logo/X1ex.vue';
import { Components } from '../../../consts';
import { lazyComponent } from '../../../router';
import { action, getter, state } from '../../../store/decorators';
Expand All @@ -92,7 +91,6 @@ const DetailsView = 'details';
@Component({
components: {
MoonpayLogo,
X1exLogo,
FormattedAmount: components.FormattedAmount,
GenericPageHeader: lazyComponent(Components.GenericPageHeader),
IFrameWidget: lazyComponent(Components.IFrameWidget),
Expand Down
3 changes: 0 additions & 3 deletions src/components/pages/SoraCard/SoraCardIntroPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,12 @@ import { getter, state } from '@/store/decorators';
import { clearPayWingsKeysFromLocalStorage } from '@/utils/card';
enum BuyButtonType {
X1,
Bridge,
}
type BuyButton = { type: BuyButtonType; text: string; button: 'primary' | 'secondary' | 'tertiary' };
@Component({
components: {
X1Dialog: lazyComponent(Components.X1Dialog),
TosDialog: lazyComponent(Components.ToSDialog),
BalanceIndicator: lazyComponent(Components.BalanceIndicator),
},
Expand All @@ -105,7 +103,6 @@ export default class SoraCardIntroPage extends Mixins(mixins.LoadingMixin, Trans
readonly MaintenanceTitle = 'Web applications are under maintenance';
readonly MaintenanceDesc = 'SORA Card is currently available in the SORA Wallet. Download to apply.';
readonly buyOptions: Array<BuyButton> = [
{ type: BuyButtonType.X1, text: 'card.depositX1Btn', button: 'primary' },
{ type: BuyButtonType.Bridge, text: 'card.bridgeTokensBtn', button: 'secondary' },
];
Expand Down
20 changes: 2 additions & 18 deletions src/components/pages/SoraCard/steps/Payment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<p>{{ t('card.oneTimeApplicationFee') }}</p>
<p>{{ t('card.applicationFeeNote') }}</p>
</div>
<x1-dialog :visible.sync="showX1Dialog" />
</div>
</template>

Expand All @@ -41,7 +40,6 @@ import type { FPNumber } from '@sora-substrate/math';
import type { AccountAsset } from '@sora-substrate/util/build/assets/types';
enum BuyButtonType {
X1,
Bridge,
Paywings,
}
Expand All @@ -52,20 +50,17 @@ type BuyButton = { type: BuyButtonType; text: string; button: 'primary' | 'secon
components: {
TokenLogo: components.TokenLogo,
BalanceIndicator: lazyComponent(Components.BalanceIndicator),
X1Dialog: lazyComponent(Components.X1Dialog),
},
})
export default class Payment extends Mixins(TranslationMixin, mixins.LoadingMixin) {
@state.soraCard.xorToDeposit private xorToDeposit!: FPNumber;
@state.soraCard.wasEuroBalanceLoaded wasEuroBalanceLoaded!: boolean;
@state.soraCard.fees fees!: Fees;
@getter.settings.x1Enabled private x1Enabled!: boolean;
@getter.soraCard.isEuroBalanceEnough isEuroBalanceEnough!: boolean;
@getter.wallet.account.isLoggedIn isLoggedIn!: boolean;
@getter.assets.xor xor!: Nullable<AccountAsset>;
showX1Dialog = false;
showPaywingsDialog = false;
WALLET_CONSTS = WALLET_CONSTS;
Expand All @@ -78,12 +73,8 @@ export default class Payment extends Mixins(TranslationMixin, mixins.LoadingMixi
}
get buyOptions(): Array<BuyButton> {
const options: Array<BuyButton> = [
{ type: BuyButtonType.Bridge, text: 'card.bridgeTokensBtn', button: !this.x1Enabled ? 'primary' : 'secondary' },
];
if (this.x1Enabled) {
options.push({ type: BuyButtonType.X1, text: 'card.depositX1Btn', button: 'primary' });
}
const options: Array<BuyButton> = [{ type: BuyButtonType.Bridge, text: 'card.bridgeTokensBtn', button: 'primary' }];
return options;
}
Expand All @@ -106,10 +97,6 @@ export default class Payment extends Mixins(TranslationMixin, mixins.LoadingMixi
return this.t('card.applicationFee', { 0: this.applicationFee });
}
private openX1(): void {
this.showX1Dialog = true;
}
private bridgeTokens(): void {
if (!this.isEuroBalanceEnough) {
router.push({ name: PageNames.Bridge, params: { amount: this.xorToDeposit.toString() } });
Expand All @@ -118,9 +105,6 @@ export default class Payment extends Mixins(TranslationMixin, mixins.LoadingMixi
buyTokens(type: BuyButtonType): void {
switch (type) {
case BuyButtonType.X1:
this.openX1();
break;
case BuyButtonType.Bridge:
this.bridgeTokens();
break;
Expand Down
Loading

0 comments on commit ed7c6fa

Please sign in to comment.