Skip to content

Commit 3511ce8

Browse files
committed
Use wallet icon to manage modal
1 parent 6b2e06c commit 3511ce8

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
@@ -73,14 +73,16 @@ const _getProviderDropdownValue = (plugin: RunTab): string => {
7373
}
7474

7575
export const setExecutionContext = (plugin: RunTab, dispatch: React.Dispatch<any>, executionContext: { context: string, fork: string }) => {
76-
if (executionContext.context === 'walletconnect') {
77-
setWalletConnectExecutionContext(plugin, dispatch, executionContext)
78-
} else {
79-
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
80-
plugin.call('notification', 'toast', alertMsg)
81-
}, async () => {
82-
setFinalContext(plugin, dispatch)
83-
})
76+
if (executionContext.context && executionContext.context !== plugin.REACT_API.selectExEnv) {
77+
if (executionContext.context === 'walletconnect') {
78+
setWalletConnectExecutionContext(plugin, dispatch, executionContext)
79+
} else {
80+
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
81+
plugin.call('notification', 'toast', alertMsg)
82+
}, async () => {
83+
setFinalContext(plugin, dispatch)
84+
})
85+
}
8486
}
8587
}
8688

@@ -236,33 +238,27 @@ export const addFileInternal = async (plugin: RunTab, path: string, content: str
236238
}
237239

238240
const setWalletConnectExecutionContext = (plugin: RunTab, dispatch: React.Dispatch<any>, executionContext: { context: string, fork: string }) => {
239-
plugin.call('walletconnect', 'isWalletConnected').then((isConnected) => {
240-
if (isConnected) {
241-
plugin.call('walletconnect', 'openModal').then(() => {
242-
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
243-
plugin.call('notification', 'toast', alertMsg)
244-
}, async () => {
245-
setFinalContext(plugin, dispatch)
246-
})
247-
})
248-
} else {
249-
plugin.call('walletconnect', 'openModal').then(() => {
250-
plugin.on('walletconnect', 'connectionSuccessful', () => {
251-
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
252-
plugin.call('notification', 'toast', alertMsg)
253-
}, async () => {
254-
setFinalContext(plugin, dispatch)
255-
})
256-
})
257-
plugin.on('walletconnect', 'connectionFailed', (msg) => {
258-
plugin.call('notification', 'toast', msg)
259-
})
260-
plugin.on('walletconnect', 'connectionDisconnected', (msg) => {
261-
plugin.call('notification', 'toast', msg)
262-
// reset to default provider if connection fails
263-
setExecutionContext(plugin, dispatch, { context: plugin.blockchain.defaultPinnedProviders[0], fork: null })
264-
})
241+
plugin.call('walletconnect', 'openModal').then(() => {
242+
plugin.on('walletconnect', 'connectionSuccessful', () => {
243+
plugin.blockchain.changeExecutionContext(executionContext, null, (alertMsg) => {
244+
plugin.call('notification', 'toast', alertMsg)
245+
}, async () => {
246+
setFinalContext(plugin, dispatch)
265247
})
266-
}
248+
})
249+
plugin.on('walletconnect', 'connectionFailed', (msg) => {
250+
plugin.call('notification', 'toast', msg)
251+
cleanupWalletConnectEvents(plugin)
252+
})
253+
plugin.on('walletconnect', 'connectionDisconnected', (msg) => {
254+
plugin.call('notification', 'toast', msg)
255+
cleanupWalletConnectEvents(plugin)
256+
})
267257
})
268258
}
259+
260+
const cleanupWalletConnectEvents = (plugin: RunTab) => {
261+
plugin.off('walletconnect', 'connectionFailed')
262+
plugin.off('walletconnect', 'connectionDisconnected')
263+
plugin.off('walletconnect', 'connectionSuccessful')
264+
}

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)