Commit 06b2d672 authored by tom's avatar tom

fix forward slash problem in files path

parent 821d4507
...@@ -6,6 +6,7 @@ import type { SmartContract } from 'types/api/contract'; ...@@ -6,6 +6,7 @@ import type { SmartContract } from 'types/api/contract';
import LinkInternal from 'ui/shared/LinkInternal'; import LinkInternal from 'ui/shared/LinkInternal';
import CodeEditor from 'ui/shared/monaco/CodeEditor'; import CodeEditor from 'ui/shared/monaco/CodeEditor';
import formatFilePath from 'ui/shared/monaco/utils/formatFilePath';
interface Props { interface Props {
data: string; data: string;
...@@ -37,8 +38,10 @@ const ContractSourceCode = ({ data, hasSol2Yml, address, isViper, filePath, addi ...@@ -37,8 +38,10 @@ const ContractSourceCode = ({ data, hasSol2Yml, address, isViper, filePath, addi
) : null; ) : null;
const editorData = React.useMemo(() => { const editorData = React.useMemo(() => {
const defaultName = isViper ? 'index.vy' : 'index.sol'; const defaultName = isViper ? '/index.vy' : '/index.sol';
return [ { file_path: filePath || defaultName, source_code: data }, ...(additionalSource || []) ]; return [
{ file_path: formatFilePath(filePath || defaultName), source_code: data },
...(additionalSource || []).map((source) => ({ ...source, file_path: formatFilePath(source.file_path) })) ];
}, [ additionalSource, data, filePath, isViper ]); }, [ additionalSource, data, filePath, isViper ]);
return ( return (
......
...@@ -2,17 +2,7 @@ import type { File, FileTree } from '../types'; ...@@ -2,17 +2,7 @@ import type { File, FileTree } from '../types';
import sortFileTree from './sortFileTree'; import sortFileTree from './sortFileTree';
const stripLeadingSlash = (str: string) => { const stripLeadingSlash = (str: string) => str[0] === '/' ? str.slice(1) : str;
if (str[0] === '.' && str[1] === '/') {
return str.slice(2);
}
if (str[0] === '/') {
return str.slice(1);
}
return str;
};
export default function composeFileTree(files: Array<File>) { export default function composeFileTree(files: Array<File>) {
const result: FileTree = []; const result: FileTree = [];
......
// ensure that path always starts with /
export default function formatFilePath(path: string) {
if (path[0] === '.' && path[1] === '/') {
return path.slice(1);
}
if (path[0] === '/') {
return path;
}
return '/' + path;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment