Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for sandbox #149

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions web/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ rules:
semi:
- error
- always
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"
}
}
13 changes: 0 additions & 13 deletions web/src/_helpers/async-for-each.ts

This file was deleted.

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.
49 changes: 20 additions & 29 deletions web/src/api/rpc/beta2/deployments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ import { fetchRpcNodeStatus } from './rpc';
import { LeaseStatus } from '../../../types';
import logging from '../../../logging';
import { getRpcNode } from '../../../hooks/useRpcNode';
import { retry } from '../../../_helpers/async-utils';

// 5AKT aka 5000000uakt
export const defaultInitialDeposit = 5000000;

function getTypeUrl<T extends {$type: string}>(type: T) {
function getTypeUrl<T extends { $type: string }>(type: T) {
return `/${type.$type}`;
}

Expand Down Expand Up @@ -399,41 +400,31 @@ export async function sendManifest(address: string, lease: Lease, sdl: any) {
const providerFetch = mtlsFetch(cert, provider.provider.hostUri);
const manifest = Manifest(sdl, 'beta2', true);

console.log(manifest);

let jsonStr = JSON.stringify(manifest);

jsonStr = jsonStr.replaceAll('"quantity":{"val', '"size":{"val');
jsonStr = jsonStr.replaceAll('"mount":', '"readOnlyTmp":');
jsonStr = jsonStr.replaceAll('"readOnly":', '"mount":');
jsonStr = jsonStr.replaceAll('"readOnlyTmp":', '"readOnly":');

return new Promise((resolve, reject) => {
const attemptSend = (retry: number) => {
return providerFetch(url, {
method: 'PUT',
body: jsonStr,
}).then((result) => {
if (result.ok) {
resolve(result);
return;
}

if (retry > 0) {
// logging.warn('Sending manifest failed. Retrying...');
setTimeout(() => attemptSend(retry - 1), 1000);
} else {
// logging.warn('Sending manifest failed.');
result.text().then(reject);
}
}, (error) => {
logging.error('Error sending manifest to provider. This is likey an issue with the provider.');
console.error(error);
});
};

attemptSend(3);
});
const attemptSend = () => {
return providerFetch(url, {
method: 'PUT',
body: jsonStr,
}).then((result) => {
if (result.ok) {
return result;
}

return Promise.reject(result);
});
};

return retry(attemptSend, [1000, 3000, 5000])
.catch((error) => {
logging.error('Error sending manifest to provider. This is likely an issue with the provider.');
console.error(error);
});
}

export async function newDeploymentData(
Expand Down
46 changes: 22 additions & 24 deletions web/src/api/rpc/beta3/deployments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ import { fetchRpcNodeStatus } from './rpc';
import { LeaseStatus } from '../../../types';
import logging from '../../../logging';
import { getRpcNode } from '../../../hooks/useRpcNode';
import { retry } from '../../../_helpers/async-utils';

// 5AKT aka 5000000uakt
export const defaultInitialDeposit = 5000000;

function getTypeUrl<T extends {$type: string}>(type: T) {
function getTypeUrl<T extends { $type: string }>(type: T) {
return `/${type.$type}`;
}

Expand Down Expand Up @@ -314,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 Expand Up @@ -400,29 +403,24 @@ export async function sendManifest(address: string, lease: Lease, sdl: any) {
const providerFetch = mtlsFetch(cert, provider.provider.hostUri);
const jsonStr = ManifestYaml(sdl, 'beta3');

return new Promise((resolve, reject) => {
const attemptSend = (retry: number) => {
return providerFetch(url, {
method: 'PUT',
body: jsonStr,
}).then((result) => {
if (result.ok) {
resolve(result);
return;
}

if (retry > 0) {
// logging.warn('Sending manifest failed. Retrying...');
setTimeout(() => attemptSend(retry - 1), 1000);
} else {
// logging.warn('Sending manifest failed.');
result.text().then(reject);
}
});
};

attemptSend(3);
});
const attemptSend = () => {
return providerFetch(url, {
method: 'PUT',
body: jsonStr,
}).then((result) => {
if (result.ok) {
return result;
}

return Promise.reject(result);
});
};

return retry(attemptSend, [1000, 3000, 5000])
.catch((error: any) => {
logging.error('Error sending manifest to provider. This is likely an issue with the provider.');
console.error(error);
});
}

export async function newDeploymentData(
Expand Down
35 changes: 19 additions & 16 deletions web/src/components/Deployment/DeploymentActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@ import React from 'react';
import { Button, Stack, Link, Tooltip, ButtonProps } from '@mui/material';

type DeploymentActionButtonProps = {
tooltipTitle: string;
tooltip: React.ReactNode;
linkTo: string;
children: React.ReactNode;
tooltipTitle: string;
tooltip: React.ReactNode;
linkTo: string;
condition: boolean;
children: React.ReactNode;
} & ButtonProps;

const ConditionalTooltip = ({ children, condition, ...rest}: any) => {
return condition
? <Link {...rest}>{children}</Link>
: <Tooltip {...rest} placement="top">{children}</Tooltip>;
const ConditionalTooltip = ({ children, condition, ...rest }: any) => {
return condition
? <Link {...rest}>{children}</Link>
: <Tooltip {...rest} placement="top">{children}</Tooltip>;
};


const DeploymentActionButton: React.FC<DeploymentActionButtonProps> = (props) => {
const {
tooltipTitle,
tooltip,
linkTo,
children,
...rest
} = props;
const {
tooltipTitle,
tooltip,
linkTo,
children,
condition,
...rest
} = props;

return <Stack direction="row" spacing={1} marginBottom="0.75rem" alignItems="center">
return <Stack direction="row" spacing={1} alignItems="center">
<ConditionalTooltip
title={tooltipTitle}
to={linkTo}
className="grow"
condition={condition}
>
<Button
fullWidth
Expand Down
Loading
Loading