Skip to content

Commit

Permalink
Merge branch 'develop' into feature/add-fearless-to-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov authored May 20, 2024
2 parents 6b3e5f6 + dcf97e3 commit 61aa10b
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 54 deletions.
5 changes: 0 additions & 5 deletions public/marketing.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
[
{
"title": "ORDERBOOK SURVEY",
"img": "/marketing/orderbook.png",
"link": "https://form.typeform.com/to/DMieGaJI"
},
{
"title": "GET SORA CARD",
"img": "/marketing/card.png",
Expand Down
Binary file removed public/marketing/orderbook.png
Binary file not shown.
10 changes: 5 additions & 5 deletions src/consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ const OtherPagesMenu: Array<SidebarMenuItemLink> = [
title: PageNames.Burn,
href: '/#/burn',
},
{
icon: 'music-eject-24',
title: PageNames.SoraCard,
href: '/#/card',
},
// {
// icon: 'music-eject-24',
// title: PageNames.SoraCard,
// href: '/#/card',
// },
{
icon: 'finance-PSWAP-24',
title: PageNames.About,
Expand Down
10 changes: 5 additions & 5 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ const routes: Array<RouteConfig> = [
name: PageNames.Wallet,
component: lazyView(PageNames.Wallet),
},
{
path: '/card',
name: PageNames.SoraCard,
component: lazyView(PageNames.SoraCard),
},
// {
// path: '/card',
// name: PageNames.SoraCard,
// component: lazyView(PageNames.SoraCard),
// },
{
path: '/bridge',
component: lazyView(PageNames.BridgeContainer),
Expand Down
4 changes: 3 additions & 1 deletion src/store/bridge/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ function bridgeDataToHistoryItem(
: BridgeNetworkType.Sub;

const [from, to] = isSubBridge
? [getters.sender, getters.recipient]
? state.isSoraToEvm
? [getters.sender, getters.recipient]
: [getters.recipient, getters.sender]
: [rootState.wallet.account.address, getters.externalAccount];

const data = {
Expand Down
16 changes: 8 additions & 8 deletions src/utils/bridge/sub/classes/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,6 @@ class SubBridgeHistory extends SubNetworksConnector {
asset: RegisteredAccountAsset;
events: any[];
}): Promise<Nullable<SubHistory>> {
const { soraParachainApi } = this;

if (!soraParachainApi) throw new Error('SORA Parachain Api is not exists');

// update SORA network fee
const soraFeeEvent = events.find((e) => this.soraApi.events.transactionPayment.TransactionFeePaid.is(e.event));
history.soraNetworkFee = soraFeeEvent.event.data[1].toString();
Expand All @@ -261,6 +257,10 @@ class SubBridgeHistory extends SubNetworksConnector {
return await this.processOutgoingToLiberland(history);
}

const { soraParachainApi } = this;

if (!soraParachainApi) throw new Error('SORA Parachain Api is not exists');

// SORA Parachain extrinsic events for next search
const parachainExtrinsicEvents = networkEventsReversed.slice(messageDispatchedIndex);
// sended from SORA Parachain to Relaychain message hash (1)
Expand Down Expand Up @@ -363,10 +363,7 @@ class SubBridgeHistory extends SubNetworksConnector {
txEvents: any[];
blockEvents: any[];
}): Promise<Nullable<SubHistory>> {
const { soraApi, soraParachainApi } = this;

if (!soraParachainApi) throw new Error('SORA Parachain Api is not exists');

const { soraApi } = this;
// Token is minted to account event
const [_, eventIndex] = getDepositedBalance(blockEvents, history.from as string, this.soraApi);
history.payload.eventIndex = eventIndex;
Expand Down Expand Up @@ -425,6 +422,9 @@ class SubBridgeHistory extends SubNetworksConnector {
return history;
}

const { soraParachainApi } = this;
if (!soraParachainApi) throw new Error('SORA Parachain Api is not exists');

// If transfer received from Parachain, extrinsic events should have xcmpQueue.Success event
const messageEvent = networkExtrinsicEvents.find((e) => soraParachainApi.events.xcmpQueue.Success.is(e.event));
const externalNetwork = history.externalNetwork as SubNetwork;
Expand Down
10 changes: 7 additions & 3 deletions src/utils/bridge/sub/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ export const getBridgeProxyHash = (events: Array<any>, api: ApiPromise): string
return bridgeProxyEvent.event.data[0].toString();
};

const isEvent = (e, section: string, method: string) => {
return e.event.section === section && e.event.method === method;
};

export const getDepositedBalance = (events: Array<any>, to: string, api: ApiPromise): [string, number] => {
const recipient = subBridgeApi.formatAddress(to);

const index = events.findIndex((e) => {
let eventRecipient = '';

if (api.events.balances?.Deposit.is(e.event) || api.events.tokens?.Deposited.is(e.event)) {
if (isEvent(e, 'balances', 'Deposit') || isEvent(e, 'balances', 'Minted') || isEvent(e, 'tokens', 'Deposited')) {
eventRecipient = e.event.data.who.toString();
} else if (api.events.assets?.Transfer.is(e.event)) {
} else if (isEvent(e, 'assets', 'Transfer')) {
eventRecipient = e.event.data[1].toString();
}

Expand All @@ -65,7 +69,7 @@ export const getDepositedBalance = (events: Array<any>, to: string, api: ApiProm
return subBridgeApi.formatAddress(eventRecipient) === recipient;
});

if (index === -1) throw new Error(`Unable to find "balances.Deposit" or "tokens.Deposited" event`);
if (index === -1) throw new Error(`Unable to find balance deposit like event`);

const event = events[index];
const balance = event.event.data.amount?.toString() ?? event.event.data[3].toString();
Expand Down
15 changes: 2 additions & 13 deletions src/views/BridgeTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -515,21 +515,10 @@ export default class BridgeTransaction extends Mixins(
return this.txSoraHash || this.txInternalBlockId || this.txSoraId;
}
private getTxAccountAddress(isInternal = true) {
const accounts = [this.txInternalAccount, this.txExternalAccount];
const [a, b] = isInternal ? accounts : [...accounts].reverse();
if (this.isEvmTxType) return a;
return this.isOutgoing ? a : b;
}
get accountLinks(): LinkData[] {
const name = this.t('accountAddressText');
const internalAddress = this.getTxAccountAddress(true);
const externalAddress = this.getTxAccountAddress(false);
const internal = this.getLinkData(internalAddress, this.internalAccountLinks, name);
const external = this.getLinkData(externalAddress, this.externalAccountLinks, name, this.externalNetworkId);
const internal = this.getLinkData(this.txInternalAccount, this.internalAccountLinks, name);
const external = this.getLinkData(this.txExternalAccount, this.externalAccountLinks, name, this.externalNetworkId);
return this.sortLinksByTxDirection([internal, external]);
}
Expand Down
61 changes: 47 additions & 14 deletions src/views/Burn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
:lg="6"
:xl="6"
>
<s-form v-loading="parentLoading" class="container container--burn el-form--actions" :show-message="false">
<s-form
v-loading="parentLoading"
class="container container--burn el-form--actions"
:class="{ disabled: ended[id] }"
:show-message="false"
>
<generic-page-header class="page-header--burn" :title="title" />
<p class="description centered p4">
{{ description }}
Expand Down Expand Up @@ -66,7 +71,7 @@
class="action-button s-typography-button--large"
type="primary"
:disabled="ended[id]"
:loading="loading || parentLoading"
:loading="parentLoading || (!ended[id] && loading)"
@click="handleBurnClick(id)"
>
<template v-if="ended[id]">TIME IS OVER</template>
Expand Down Expand Up @@ -95,6 +100,7 @@
:burned-asset="selectedBurnedAsset"
:rate="selectedRate"
:max="selectedMax"
@confirm="handleBurnConfirm"
/>
</div>
</template>
Expand Down Expand Up @@ -182,8 +188,6 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
};
readonly campaigns = Object.values(this.campaignsObj);
readonly minBlock = Math.min(...this.campaigns.map((c) => c.from));
readonly maxBlock = Math.max(...this.campaigns.map((c) => c.to));
private interval: Nullable<ReturnType<typeof setInterval>> = null;
private totalXorBurned: Record<CampaignKey, FPNumber> = { ...this.defaultBurned };
Expand Down Expand Up @@ -211,6 +215,14 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
@state.wallet.settings.soraNetwork private soraNetwork!: Nullable<WALLET_CONSTS.SoraNetwork>;
@getter.wallet.account.isLoggedIn isLoggedIn!: boolean;
get minBlock(): number {
return Math.min(...this.campaigns.map((c) => c.from));
}
get maxBlock(): number {
return Math.max(...this.campaigns.map((c) => c.to));
}
getFormattedXor(rate: number): string {
return this.getFPNumber(rate).toLocaleString();
}
Expand Down Expand Up @@ -267,12 +279,22 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
const campaignBurns = burns.filter(
({ blockHeight }) => blockHeight >= campaign.from && blockHeight <= campaign.to
);
const accountsBurned = campaignBurns.reduce<Record<string, FPNumber>>((acc, { address, amount }) => {
if (!acc[address]) {
acc[address] = FPNumber.ZERO;
}
acc[address] = acc[address].add(amount);
return acc;
}, {});
const fpRate = new FPNumber(campaign.rate);
campaignBurns.forEach((burn) => {
if (burn.amount.gte(fpRate)) {
totalXorBurned[campaign.id] = totalXorBurned[campaign.id].add(burn.amount);
if (address === burn.address) {
accountXorBurned[campaign.id] = accountXorBurned[campaign.id].add(burn.amount);
Object.entries(accountsBurned).forEach(([addr, amount]) => {
if (amount.gte(fpRate)) {
totalXorBurned[campaign.id] = totalXorBurned[campaign.id].add(amount);
if (address === addr) {
accountXorBurned[campaign.id] = accountXorBurned[campaign.id].add(amount);
}
}
});
Expand All @@ -282,9 +304,11 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
this.totalXorBurned = { ...totalXorBurned };
}
private fetchDataAndCalcCountdown(): void {
this.calcCountdown();
this.fetchData();
private async fetchDataAndCalcCountdown(): Promise<void> {
await this.withLoading(async () => {
this.calcCountdown();
await this.fetchData();
});
}
handleConnectWallet(): void {
Expand All @@ -309,13 +333,18 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
this.campaignsObj.kensetsu.from = 0;
this.campaignsObj.kensetsu.to = 10_000;
}
this.fetchDataAndCalcCountdown();
await this.fetchDataAndCalcCountdown();
this.interval = setInterval(this.fetchDataAndCalcCountdown, 60_000);
});
}
handleBurnConfirm(done?: boolean): void {
if (done) {
this.loading = true;
}
}
beforeUnmount(): void {
if (this.interval) {
clearInterval(this.interval);
Expand All @@ -333,6 +362,10 @@ export default class Kensetsu extends Mixins(mixins.LoadingMixin, mixins.Formatt
margin: 0;
&--burn {
margin-bottom: $basic-spacing;
box-shadow: var(--s-shadow-element-pressed);
&.disabled {
box-shadow: var(--s-shadow-element);
}
}
}
.page-header--burn {
Expand Down

0 comments on commit 61aa10b

Please sign in to comment.