Skip to content

Commit

Permalink
feat: updates to support sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jtary committed Aug 30, 2023
1 parent 5244578 commit 718f1aa
Show file tree
Hide file tree
Showing 14 changed files with 210 additions and 99 deletions.
2 changes: 1 addition & 1 deletion web/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ rules:
semi:
- error
- always
@typescript-eslint/no-explicit-any: "off"
typescript-eslint/no-explicit-any: "off"
react/react-in-jsx-scope: "off"
react/no-unescaped-entities: "off"
4 changes: 2 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"css": "npx tailwindcss -i ./src/style/app.scss -o ./src/style/app.css --watch"
},
"dependencies": {
"@akashnetwork/akashjs": "^0.4.7",
"@akashnetwork/akashjs": "^0.4.11",
"@cosmjs/launchpad": "^0.27.1",
"@cosmjs/proto-signing": "0.25.4",
"@craco/craco": "^6.4.4",
Expand Down Expand Up @@ -92,4 +92,4 @@
]
},
"typings": "./src/react-app-env.d.ts"
}
}
66 changes: 66 additions & 0 deletions web/src/_helpers/async-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
type AsyncFunction = (...params: any[]) => Promise<any>;
type AsyncMapFunction<T, R> = (elem: T, index: number, array: T[]) => Promise<R>;
type ErrorHandler = (e: any) => void;

function noop<T>(result: T) {
return result;
}

export async function asyncForEach<T, R>(arr: Array<T>, callback: AsyncMapFunction<T, R>) {
return asyncMap(arr, callback).then(noop);
}

export async function asyncMap<T, R>(arr: Array<T>, callback: AsyncMapFunction<T, R>) {
return Promise.all(arr.map(callback));
}

/**
* Wrapper for setTimeout that returns a promise.
*
* @param timeout The delay in milliseconds
* @param action The function to call after the delay
*
* @returns Promise that resolves after the delay
*/
export function schedule<TFn extends AsyncFunction>(timeout: number, action: TFn) {
return new Promise<ReturnType<TFn>>((resolve, reject) => {
const fire = () => action().then(resolve, reject);
setTimeout(fire, timeout);
});
}

/**
* Returns a function that will accept an error, call the notify function
* with that error, and then schedule a retry using the provided function.
*
* @param fn The function to call after the delay
* @param delay The delay between catch the error and retrying
* @param notify A function to pass the captured error too
*
* @returns A function suitable for use as an error handler
*/
function retryHandler(fn: any, delay: number, notify: ErrorHandler) {
const attempt = () => fn();

return (e: any) => {
notify(e);
return schedule(delay, attempt);
};
}

/**
* Schedule retries for a function that returns a promise.
*
* @param attempt Function that returns a promise
* @param delays Array of delays between retries
* @param notify Function to call with the error (optional)
*
* @returns New that will only fail if all retries fail
*/
export function retry(attempt: any, delays: number[], notify = noop) {
const addRetry = (promise: Promise<any>, delay: number) => (
promise.catch(retryHandler(attempt, delay, notify))
);

return delays.reduce(addRetry, attempt());
}
41 changes: 41 additions & 0 deletions web/src/_helpers/sandbox-chain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export default {
'rpc': 'https://rpc.sandbox-01.aksh.pw',
'rest': 'https://api.sandbox-01.aksh.pw',
'chainId': 'sandbox-01',
'chainName': 'Akash Sandbox',
'chainSymbolImageUrl': 'https://raw.githubusercontent.com/chainapsis/keplr-chain-registry/main/images/akashnet/chain.png',
'stakeCurrency': {
'coinDenom': 'AKT',
'coinMinimalDenom': 'uakt',
'coinDecimals': 6,
'coinGeckoId': 'akash-network'
},
'bip44': {
'coinType': 118
},
'bech32Config': {
'bech32PrefixAccAddr': 'akash',
'bech32PrefixAccPub': 'akashpub',
'bech32PrefixValAddr': 'akashvaloper',
'bech32PrefixValPub': 'akashvaloperpub',
'bech32PrefixConsAddr': 'akashvalcons',
'bech32PrefixConsPub': 'akashvalconspub'
},
'currencies': [
{
'coinDenom': 'AKT',
'coinMinimalDenom': 'uakt',
'coinDecimals': 6,
'coinGeckoId': 'akash-network'
}
],
'feeCurrencies': [
{
'coinDenom': 'AKT',
'coinMinimalDenom': 'uakt',
'coinDecimals': 6,
'coinGeckoId': 'akash-network'
}
],
'features': []
};
File renamed without changes.
2 changes: 2 additions & 0 deletions web/src/api/rpc/beta3/deployments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ export async function createDeployment(
}),
};

console.log(msg);

const tx = await client.signAndBroadcast(account.address, [msg], 'auto', 'Creating the deployment');

return {
Expand Down
3 changes: 3 additions & 0 deletions web/src/components/Deployment/DeploymentActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type DeploymentActionButtonProps = {
tooltipTitle: string;
tooltip: React.ReactNode;
linkTo: string;
condition: boolean;
children: React.ReactNode;
} & ButtonProps;

Expand All @@ -21,6 +22,7 @@ const DeploymentActionButton: React.FC<DeploymentActionButtonProps> = (props) =>
tooltip,
linkTo,
children,
condition,
...rest
} = props;

Expand All @@ -29,6 +31,7 @@ const DeploymentActionButton: React.FC<DeploymentActionButtonProps> = (props) =>
title={tooltipTitle}
to={linkTo}
className="grow"
condition={condition}
>
<Button
fullWidth
Expand Down
19 changes: 5 additions & 14 deletions web/src/components/Deployment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,11 @@ const Deployment: React.FC<any> = () => {

// In case that current SDL is deployed from another machine, only show Tooltip and not show re-deploy page
const ConditionalLinkReDeploy = application !== null ? Link : Tooltip;

// In case that current SDL is deployed from another machine or status closed, only show Tooltip and not show update page
const ConditionalLinkUpdate =
application !== null && deployment?.deployment?.state === 1 ? Link : Tooltip;
const canUpdate = application !== null && deployment?.deployment?.state === 1;

console.log('Can Update', canUpdate);

return (
<Stack>
Expand Down Expand Up @@ -281,18 +283,7 @@ const Deployment: React.FC<any> = () => {
aria-label="update deployment"
aria-controls="menu-appbar"
aria-haspopup="true"
startIcon={<Icon type="update" />}
>
Update Deployment
</DeploymentActionButton>

<DeploymentActionButton
tooltipTitle="This SDL is deployed with another tool and can't be re-deployed from here"
tooltip={ReDeployTooltip}
linkTo={'re-deploy'}
aria-label="update deployment"
aria-controls="menu-appbar"
aria-haspopup="true"
condition={canUpdate}
startIcon={<Icon type="update" />}
>
Update Deployment
Expand Down
124 changes: 58 additions & 66 deletions web/src/components/DeploymentStepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const DeploymentStepper: React.FC<DeploymentStepperProps> = () => {
const [errorMessage, setErrorMessage] = React.useState<string>();
const [myDeployments, setMyDeployments] = useRecoilState(myDeploymentsAtom);
const [, setDeploymentRefresh] = useRecoilState(deploymentDataStale);
const { mutate: mxCreateDeployment, isLoading: deploymentProgressVisible } =
const { mutateAsync: mxCreateDeployment, isLoading: deploymentProgressVisible } =
useMutation(createDeployment);
const { mutate: mxCreateLease, isLoading: leaseProgressVisible } = useMutation(createLease);
const { mutate: mxSendManifest, isLoading: manifestSending } = useMutation(sendManifest);
Expand Down Expand Up @@ -174,7 +174,7 @@ const DeploymentStepper: React.FC<DeploymentStepperProps> = () => {
setErrorMessage(message);
setCardMessage('');
setOpen(true);
throw new Error(`${method}: ${error.message}`);
// throw new Error(`${method}: ${error.message}`);
};

return (
Expand All @@ -187,32 +187,24 @@ const DeploymentStepper: React.FC<DeploymentStepperProps> = () => {
// it uses the useFormikContext hook.
// const { submitForm } = useFormikContext();
setCardMessage('Creating deployment');
mxCreateDeployment({ sdl: value.sdl, depositor: value.depositor })
.then(async (result) => {
if (result && result.deploymentId) {
setDeploymentId(result.deploymentId);
setSdl(value.sdl);

try {
const result = mxCreateDeployment(
{ sdl: value.sdl, depositor: value.depositor },
{
onSuccess: async (result) => {
if (result && result.deploymentId) {
setDeploymentId(result.deploymentId);
setSdl(value.sdl);
// set deployment to localStorage object using Atom
const _deployment = await myDeploymentFormat(result, value);
handleDeployment(_deployment.key, JSON.stringify(_deployment.data));

// set deployment to localStorage object using Atom
const _deployment = await myDeploymentFormat(result, value);
handleDeployment(_deployment.key, JSON.stringify(_deployment.data));
// set deployment to localStorage item by dseq (deprecate ?)
localStorage.setItem(_deployment.key, JSON.stringify(_deployment.data));

// set deployment to localStorage item by dseq (deprecate ?)
localStorage.setItem(_deployment.key, JSON.stringify(_deployment.data));

// head to the bid selection page
navigate(`/configure-deployment/${result.deploymentId.dseq}`);
}
},
// head to the bid selection page
navigate(`/configure-deployment/${result.deploymentId.dseq}`);
}
);
} catch (error) {
await handleError(error, 'createDeployment');
}
})
.catch((error) => handleError(error, 'createDeployment'));
}}
>
{({ setFieldValue, values }) => {
Expand Down Expand Up @@ -256,48 +248,48 @@ const DeploymentStepper: React.FC<DeploymentStepperProps> = () => {
{activeStep.currentCard === steps.length
? null
: !progressVisible && (
<React.Fragment>
{activeStep.currentCard === 0 && (
<FeaturedApps
onDeployNowClick={(folderName) => {
selectFolder(folderName);
}}
callback={(sdl) =>
navigate('/new-deployment/custom-sdl', { state: { sdl: sdl } })
}
setFieldValue={setFieldValue}
onSave={function (sdl: any): void {
throw new Error('Function not implemented.');
}}
/>
)}
{activeStep.currentCard === 1 && folderName && (
<SelectApp
folderName={uriToName(folderName)}
setFieldValue={setFieldValue}
onNextButtonClick={selectTemplate}
/>
)}
{activeStep.currentCard === 2 && folderName && templateId && (
<ConfigureApp
folderName={uriToName(folderName)}
templateId={uriToName(templateId)}
onNextButtonClick={(intent: string) =>
handlePreflightCheck(intent, values.sdl)
}
<React.Fragment>
{activeStep.currentCard === 0 && (
<FeaturedApps
onDeployNowClick={(folderName) => {
selectFolder(folderName);
}}
callback={(sdl) =>
navigate('/new-deployment/custom-sdl', { state: { sdl: sdl } })
}
setFieldValue={setFieldValue}
onSave={function (sdl: any): void {
throw new Error('Function not implemented.');
}}
/>
)}
{activeStep.currentCard === 1 && folderName && (
<SelectApp
folderName={uriToName(folderName)}
setFieldValue={setFieldValue}
onNextButtonClick={selectTemplate}
/>
)}
{activeStep.currentCard === 2 && folderName && templateId && (
<ConfigureApp
folderName={uriToName(folderName)}
templateId={uriToName(templateId)}
onNextButtonClick={(intent: string) =>
handlePreflightCheck(intent, values.sdl)
}
/>
)}
{activeStep.currentCard === 3 && <PreflightCheck />}
{activeStep.currentCard === 4 && deploymentId && (
<Suspense fallback={<Loading />}>
<SelectProvider
deploymentId={deploymentId}
onNextButtonClick={(bidId: any) => acceptBid(bidId)}
/>
)}
{activeStep.currentCard === 3 && <PreflightCheck />}
{activeStep.currentCard === 4 && deploymentId && (
<Suspense fallback={<Loading />}>
<SelectProvider
deploymentId={deploymentId}
onNextButtonClick={(bidId: any) => acceptBid(bidId)}
/>
</Suspense>
)}
</React.Fragment>
)}
</Suspense>
)}
</React.Fragment>
)}
</>
);
}}
Expand All @@ -308,7 +300,7 @@ const DeploymentStepper: React.FC<DeploymentStepperProps> = () => {
title={errorTitle || ''}
message={errorMessage || ''}
/>
</Box>
</Box >
);
};

Expand Down
2 changes: 1 addition & 1 deletion web/src/components/SdlConfiguration/HttpOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const HttpOptions: React.FC<EnvironmentVariableProps> = ({
<SdlSectionWrapper>
<Stack gap="10px" direction={'column'}>
{httpOptions.map(([key, label, description, defaultValue]) => (
<Grid container key={key} xs={12}>
<Grid container key={key}>
{/* label */}
<Grid item xs={6}>
<label htmlFor={key}>{label}</label>
Expand Down
3 changes: 2 additions & 1 deletion web/src/components/SdlConfiguration/Storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
PlusSign,
TableTitle,
} from './styling';
import { randomInt } from 'crypto';

interface TabPanelProps {
children?: React.ReactNode;
Expand Down Expand Up @@ -378,4 +379,4 @@ const StorageType = styled.p`
font-size: 14px;
line-height: 20px;
color: #6b7280;
`;
`;
Loading

0 comments on commit 718f1aa

Please sign in to comment.