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 Apr 26, 2024
2 parents 758746b + 0f99640 commit fd40b06
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 33 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
25 changes: 12 additions & 13 deletions src/store/web3/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import ethersUtil, { Provider, PROVIDER_ERROR } from '@/utils/ethers-util';
import type { SubNetwork } from '@sora-substrate/util/build/bridgeProxy/sub/types';
import type { ActionContext } from 'vuex';

async function connectNetworkType(context: ActionContext<any, any>): Promise<void> {
const { state } = web3ActionContext(context);

if (state.networkType === BridgeNetworkType.Sub) {
autoselectSubAddress(context);
await connectSubNetwork(context);
}
}

async function connectSubNetwork(context: ActionContext<any, any>): Promise<void> {
const { getters, rootState } = web3ActionContext(context);
const subNetwork = getters.selectedNetwork;
Expand Down Expand Up @@ -80,13 +89,6 @@ async function autoselectSubAddress(context: ActionContext<any, any>): Promise<v
}
}

async function getRegisteredAssets(context: ActionContext<any, any>): Promise<void> {
const { rootDispatch } = web3ActionContext(context);

await rootDispatch.assets.getRegisteredAssets();
await autoselectBridgeAsset(context);
}

const actions = defineActions({
async selectEvmProvider(context, provider: Provider): Promise<void> {
const { commit, state } = web3ActionContext(context);
Expand Down Expand Up @@ -130,19 +132,16 @@ const actions = defineActions({
},

async selectExternalNetwork(context, { id, type }: { id: BridgeNetworkId; type: BridgeNetworkType }): Promise<void> {
const { commit, dispatch } = web3ActionContext(context);
const { commit, dispatch, rootDispatch } = web3ActionContext(context);

await dispatch.disconnectExternalNetwork();

commit.setNetworkType(type);
commit.setSelectedNetwork(id);

getRegisteredAssets(context);
await Promise.allSettled([rootDispatch.assets.getRegisteredAssets(), connectNetworkType(context)]);

if (type === BridgeNetworkType.Sub) {
autoselectSubAddress(context);
await connectSubNetwork(context);
}
await autoselectBridgeAsset(context);
},

async changeEvmNetworkProvided(context): Promise<void> {
Expand Down
10 changes: 8 additions & 2 deletions src/utils/bridge/sub/classes/adapters/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export class SubAdapter {
return !!this.api?.isConnected;
}

get closed(): boolean {
return !this.connected && !this.subNetworkConnection.nodeAddressConnecting;
}

get chainSymbol(): string | undefined {
return this.api?.registry.chainTokens[0];
}
Expand All @@ -61,7 +65,9 @@ export class SubAdapter {
};

protected async withConnection<T>(onSuccess: AsyncFnWithoutArgs<T> | FnWithoutArgs<T>, fallback: T) {
if (!this.connected && !this.connection.loading) return fallback;
if (this.closed) {
return fallback;
}

await this.api.isReady;

Expand All @@ -74,7 +80,7 @@ export class SubAdapter {
}

public async connect(): Promise<void> {
if (!this.connected && !this.api && !this.connection.loading) {
if (this.closed && !this.api) {
try {
await this.subNetworkConnection.connect();
} catch {}
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 fd40b06

Please sign in to comment.