diff --git a/src/store/bridge/actions.ts b/src/store/bridge/actions.ts index 08f171ae1..67d517d76 100644 --- a/src/store/bridge/actions.ts +++ b/src/store/bridge/actions.ts @@ -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 = { diff --git a/src/utils/bridge/sub/classes/history.ts b/src/utils/bridge/sub/classes/history.ts index ebab2de3e..d78a23bca 100644 --- a/src/utils/bridge/sub/classes/history.ts +++ b/src/utils/bridge/sub/classes/history.ts @@ -231,10 +231,6 @@ class SubBridgeHistory extends SubNetworksConnector { asset: RegisteredAccountAsset; events: any[]; }): Promise> { - 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(); @@ -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) @@ -363,10 +363,7 @@ class SubBridgeHistory extends SubNetworksConnector { txEvents: any[]; blockEvents: any[]; }): Promise> { - 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; @@ -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; diff --git a/src/utils/bridge/sub/utils.ts b/src/utils/bridge/sub/utils.ts index 408c27452..849aebbfd 100644 --- a/src/utils/bridge/sub/utils.ts +++ b/src/utils/bridge/sub/utils.ts @@ -48,15 +48,19 @@ export const getBridgeProxyHash = (events: Array, 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, 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(); } @@ -65,7 +69,7 @@ export const getDepositedBalance = (events: Array, 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(); diff --git a/src/views/BridgeTransaction.vue b/src/views/BridgeTransaction.vue index 55558356b..3a15c5708 100644 --- a/src/views/BridgeTransaction.vue +++ b/src/views/BridgeTransaction.vue @@ -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]); }