Skip to content

Commit

Permalink
use new class in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
findolor committed Feb 20, 2025
1 parent 43348a1 commit 9466c5f
Showing 1 changed file with 31 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,8 @@
import type { DisclaimerModalProps, DeployModalProps } from '../../types/modal';
import { getDeploymentTransactionArgs } from './getDeploymentTransactionArgs';
import type { HandleAddOrderResult } from './getDeploymentTransactionArgs';
enum DeploymentStepErrors {
NO_GUI = 'Error loading GUI',
NO_STRATEGY = 'No valid strategy exists at this URL',
NO_SELECT_TOKENS = 'Error loading tokens',
NO_TOKEN_INFO = 'Error loading token information',
NO_FIELD_DEFINITIONS = 'Error loading field definitions',
NO_DEPOSITS = 'Error loading deposits',
NO_TOKEN_INPUTS = 'Error loading token inputs',
NO_TOKEN_OUTPUTS = 'Error loading token outputs',
NO_GUI_DETAILS = 'Error getting GUI details',
NO_CHAIN = 'Unsupported chain ID',
SERIALIZE_ERROR = 'Error serializing state',
ADD_ORDER_FAILED = 'Failed to add order'
}
import { DeploymentStepsError, DeploymentStepsErrorCode } from '$lib/errors';
export let settings: Writable<ConfigSource>;
export let dotrain: string;
export let deployment: GuiDeployment;
Expand All @@ -59,11 +47,11 @@
let showAdvancedOptions: boolean = false;
let gui: DotrainOrderGui | null = null;
let checkingDeployment: boolean = false;
let error: DeploymentStepErrors | null = null;
let errorDetails: string | null = null;
let networkKey: string | null = null;
let subgraphUrl: string = '';
let deploymentStepsError = DeploymentStepsError.error;
export let wagmiConfig: Writable<Config | undefined>;
export let wagmiConnected: Writable<boolean>;
export let appKitModal: Writable<AppKit>;
Expand All @@ -74,8 +62,7 @@
async function handleDeploymentChange(deployment: string) {
if (!deployment || !dotrain) return;
error = null;
errorDetails = null;
DeploymentStepsError.clear();
try {
gui = await DotrainOrderGui.chooseDeployment(dotrain, deployment);
Expand All @@ -87,13 +74,11 @@
selectTokens = gui.getSelectTokens();
return selectTokens;
} catch (e) {
error = DeploymentStepErrors.NO_SELECT_TOKENS;
return (errorDetails = e instanceof Error ? e.message : 'Unknown error');
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_SELECT_TOKENS);
}
}
} catch (e) {
error = DeploymentStepErrors.NO_GUI;
return (errorDetails = e instanceof Error ? e.message : 'Unknown error');
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_GUI);
}
}
Expand All @@ -102,8 +87,7 @@
try {
allFieldDefinitions = gui.getAllFieldDefinitions();
} catch (e) {
error = DeploymentStepErrors.NO_FIELD_DEFINITIONS;
errorDetails = e instanceof Error ? e.message : 'Unknown error';
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_FIELD_DEFINITIONS);
}
}
Expand All @@ -115,8 +99,7 @@
allDepositFields = depositFields;
} catch (e) {
error = DeploymentStepErrors.NO_DEPOSITS;
errorDetails = e instanceof Error ? e.message : 'Unknown error';
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_DEPOSITS);
}
}
Expand All @@ -127,8 +110,7 @@
try {
allTokenInputs = gui.getCurrentDeployment().deployment.order.inputs;
} catch (e) {
error = DeploymentStepErrors.NO_TOKEN_INPUTS;
errorDetails = e instanceof Error ? e.message : 'Unknown error';
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_TOKEN_INPUTS);
}
}
Expand All @@ -137,8 +119,7 @@
try {
allTokenOutputs = gui.getCurrentDeployment().deployment.order.outputs;
} catch (e) {
error = DeploymentStepErrors.NO_TOKEN_OUTPUTS;
errorDetails = e instanceof Error ? e.message : 'Unknown error';
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_TOKEN_OUTPUTS);
}
}
Expand All @@ -148,15 +129,14 @@
async function updateFields() {
try {
error = null;
errorDetails = null;
DeploymentStepsError.clear();
getAllDepositFields();
getAllFieldDefinitions();
getAllTokenInputs();
getAllTokenOutputs();
} catch (e) {
error = DeploymentStepErrors.NO_GUI;
errorDetails = e instanceof Error ? e.message : 'Unknown error';
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_GUI);
}
}
Expand Down Expand Up @@ -188,24 +168,23 @@
}
async function handleDeployButtonClick() {
error = null;
errorDetails = null;
DeploymentStepsError.clear();
if (!gui) {
error = DeploymentStepErrors.NO_GUI;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_GUI);
return;
}
if (!allTokenOutputs) {
error = DeploymentStepErrors.NO_TOKEN_OUTPUTS;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_TOKEN_OUTPUTS);
return;
}
if (!wagmiConfig) {
error = DeploymentStepErrors.NO_CHAIN;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_CHAIN);
return;
}
if (!networkKey) {
error = DeploymentStepErrors.NO_CHAIN;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_CHAIN);
return;
}
Expand All @@ -217,21 +196,20 @@
result = await getDeploymentTransactionArgs(gui, $wagmiConfig);
} catch (e) {
checkingDeployment = false;
error = DeploymentStepErrors.ADD_ORDER_FAILED;
errorDetails = e instanceof Error ? e.message : 'Unknown error';
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
}
if (!result) {
checkingDeployment = false;
error = DeploymentStepErrors.ADD_ORDER_FAILED;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
return;
}
checkingDeployment = false;
const onAccept = () => {
if (!networkKey) {
error = DeploymentStepErrors.NO_CHAIN;
DeploymentStepsError.catch(null, DeploymentStepsErrorCode.NO_CHAIN);
return;
}
Expand Down Expand Up @@ -264,21 +242,18 @@
showAdvancedOptions = true;
}
} catch (e) {
error = DeploymentStepErrors.NO_SELECT_TOKENS;
return (errorDetails = e instanceof Error ? e.message : 'Unknown error');
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.NO_SELECT_TOKENS);
}
}
};
</script>

<div>
{#if error || errorDetails}
{#if $deploymentStepsError}
<Alert color="red">
{#if error}
<p class="text-red-500">{error}</p>
{/if}
{#if errorDetails}
<p class="text-red-500">{errorDetails}</p>
<p class="text-red-500">{$deploymentStepsError.code}</p>
{#if $deploymentStepsError.details}
<p class="text-red-500">{$deploymentStepsError.details}</p>
{/if}
</Alert>
{/if}
Expand Down Expand Up @@ -315,13 +290,11 @@
<TokenIOSection bind:allTokenInputs bind:allTokenOutputs {gui} {handleUpdateGuiState} />
{/if}

{#if error || errorDetails}
{#if $deploymentStepsError}
<Alert color="red">
{#if error}
<p class="text-red-500">{error}</p>
{/if}
{#if errorDetails}
<p class="text-red-500">{errorDetails}</p>
<p class="text-red-500">{$deploymentStepsError.code}</p>
{#if $deploymentStepsError.details}
<p class="text-red-500">{$deploymentStepsError.details}</p>
{/if}
</Alert>
{/if}
Expand Down

0 comments on commit 9466c5f

Please sign in to comment.