diff --git a/frontend/components/Main/MainHeader.tsx b/frontend/components/Main/MainHeader.tsx index 83313c074..1a82d2333 100644 --- a/frontend/components/Main/MainHeader.tsx +++ b/frontend/components/Main/MainHeader.tsx @@ -111,12 +111,15 @@ export const MainHeader = () => { return ServicesService.createService({ serviceTemplate, deploy: true, - }).then(() => { - setServiceStatus(DeploymentStatus.DEPLOYED); - setIsBalancePollingPaused(false); - setServiceButtonState(ServiceButtonLoadingState.NotLoading); - showNotification?.('Your agent is now running!'); - }); + }) + .then(() => { + setServiceStatus(DeploymentStatus.DEPLOYED); + showNotification?.('Your agent is now running!'); + }) + .finally(() => { + setIsBalancePollingPaused(false); + setServiceButtonState(ServiceButtonLoadingState.NotLoading); + }); } catch (error) { setIsBalancePollingPaused(false); setServiceButtonState(ServiceButtonLoadingState.NotLoading); diff --git a/frontend/service/Services.ts b/frontend/service/Services.ts index 7f923085e..fe2182217 100644 --- a/frontend/service/Services.ts +++ b/frontend/service/Services.ts @@ -35,20 +35,27 @@ const createService = async ({ serviceTemplate: ServiceTemplate; deploy: boolean; }): Promise => - fetch(`${BACKEND_URL}/services`, { - method: 'POST', - body: JSON.stringify({ - ...serviceTemplate, - deploy, - configuration: { - ...serviceTemplate.configuration, - rpc: `${process.env.GNOSIS_RPC}`, + new Promise((resolve, reject) => + fetch(`${BACKEND_URL}/services`, { + method: 'POST', + body: JSON.stringify({ + ...serviceTemplate, + deploy, + configuration: { + ...serviceTemplate.configuration, + rpc: `${process.env.GNOSIS_RPC}`, + }, + }), + headers: { + 'Content-Type': 'application/json', }, + }).then((response) => { + if (response.ok) { + resolve(response.json()); + } + reject('Failed to create service'); }), - headers: { - 'Content-Type': 'application/json', - }, - }).then((response) => response.json()); + ); const deployOnChain = async (serviceHash: ServiceHash): Promise => fetch(`${BACKEND_URL}/services/${serviceHash}/onchain/deploy`, {