Skip to content

Commit 684fdae

Browse files
committed
create label component. update reducer function.
1 parent 53850b8 commit 684fdae

File tree

7 files changed

+93
-19
lines changed

7 files changed

+93
-19
lines changed

libs/remix-ui/environment-explorer/src/lib/types/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,12 @@ export type Provider = {
4949
init: () => Promise<void>
5050
provider:{
5151
sendAsync: (payload: any) => Promise<void>
52+
udapp?: {
53+
REACT_API: {
54+
chainId: number,
55+
accounts: any,
56+
selectExEnv: string
57+
}
58+
}
5259
}
53-
}
60+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Provider } from '@remix-ui/environment-explorer'
2+
import { CustomTooltip } from '@remix-ui/helper'
3+
import React, { useEffect, useState } from 'react'
4+
import { FormattedMessage } from 'react-intl'
5+
import { RunTabState } from '../types'
6+
import { current } from '@reduxjs/toolkit'
7+
8+
export function DropdownLabel({ label, bridges, currentProvider, chainId, runTabState }: { label: string, bridges: any, currentProvider: any, chainId: string, runTabState: RunTabState }) {
9+
10+
const [renderLabel, setRenderLabel] = useState(label)
11+
12+
const selectedEnvs = [
13+
{ name: 'Remix VM (Cancun)', value: 'vm-cancun', chainId: 'vm-cancun' },
14+
{ name: 'Gnosis Mainnet - MetaMask', value: 'injected-metamask-gnosis', chainId: 100 },
15+
{ name: 'L2 - Optimism - MetaMask', value: 'injected-metamask-optimism', chainId: 10 },
16+
{ name: 'L2 - Arbitrum - MetaMask', value: 'injected-metamask-arbitrum', chainId: 42161 },
17+
{ name: 'Ephemery Testnet - MetaMask', value: 'injected-metamask-ephemery', chainId: 39438143 },
18+
{ name: 'Sepolia Testnet - MetaMask', value: 'injected-metamask-sepolia', chainId: 11155111 },
19+
{ name: 'L2 - Linea - MetaMask', value: 'injected-metamask-linea', chainId: 59144 },
20+
{ name: 'Injected Provider - MetaMask', value: 'injected-MetaMask' },
21+
{ name: 'WalletConnect', value: 'walletconnect' },
22+
{ name: 'Remix VM - Mainnet fork', value: 'vm-mainnet-fork', chainId: 'vm-mainnet-fork' },
23+
{ name: 'Remix VM - Sepolia fork', value: 'vm-sepolia-fork', chainId: 'vm-sepolia-fork' },
24+
{ name: 'Remix VM - Custom fork', value: 'vm-custom-fork', chainId: 'vm-custom-fork' },
25+
{ name: 'Remix VM (Shanghai)', value: 'vm-shanghai', chainId: 'vm-shanghai' },
26+
{ name: 'Remix VM (Paris)', value: 'vm-paris', chainId: 'vm-paris' },
27+
{ name: 'Remix VM (London)', value: 'vm-london', chainId: 'vm-london' },
28+
{ name: 'Remix VM (Berlin)', value: 'vm-berlin', chainId: 'vm-berlin' },
29+
{ name: 'Custom - External Http Provider', value: 'basic-http-provider', chainId: 1741104841094 },
30+
{ name: 'Dev - Hardhat Provider', value: 'hardhat-provider', chainId: 31337 },
31+
{ name: 'Dev - Foundry Provider', value: 'foundry-provider', chainId: 31337 },
32+
{ name: 'Dev - Ganache Provider', value: 'ganache-provider', chainId: 1741104841094 },
33+
]
34+
35+
useEffect(() => {
36+
const selectedEnv = selectedEnvs.find(env => (env.chainId === chainId && env.value === runTabState.selectExEnv) || (env.value === 'walletconnect' && env.value === currentProvider?.name) || env.chainId === chainId)
37+
if (selectedEnv) {
38+
setRenderLabel(selectedEnv.name)
39+
} else {
40+
setRenderLabel('Injected Provider - MetaMask')
41+
}
42+
}, [chainId])
43+
44+
return (
45+
<>
46+
<span>{renderLabel}</span>
47+
{currentProvider && bridges[currentProvider.displayName.substring(0, 13)] && (
48+
<CustomTooltip placement={'auto-end'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}>
49+
<i
50+
style={{ fontSize: 'medium' }}
51+
className={'ml-1 fa fa-rocket-launch'}
52+
aria-hidden="true"
53+
onClick={() => {
54+
window.open(bridges[currentProvider.displayName.substring(0, 13)], '_blank')
55+
}}
56+
></i>
57+
</CustomTooltip>
58+
)}
59+
</>
60+
)
61+
}

libs/remix-ui/run-tab/src/lib/components/environment.tsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import React, { useRef } from 'react'
33
import { FormattedMessage, useIntl } from 'react-intl'
44
import { EnvironmentProps } from '../types'
5-
import { Provider } from '@remix-ui/environment-explorer'
65
import { Dropdown } from 'react-bootstrap'
76
import { CustomMenu, CustomToggle, CustomTooltip } from '@remix-ui/helper'
7+
import { DropdownLabel } from './dropdownLabel'
8+
89
const _paq = (window._paq = window._paq || [])
910

1011
export function EnvironmentUI(props: EnvironmentProps) {
@@ -26,6 +27,8 @@ export function EnvironmentUI(props: EnvironmentProps) {
2627
'L2 - Arbitrum': 'https://bridge.arbitrum.io/'
2728
}
2829

30+
const isL2 = (providerDisplayName: string) => providerDisplayName && (providerDisplayName.startsWith('L2 - Optimism') || providerDisplayName.startsWith('L2 - Arbitrum'))
31+
2932
const intl = useIntl()
3033
const isSaveEvmStateChecked = props.config.get('settings/save-evm-state')
3134

@@ -118,7 +121,6 @@ export function EnvironmentUI(props: EnvironmentProps) {
118121
} else props.runTabPlugin.call('notification', 'toast', `State not available to reset, as no transactions have been made for selected environment & selected workspace.`)
119122
}
120123

121-
const isL2 = (providerDisplayName: string) => providerDisplayName && (providerDisplayName.startsWith('L2 - Optimism') || providerDisplayName.startsWith('L2 - Arbitrum'))
122124
return (
123125
<div className="udapp_crow">
124126
<label id="selectExEnv" className="udapp_settingsLabel w-100">
@@ -142,19 +144,7 @@ export function EnvironmentUI(props: EnvironmentProps) {
142144
<Dropdown id="selectExEnvOptions" data-id="settingsSelectEnvOptions" className="udapp_selectExEnvOptions">
143145
<Dropdown.Toggle as={CustomToggle} id="dropdown-custom-components" className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control" icon={null}>
144146
{isL2(currentProvider && currentProvider.displayName)}
145-
{currentProvider && currentProvider.displayName}
146-
{currentProvider && bridges[currentProvider.displayName.substring(0, 13)] && (
147-
<CustomTooltip placement={'auto-end'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}>
148-
<i
149-
style={{ fontSize: 'medium' }}
150-
className={'ml-2 fa fa-rocket-launch'}
151-
aria-hidden="true"
152-
onClick={() => {
153-
window.open(bridges[currentProvider.displayName.substring(0, 13)], '_blank')
154-
}}
155-
></i>
156-
</CustomTooltip>
157-
)}
147+
<DropdownLabel label={currentProvider && currentProvider.displayName} bridges={bridges} currentProvider={currentProvider} chainId={props.envLabel} runTabState={props.udappState} />
158148
</Dropdown.Toggle>
159149
<Dropdown.Menu as={CustomMenu} className="w-100 custom-dropdown-items" data-id="custom-dropdown-items">
160150
{props.providers.providerList.length === 0 && <Dropdown.Item>
@@ -166,6 +156,7 @@ export function EnvironmentUI(props: EnvironmentProps) {
166156
<Dropdown.Item
167157
key={name}
168158
onClick={async () => {
159+
console.log('name when switching selected env', name)
169160
handleChangeExEnv(name)
170161
}}
171162
data-id={`dropdown-item-${name}`}

libs/remix-ui/run-tab/src/lib/components/settingsUI.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export function SettingsUI(props: SettingsProps) {
2020
checkSelectionCorrectness={props.EvaluateEnvironmentSelection}
2121
modal={props.modal}
2222
config={props.runTabPlugin.config}
23+
udappState={props.udappState}
24+
envLabel={props.envLabel}
2325
/>
2426
<NetworkUI networkName={props.networkName} />
2527
<AccountUI

libs/remix-ui/run-tab/src/lib/reducers/runTab.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const runTabInitialState: RunTabState = {
2323
personalMode: false,
2424
networkName: 'VM',
2525
chainId:'-',
26+
displayName: 'Remix VM (Cancun)',
2627
providers: {
2728
providerList: [],
2829
isRequesting: false,
@@ -163,6 +164,7 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
163164
...state,
164165
selectExEnv: payload,
165166
networkName: state.selectExEnv === 'vm-cancun' ? 'VM' : state.networkName,
167+
displayName: state.providers.providerList.find((env) => env.name === state.selectExEnv).displayName,
166168
accounts: {
167169
...state.accounts,
168170
selectedAccount: '',
@@ -186,6 +188,7 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
186188
return {
187189
...state,
188190
networkName: payload,
191+
displayName: state.providers.providerList.find((env) => env.name === state.selectExEnv).displayName,
189192
}
190193
}
191194

@@ -194,7 +197,8 @@ export const runTabReducer = (state: RunTabState = runTabInitialState, action: A
194197

195198
return {
196199
...state,
197-
chainId: payload
200+
chainId: payload,
201+
displayName: state.providers.providerList.find((env) => env.name === state.selectExEnv).displayName,
198202
}
199203
}
200204

libs/remix-ui/run-tab/src/lib/run-tab.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ export function RunTabUI(props: RunTabProps) {
379379
tooltip={toast}
380380
signMessageWithAddress={signMessage}
381381
passphrase={runTab.passphrase}
382+
udappState={runTab}
383+
envLabel={runTab.chainId}
382384
/>
383385
<ContractDropdownUI
384386
selectedAccount={runTab.accounts.selectedAccount}

libs/remix-ui/run-tab/src/lib/types/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export interface RunTabState {
3737
selectExEnv: string,
3838
personalMode: boolean,
3939
networkName: string,
40-
chainId: string
40+
chainId: string,
41+
displayName: string,
4142
providers: {
4243
providerList: Provider[],
4344
isRequesting: boolean,
@@ -110,6 +111,9 @@ export interface RunTabState {
110111

111112
export interface SettingsProps {
112113
runTabPlugin: RunTab,
114+
udappState: RunTabState
115+
envLabel: string,
116+
currentSelectedEnv?: string,
113117
selectExEnv: string,
114118
EvaluateEnvironmentSelection: any
115119
accounts: {
@@ -148,6 +152,7 @@ export interface SettingsProps {
148152
export interface EnvironmentProps {
149153
checkSelectionCorrectness: any
150154
runTabPlugin: RunTab,
155+
envLabel: string,
151156
selectedEnv: string,
152157
providers: {
153158
providerList: Provider[],
@@ -157,7 +162,9 @@ export interface EnvironmentProps {
157162
},
158163
setExecutionContext: (executionContext: { context: string }) => void
159164
modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void, okBtnClass?: string, cancelBtnClass?: string) => void,
160-
config: any
165+
config: any,
166+
currentSelectedEnv?: string,
167+
udappState: RunTabState
161168
}
162169

163170
export interface NetworkProps {

0 commit comments

Comments
 (0)