vyper: use apewrx

pull/5370/head
yann300 1 year ago committed by Joseph Izang
parent 5de4b6d0ec
commit 4bd2c4c858
  1. 4
      apps/vyper/src/app/app.tsx
  2. 33
      apps/vyper/src/app/utils/compiler.tsx

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

@ -43,10 +43,16 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
if (extension !== 'vy') { if (extension !== 'vy') {
throw new Error('Use extension .vy for Vyper.') 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', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: contract.content}) body: files
}) })
if (response.status === 404) { if (response.status === 404) {
@ -55,7 +61,30 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
/*if (response.status === 400) { /*if (response.status === 400) {
throw new Error(`Vyper compilation failed: ${response.statusText}`) throw new Error(`Vyper compilation failed: ${response.statusText}`)
}*/ }*/
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() 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