From a1565b7b69a6ab121bd98cab66df4a01a300d051 Mon Sep 17 00:00:00 2001 From: drafish Date: Wed, 17 Jul 2024 15:41:39 +0800 Subject: [PATCH] add teardown and data-id for quick-dapp e2e --- apps/quick-dapp/src/actions/index.ts | 42 +++++++++++ .../src/components/ContractGUI/index.tsx | 4 +- .../src/components/DeployPanel/index.tsx | 75 +++++++++++++++---- .../src/components/DeployPanel/theme.tsx | 3 +- .../src/components/EditInstance/index.tsx | 2 + .../src/components/ImageUpload/index.tsx | 2 +- .../components/Container/Container.tsx | 6 +- .../components/Item/Item.tsx | 5 +- .../components/MultipleContainers/index.tsx | 9 ++- .../src/app/tabs/locales/en/quickDapp.json | 2 + .../src/lib/components/universalDappUI.tsx | 1 + 11 files changed, 127 insertions(+), 24 deletions(-) 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 }) {