vyper: use apewrx

pull/4182/head
yann300 1 year ago committed by Joseph Izang
parent 633a2f214c
commit 6745f6242f
  1. 4
      apps/vyper/src/app/app.tsx
  2. 35
      apps/vyper/src/app/utils/compiler.tsx

@ -31,7 +31,7 @@ const App: React.FC = () => {
const [state, setState] = useState<AppState>({
status: 'idle',
environment: 'local',
localUrl: 'http://localhost:8000/compile'
localUrl: 'http://localhost:8000'
})
useEffect(() => {
@ -61,7 +61,7 @@ const App: React.FC = () => {
}
function compilerUrl() {
return state.environment === 'remote' ? 'https://vyper.remixproject.org/compile' : state.localUrl
return state.environment === 'remote' ? 'https://vyper.remixproject.org' : state.localUrl
}
return (

@ -43,10 +43,16 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
if (extension !== 'vy') {
throw new Error('Use extension .vy for Vyper.')
}
const response = await fetch(url, {
const files = new FormData();
const content = new Blob([contract.content], {
type: 'text/plain'
});
files.append("file", content, 'contract.vy');
let response = await fetch(url + '/compile', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: contract.content})
body: files
})
if (response.status === 404) {
@ -55,7 +61,30 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
/*if (response.status === 400) {
throw new Error(`Vyper compilation failed: ${response.statusText}`)
}*/
return response.json()
const initCallResult = await response.json()
let apiCallFinished = false
while (!apiCallFinished) {
response = await fetch(url + '/status/' + initCallResult.id , {
method: 'Get'
})
const res = await response.json()
if (res.status === 'SUCCESS') {
response = await fetch(url + '/compiled_artifact/' + initCallResult.id , {
method: 'Get'
})
apiCallFinished = true
return response.json()
} else if (res.status === 'FAILED') {
response = await fetch(url + '/exceptions/' + initCallResult.id , {
method: 'Get'
})
apiCallFinished = true
return response.json()
}
await new Promise((resolve) => setTimeout(() => resolve({}), 2000))
}
}
/**

Loading…
Cancel
Save