Skip to content

Commit

Permalink
Fix bridge tx account address issues (#1393)
Browse files Browse the repository at this point in the history
* fix bridge tx account address issues

* refactoring
  • Loading branch information
Nikita-Polyakov authored Apr 26, 2024
1 parent d964ada commit 0f99640
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
9 changes: 7 additions & 2 deletions src/store/bridge/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function bridgeDataToHistoryItem(
{ date = Date.now(), payload = {}, ...params } = {}
): IBridgeTransaction {
const { getters, state, rootState } = bridgeActionContext(context);
const { isEthBridge, isEvmBridge } = getters;
const { isEthBridge, isEvmBridge, isSubBridge } = getters;
const transactionState = isEthBridge ? WALLET_CONSTS.ETH_BRIDGE_STATES.INITIAL : BridgeTxStatus.Pending;
const externalNetwork = rootState.web3.networkSelected as BridgeNetworkId as any;
const externalNetworkType = isEthBridge
Expand All @@ -105,6 +105,10 @@ function bridgeDataToHistoryItem(
? BridgeNetworkType.Evm
: BridgeNetworkType.Sub;

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

const data = {
type: (params as any).type ?? getters.operation,
amount: (params as any).amount ?? state.amountSend,
Expand All @@ -119,7 +123,8 @@ function bridgeDataToHistoryItem(
externalNetworkFee: (params as any).externalNetworkFee,
externalNetwork,
externalNetworkType,
to: (params as any).to ?? getters.externalAccountFormatted,
from: (params as any).from ?? from,
to: (params as any).to ?? to,
payload,
};

Expand Down
10 changes: 0 additions & 10 deletions src/store/bridge/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,6 @@ const getters = defineGetters<BridgeState>()({
}
},

externalAccountFormatted(...args): string {
const { getters, state } = bridgeGetterContext(args);

if (!getters.isSubBridge) return getters.externalAccount;

return state.subBridgeConnector.network?.subNetworkConnection.nodeIsConnected
? state.subBridgeConnector.network.formatAddress(getters.externalAccount)
: getters.externalAccount;
},

sender(...args): string {
const { state, rootState, getters } = bridgeGetterContext(args);
const { address: soraAddress } = rootState.wallet.account;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/bridge/sub/classes/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class SubBridgeIncomingReducer extends SubBridgeReducer {

soraHash = getBridgeProxyHash(foundedEvents, subBridgeApi.api);

[amount, eventIndex] = getDepositedBalance(foundedEvents, tx.from as string, subBridgeApi.api);
[amount, eventIndex] = getDepositedBalance(foundedEvents, tx.to as string, subBridgeApi.api);

resolve();
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/views/BridgeContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default class BridgeContainer extends Mixins(mixins.LoadingMixin, WalletC
*/
private async updateBridgeApps(): Promise<void> {
await this.getSupportedApps();
await this.restoreSelectedNetwork();
// don't block ui while connecting to external network
this.restoreSelectedNetwork();
}
}
</script>
19 changes: 15 additions & 4 deletions src/views/BridgeTransaction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export default class BridgeTransaction extends Mixins(
@state.router.prev private prevRoute!: Nullable<PageNames>;
@getter.bridge.historyItem private historyItem!: Nullable<IBridgeTransaction>;
@getter.bridge.externalAccountFormatted private externalAccountFormatted!: string;
@getter.bridge.externalAccount private externalAccount!: string;
@action.bridge.removeHistory private removeHistory!: ({ tx, force }: { tx: any; force?: boolean }) => Promise<void>;
@action.bridge.handleBridgeTransaction private handleBridgeTransaction!: (id: string) => Promise<void>;
Expand Down Expand Up @@ -431,7 +431,7 @@ export default class BridgeTransaction extends Mixins(
get isAnotherEvmAddress(): boolean {
if (!this.isEvmTxType) return false;
return this.txExternalAccount.toLowerCase() !== this.externalAccountFormatted.toLowerCase();
return this.txExternalAccount.toLowerCase() !== this.externalAccount.toLowerCase();
}
get confirmationButtonDisabled(): boolean {
Expand Down Expand Up @@ -515,10 +515,21 @@ 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 internal = this.getLinkData(this.txInternalAccount, this.internalAccountLinks, name);
const external = this.getLinkData(this.txExternalAccount, this.externalAccountLinks, name, this.externalNetworkId);
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);
return this.sortLinksByTxDirection([internal, external]);
}
Expand Down

0 comments on commit 0f99640

Please sign in to comment.