Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/react-environment/src/WebbProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { WebbPolkadot } from './api-providers/polkadot';
import { extensionNotInstalled, unsupportedChain } from './error';
import { SettingProvider } from './SettingProvider';
import { Chain, netStorageFactory, NetworkStorage, Wallet, WebbApiProvider, WebbContext } from './webb-context';
import { appEvent } from '@webb-dapp/react-environment/app-event';

interface WebbProviderProps extends BareProps {
applicationName: string;
Expand Down Expand Up @@ -322,6 +323,12 @@ export const WebbProvider: FC<WebbProviderProps> = ({ applicationName = 'Webb Da
init().finally(() => {
setIsInit(false);
});
appEvent.on('switchNetwork', ([chain, wallet]) => {
switchChainAndStore(chain, wallet);
});
appEvent.on('setActiveAccount', (nextAccount) => {
setActiveAccount(nextAccount);
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
Expand Down
19 changes: 19 additions & 0 deletions packages/react-environment/src/app-event/app-events.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Chain, Wallet } from '@webb-dapp/react-environment';
import { Account } from '@webb-dapp/wallet/account/Accounts.adapter';
import { EventBus } from '@webb-tools/app-util';

export type AppEvents = {
changeNetworkSwitcherVisibility: boolean;
switchNetwork: [Chain, Wallet];
setActiveAccount: Account;
};

class AppEvent extends EventBus<AppEvents> {
public readonly send: <E extends keyof AppEvents>(event: E, data: AppEvents[E]) => void | Promise<void>;
constructor() {
super();
this.send = this.emit;
}
}

export const appEvent = new AppEvent();
1 change: 1 addition & 0 deletions packages/react-environment/src/app-event/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './app-events.class';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { InteractiveFeedback, WebbErrorCodes } from '@webb-dapp/utils/webb-error';
import { appEvent } from '@webb-dapp/react-environment/app-event';

export function insufficientApiInterface(): InteractiveFeedback {
let interactiveFeedback: InteractiveFeedback;
Expand All @@ -15,6 +16,7 @@ export function insufficientApiInterface(): InteractiveFeedback {
'Switch',
() => {
interactiveFeedback?.cancel();
appEvent.send('changeNetworkSwitcherVisibility', true);
},
'success'
)
Expand Down
11 changes: 11 additions & 0 deletions packages/ui-components/src/NetworkManger/NetworkManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Padding } from '@webb-dapp/ui-components/Padding/Padding';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import styled from 'styled-components';
import { Pallet } from '@webb-dapp/ui-components/styling/colors';
import { appEvent } from '@webb-dapp/react-environment/app-event';

const NetworkManagerWrapper = styled.div`
padding: 1rem;
Expand Down Expand Up @@ -96,6 +97,13 @@ export const NetworkManager: React.FC<NetworkManagerProps> = () => {
setConnectionStep(ConnectionStep.SelectChain);
}
}, [connectionStep]);

useEffect(() => {
const off = appEvent.on('changeNetworkSwitcherVisibility', (next) => {
setOpen(next);
});
return () => off && off();
}, []);
const content = useMemo(() => {
switch (connectionStep) {
case ConnectionStep.SelectChain:
Expand Down Expand Up @@ -406,6 +414,7 @@ const NetworkIndecatorWrapper = styled.button`
padding: 0 0.3rem;
//background: ${({ theme }: { theme: Pallet }) => theme.background};
position: relative;

&:before {
position: absolute;
content: '';
Expand All @@ -417,6 +426,7 @@ const NetworkIndecatorWrapper = styled.button`
background: ${({ theme }: { theme: Pallet }) => (theme.type === 'light' ? 'white' : 'rgba(51, 81, 242, 0.28)')};
border-radius: 32px;
}

&:after {
z-index: 2;
position: absolute;
Expand All @@ -428,6 +438,7 @@ const NetworkIndecatorWrapper = styled.button`
background: ${({ theme }: { theme: Pallet }) => (theme.type === 'light' ? 'rgba(71, 69, 83, 0.1)' : 'black')};
border-radius: 32px;
}

*:first-child {
position: relative;
z-index: 3;
Expand Down