diff --git a/apps/quick-dapp/src/actions/index.ts b/apps/quick-dapp/src/actions/index.ts index d27d264d14..2c791e42ea 100644 --- a/apps/quick-dapp/src/actions/index.ts +++ b/apps/quick-dapp/src/actions/index.ts @@ -244,8 +244,50 @@ export const deploy = async (payload: any, callback: any) => { } catch (error) {} callback({ code: 'ERROR', error: 'deploy failed, please try again' }); return; + }; +export const teardown = async (payload: any, callback: any) => { + const surgeToken = localStorage.getItem('__SURGE_TOKEN'); + const surgeEmail = localStorage.getItem('__SURGE_EMAIL'); + let isLogin = false; + if (surgeToken && surgeEmail === payload.email) { + try { + await surgeClient.whoami(); + isLogin = true; + } catch (error) { + /* empty */ + } + } + if (!isLogin) { + try { + await surgeClient.login({ + user: payload.email, + password: payload.password, + }); + localStorage.setItem('__SURGE_EMAIL', payload.email); + localStorage.setItem('__SURGE_PASSWORD', payload.password); + localStorage.setItem('__DISQUS_SHORTNAME', payload.shortname); + } catch (error: any) { + callback({ code: 'ERROR', error: error.message }); + return; + } + } + + try { + await surgeClient.teardown(`${payload.subdomain}.surge.sh`); + } catch ({ message }: any) { + if (message === '403') { + callback({ code: 'ERROR', error: 'this domain belongs to someone else' }); + } else { + callback({ code: 'ERROR', error: 'gateway timeout, please try again' }); + } + return; + } + callback({ code: 'SUCCESS', error: '' }); + return; +} + export const initInstance = async ({ methodIdentifiers, devdoc, diff --git a/apps/quick-dapp/src/components/ContractGUI/index.tsx b/apps/quick-dapp/src/components/ContractGUI/index.tsx index 50f4f6a424..f66f095ca1 100644 --- a/apps/quick-dapp/src/components/ContractGUI/index.tsx +++ b/apps/quick-dapp/src/components/ContractGUI/index.tsx @@ -12,7 +12,7 @@ const getFuncABIInputs = (funABI: any) => { return txHelper.inputParametersDeclarationToString(funABI.inputs); }; -export function ContractGUI(props: { funcABI: any }) { +export function ContractGUI(props: { funcABI: any, funcId: any }) { const intl = useIntl() const isConstant = props.funcABI.constant !== undefined ? props.funcABI.constant : false; @@ -69,6 +69,7 @@ export function ContractGUI(props: { funcABI: any }) {