Skip to content

Commit 3e1c80a

Browse files
committed
Refactor: Consolidate file fetching & clean up comments
1 parent 68dd754 commit 3e1c80a

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

apps/remix-ide/src/app/components/bottom-bar.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
1010
const [explaining, setExplaining] = useState(false)
1111
const [aiSwitch, setAiSwitch] = useState(true)
1212
const [currentExt, setCurrentExt] = useState('')
13+
const [currentFilePath, setCurrentFilePath] = useState('')
1314

1415
useEffect(() => {
1516
const getAI = async () => {
@@ -24,10 +25,12 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
2425
const getCurrentExt = async () => {
2526
try {
2627
const path = await plugin.call('fileManager', 'getCurrentFile')
28+
setCurrentFilePath(path)
2729
const ext = path?.split('.').pop()?.toLowerCase() || ''
2830
setCurrentExt(ext)
2931
} catch (err) {
3032
console.error('Failed to get current file', err)
33+
setCurrentFilePath('')
3134
setCurrentExt('')
3235
}
3336
}
@@ -44,12 +47,15 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
4447
}, [plugin])
4548

4649
const handleExplain = async () => {
50+
if (!currentFilePath) {
51+
plugin.call('notification', 'toast', 'No file selected to explain.');
52+
return
53+
}
4754
setExplaining(true)
4855
try {
4956
await plugin.call('menuicons', 'select', 'remixaiassistant')
5057
await new Promise(resolve => setTimeout(resolve, 500))
51-
const path = await plugin.call('fileManager', 'getCurrentFile')
52-
const content = await plugin.call('fileManager', 'readFile', path)
58+
const content = await plugin.call('fileManager', 'readFile', currentFilePath)
5359
await plugin.call('remixAI', 'chatPipe', 'code_explaining', content)
5460

5561
} catch (err) {
@@ -79,7 +85,7 @@ export const BottomBar = ({ plugin }: BottomBarProps) => {
7985
<button
8086
className="btn explain-btn"
8187
onClick={handleExplain}
82-
disabled={explaining}
88+
disabled={explaining || !currentFilePath}
8389
>
8490
<img src="assets/img/remixAI_small.svg" alt="Remix AI" className="explain-icon" />
8591
<span>{getExplainLabel()}</span>

libs/remix-ui/helper/src/lib/solidity-scan.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// remix-project/libs/remix-ui/helper/src/lib/solidity-scan.tsx
2-
31
import React from 'react'
42
import axios from 'axios'
53
import { FormattedMessage } from 'react-intl'

libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,6 @@ export const TabsUI = (props: TabsUIProps) => {
207207
setCompileState('idle')
208208
}, [tabsState.selectedIndex])
209209

210-
/**
211-
* Compiles the current file and triggers the 'Publish' functionality of the Solidity Compiler plugin.
212-
* * ⚠️ WARNING: This function uses a brittle method of direct DOM manipulation
213-
* * instead of formal inter-plugin API communication.
214-
* * It relies on the compiler UI's button ID (e.g., 'publishOnIpfs'), so it may break
215-
* * without warning during future updates.
216-
* * It also uses an unreliable `setTimeout` to wait for the UI to render after compilation.
217-
* * @todo This logic should be refactored in the future to a more stable approach:
218-
* * add a formal API to the Solidity Compiler plugin and call that API instead.
219-
* * @param {'ipfs' | 'swarm'} storageType - The type of storage to publish to.
220-
*/
221210
const handleCompileAndPublish = async (storageType: 'ipfs' | 'swarm') => {
222211
setCompileState('compiling')
223212
await props.plugin.call('notification', 'toast', `Switching to Solidity Compiler to publish...`)

0 commit comments

Comments
 (0)