Skip to content

Commit 9b05b74

Browse files
ioedeveloperyann300
authored andcommitted
Use wallet icon to manage modal
1 parent 99ab605 commit 9b05b74

File tree

5 files changed

+60
-51
lines changed

5 files changed

+60
-51
lines changed

apps/remix-ide/src/app/plugins/walletconnect/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@ export class WalletConnect extends Plugin {
2929

3030
constructor () {
3131
super(profile)
32-
this.appkit = createAppKit({
33-
adapters: [new Ethers5Adapter()],
34-
projectId: constants.PROJECT_ID,
35-
metadata: constants.METADATA,
36-
networks: [mainnet, sepolia, arbitrum, arbitrumSepolia, optimism, optimismSepolia, solana, solanaTestnet, bitcoin, bitcoinTestnet, bsc, bscTestnet, polygon]
37-
})
38-
this.chains = constants.chains
3932
}
4033

4134
onActivation() {
42-
this.subscribeToEvents()
35+
if (!this.appkit) {
36+
this.appkit = createAppKit({
37+
adapters: [new Ethers5Adapter()],
38+
projectId: constants.PROJECT_ID,
39+
metadata: constants.METADATA,
40+
networks: [mainnet, sepolia, arbitrum, arbitrumSepolia, optimism, optimismSepolia, solana, solanaTestnet, bitcoin, bitcoinTestnet, bsc, bscTestnet, polygon]
41+
})
42+
this.chains = constants.chains
43+
this.subscribeToEvents()
44+
}
4345
}
4446

4547
async init() {
@@ -115,7 +117,7 @@ export class WalletConnect extends Plugin {
115117
return this.sendWalletConnectRequest(data)
116118
} else {
117119
const err = `Cannot make ${data.method} request. Remix client is not connected to walletconnect client`
118-
console.error(err)
120+
119121
return { jsonrpc: '2.0', error: { message: err, code: -32603 }, id: data.id }
120122
}
121123

apps/remix-ide/src/blockchain/execution-context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class ExecutionContext {
148148
if (!infoCb) infoCb = () => { /* Do nothing. */ }
149149
if (this.customNetWorks[context]) {
150150
var network = this.customNetWorks[context]
151-
if (context !== 'walletconnect') await network.init()
151+
await network.init()
152152
this.currentFork = network.config.fork
153153
this.executionContext = context
154154
// injected

libs/remix-ui/run-tab/src/lib/actions/account.ts

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,16 @@ const _getProviderDropdownValue = (plugin: RunTab): string => {
7676
}
7777

7878
export const setExecutionContext = (plugin: RunTab, dispatch: React.Dispatch<any>, executionContext: { context: string, fork: string }) => {
79-
if (executionContext.context === 'walletconnect') {
80-
setWalletConnectExecutionContext(plugin, dispatch, executionContext)
81-
} else {
82-
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
83-
plugin.call('notification', 'toast', alertMsg)
84-
}, async () => {
85-
setFinalContext(plugin, dispatch)
86-
})
79+
if (executionContext.context && executionContext.context !== plugin.REACT_API.selectExEnv) {
80+
if (executionContext.context === 'walletconnect') {
81+
setWalletConnectExecutionContext(plugin, dispatch, executionContext)
82+
} else {
83+
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
84+
plugin.call('notification', 'toast', alertMsg)
85+
}, async () => {
86+
setFinalContext(plugin, dispatch)
87+
})
88+
}
8789
}
8890
}
8991

@@ -313,33 +315,27 @@ export const addFileInternal = async (plugin: RunTab, path: string, content: str
313315
}
314316

315317
const setWalletConnectExecutionContext = (plugin: RunTab, dispatch: React.Dispatch<any>, executionContext: { context: string, fork: string }) => {
316-
plugin.call('walletconnect', 'isWalletConnected').then((isConnected) => {
317-
if (isConnected) {
318-
plugin.call('walletconnect', 'openModal').then(() => {
319-
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
320-
plugin.call('notification', 'toast', alertMsg)
321-
}, async () => {
322-
setFinalContext(plugin, dispatch)
323-
})
324-
})
325-
} else {
326-
plugin.call('walletconnect', 'openModal').then(() => {
327-
plugin.on('walletconnect', 'connectionSuccessful', () => {
328-
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
329-
plugin.call('notification', 'toast', alertMsg)
330-
}, async () => {
331-
setFinalContext(plugin, dispatch)
332-
})
333-
})
334-
plugin.on('walletconnect', 'connectionFailed', (msg) => {
335-
plugin.call('notification', 'toast', msg)
336-
})
337-
plugin.on('walletconnect', 'connectionDisconnected', (msg) => {
338-
plugin.call('notification', 'toast', msg)
339-
// reset to default provider if connection fails
340-
setExecutionContext(plugin, dispatch, { context: plugin.blockchain.defaultPinnedProviders[0], fork: null })
341-
})
318+
plugin.call('walletconnect', 'openModal').then(() => {
319+
plugin.on('walletconnect', 'connectionSuccessful', () => {
320+
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
321+
plugin.call('notification', 'toast', alertMsg)
322+
}, async () => {
323+
setFinalContext(plugin, dispatch)
342324
})
343-
}
325+
})
326+
plugin.on('walletconnect', 'connectionFailed', (msg) => {
327+
plugin.call('notification', 'toast', msg)
328+
cleanupWalletConnectEvents(plugin)
329+
})
330+
plugin.on('walletconnect', 'connectionDisconnected', (msg) => {
331+
plugin.call('notification', 'toast', msg)
332+
cleanupWalletConnectEvents(plugin)
333+
})
344334
})
345335
}
336+
337+
const cleanupWalletConnectEvents = (plugin: RunTab) => {
338+
plugin.off('walletconnect', 'connectionFailed')
339+
plugin.off('walletconnect', 'connectionDisconnected')
340+
plugin.off('walletconnect', 'connectionSuccessful')
341+
}

libs/remix-ui/run-tab/src/lib/actions/events.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export const setupEvents = (plugin: RunTab) => {
4040
plugin.blockchain.event.register('contextChanged', async (context) => {
4141
dispatch(resetProxyDeployments())
4242
getNetworkProxyAddresses(plugin, dispatch)
43-
if (context !== 'walletconnect') {
44-
(await plugin.call('manager', 'isActive', 'walletconnect')) && plugin.call('manager', 'deactivatePlugin', 'walletconnect')
45-
}
4643
setFinalContext(plugin, dispatch)
4744
fillAccountsList(plugin, dispatch)
4845
// 'contextChanged' & 'networkStatus' both are triggered on workspace & network change

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CustomTooltip } from '@remix-ui/helper'
1+
import { CustomTooltip, RenderIf } from '@remix-ui/helper'
22
import React, { useEffect, useState } from 'react'
33
import { FormattedMessage } from 'react-intl'
44
import { RunTabState } from '../types'
@@ -37,7 +37,7 @@ export function DropdownLabel({ label, bridges, currentProvider, chainId, runTab
3737
return (
3838
<>
3939
<span>{renderLabel}</span>
40-
{isL2(renderLabel) && bridges[renderLabel.substring(0, 13)] && (
40+
<RenderIf condition={isL2(renderLabel) && bridges[renderLabel.substring(0, 13)]}>
4141
<CustomTooltip placement={'auto-end'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}>
4242
<i
4343
style={{ fontSize: 'medium' }}
@@ -48,7 +48,21 @@ export function DropdownLabel({ label, bridges, currentProvider, chainId, runTab
4848
}}
4949
></i>
5050
</CustomTooltip>
51-
)}
51+
</RenderIf>
52+
<RenderIf condition={runTabState.selectExEnv === 'walletconnect'}>
53+
<CustomTooltip placement={'auto-end'} tooltipClasses="text-nowrap" tooltipId="info-recorder" tooltipText={<FormattedMessage id="udapp.tooltipText3" />}>
54+
<i
55+
style={{ fontSize: 'medium' }}
56+
className={'ml-1 fa fa-wallet'}
57+
aria-hidden="true"
58+
onClick={(e) => {
59+
e.preventDefault()
60+
e.stopPropagation()
61+
plugin.call('walletconnect', 'openModal')
62+
}}
63+
></i>
64+
</CustomTooltip>
65+
</RenderIf>
5266
</>
5367
)
5468
}

0 commit comments

Comments
 (0)