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

Orchestration-basics v1 release #10

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Binary file added images/ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,31 @@
"private": true,
"version": "0.0.0",
"type": "module",
"packageManager": "yarn@4.3.1",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build": "tsc && NODE_OPTIONS=--max-old-space-size=4096 vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "yarn lint --fix",
"preview": "vite preview",
"test": "exit 0",
"test:e2e": "exit 0"
},
"dependencies": {
"@agoric/react-components": "0.1.1-dev-8fc28e8.0",
"@agoric/react-components": "^0.1.1-dev-ca0ddde.0",
"@agoric/ui-components": "^0.3.9-u13.0",
"@agoric/web-components": "0.15.1-dev-8fc28e8.0",
"buffer": "^6.0.3",
"chain-registry": "^1.28.1",
"cosmos-kit": "^2.9.0",
"daisyui": "^4.7.2",
"react": "^18.2.0",
"daisyui": "^4.12.10",
"react": "^18.3.1",
"react-daisyui": "^5.0.0",
"react-dom": "^18.2.0",
"ses": "^1.2.0"
},
"devDependencies": {
"@interchain-ui/react": "^1.23.24",
"@types/react": "^18.2.56",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.0.2",
Expand All @@ -51,4 +53,4 @@
"prettier-plugin-tailwindcss"
]
}
}
}
52 changes: 34 additions & 18 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,45 @@ import { AgoricProvider } from '@agoric/react-components';
import { Navbar } from './components/Navbar';
import { Tabs } from './components/Tabs';
import { wallets } from 'cosmos-kit';
import { ThemeProvider, useTheme } from '@interchain-ui/react';
import '@agoric/react-components/dist/style.css';
// import { Button, Modal } from 'react-daisyui';



function App() {
const { themeClass } = useTheme();

return (
<AgoricProvider
wallets={wallets.extension}
defaultNetworkConfig={{
testChain: {
chainId: 'agoriclocal',
chainName: 'agoric-local',
},
apis: {
rest: ['http://localhost:1317'],
rpc: ['http://localhost:26657'],
},
}}
>
<ContractProvider>
<Navbar />
<Tabs />
</ContractProvider>
</AgoricProvider>
<ThemeProvider>
<div className={themeClass}>
<AgoricProvider
wallets={wallets.extension}
agoricNetworkConfigs={[
{
testChain: {
chainId: 'agoriclocal',
chainName: 'agoric-local',
iconUrl: 'agoric.svg', // Optional icon for dropdown display
},
apis: {
rest: ['http://localhost:1317'],
rpc: ['http://localhost:26657'],
},
},
]}
defaultChainName="agoric-local"
>
<ContractProvider>
<Navbar />
<Tabs />

</ContractProvider>
</AgoricProvider>
</div>
</ThemeProvider>
);
}


export default App;
27 changes: 4 additions & 23 deletions ui/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { ConnectWalletButton } from '@agoric/react-components';
import { NetworkDropdown } from '@agoric/react-components';
import { ThemeProvider, useTheme } from '@interchain-ui/react';

const localnet = {
testChain: {
chainId: 'agoriclocal',
chainName: 'agoric-local',
},
apis: {
rest: ['http://localhost:1317'],
rpc: ['http://localhost:26657'],
iconUrl: '/agoriclocal.svg', // Optional icon for dropdown display
},
};

const Navbar = () => {
const { themeClass } = useTheme();

return (
<div className="daisyui-navbar bg-neutral text-neutral-content">
{/* Agoric logo */}
Expand All @@ -28,17 +13,13 @@ const Navbar = () => {
{/* dApp title */}
<div className="flex-1">
<button className="daisyui-btn daisyui-btn-ghost text-xl">
dApp Agoric Dao
Agoric Orchestration Basics
</button>
</div>
{/* network selector */}
<ThemeProvider>
<div className={themeClass}>
<div>
<NetworkDropdown networkConfigs={[localnet]} />
</div>
</div>
</ThemeProvider>
<div className="mx-2">
<NetworkDropdown />
</div>
{/* connect wallet button */}
<div className="flex-none">
<ConnectWalletButton className="daisyui-btn daisyui-btn-outline daisyui-btn-secondary" />
Expand Down
50 changes: 50 additions & 0 deletions ui/src/components/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Toast, Alert, Button } from 'react-daisyui';
import { DynamicToastChild } from './Tabs';
import { Dispatch, SetStateAction } from 'react';

const daisyUiAlertClass = (status: string) => {
switch (status) {
case 'info':
return 'daisyui-alert-info';
case 'success':
return 'daisyui-alert-success';
case 'warning':
return 'daisyui-alert-warning';
case 'error':
return 'daisyui-alert-error';
default:
return '';
Comment on lines +15 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like a silent failure. is that by design?

}
};

const Notifications = (props: {
notifications: DynamicToastChild[];
setNotifications: Dispatch<SetStateAction<DynamicToastChild[]>>;
}) => {
const handleRemoveToast = (index: number) => {
props.setNotifications(notifications =>
notifications.filter((_, i) => i !== index),
);
};

return (
<Toast className="daisyui-toast daisyui-toast-end daisyui-toast-top mt-14">
{props.notifications.map((alert, index) => (
<Alert
className={'daisyui-alert ' + daisyUiAlertClass(alert.status)}
key={index}
status={alert.status}
>
<div className="w-full flex-row justify-between gap-2">
<h3>{alert.text}</h3>
</div>
<Button color="ghost" onClick={() => handleRemoveToast(index)}>
X
</Button>
</Alert>
))}
</Toast>
);
};

export { Notifications };
59 changes: 59 additions & 0 deletions ui/src/components/Orchestration/AccountList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const tokenLogos = {
ubld: 'https://assets.coingecko.com/coins/images/24487/large/agoric_bld_logo.png?1696523668',
uist: 'https://inter.trade/static/inter-protocol-logo-symbol-color-64318316bdb96c351674e3157a9f7546.png',
ibc: 'https://cdn-icons-png.flaticon.com/512/566/566295.png',
default: 'https://cdn-icons-png.flaticon.com/512/566/566295.png',
};

const AccountList = ({ balances, loadingDeposit, handleDeposit, loadingWithdraw, handleWithdraw, loadingStake, handleStake, loadingUnstake, handleUnstake, guidelines }) => {
return (
<div className={`w-2/3 space-y-10 pr-4 rounded-lg p-4 border${guidelines ? "" : "-0"}`}>
<h1 className="daisyui-card-title">Accounts</h1>
{balances.map((balance, idx) => (
<div key={idx} className={`card bg-base-100 shadow-md p-4 rounded-lg border${guidelines ? "" : "-0"}`}>
<div className="stats shadow">
<div className="stat">
<div className="stat-title">Address</div>
<div className="stat-value text-primary">{balance.address.slice(0, 10)}...{balance.address.slice(-10)}</div>
</div>

<div className="flex flex-wrap">
{balance.balances.map((bal, idx) => (
<div key={idx} className={`stat p-2 border${guidelines ? "" : "-0"}`} style={{ minWidth: '150px', maxWidth: '200px' }}>
<div className="stat-figure text-secondary">
<div className="avatar online">
<div className="w-8 rounded-full">
<img src={tokenLogos[bal.denom] || tokenLogos.default} alt={`${bal.denom} logo`} />
</div>
</div>
</div>
<div className="stat-title truncate">{bal.denom.toUpperCase()}</div>
<div className="stat-value text-secondary">{bal.amount}</div>
</div>
))}
</div>
</div>

<div className={`flex flex-col space-y-1 mt-2 border${guidelines ? "" : "-0"}`}>
<div className="inline-flex rounded-md shadow-sm" role="group">
<button className={`inline-flex items-center px-4 py-2 text-sm font-medium text-white ${loadingDeposit[balance.address] ? 'bg-gray-600' : 'bg-gray-800'} border border-gray-700 rounded-l-full hover:bg-gray-700 hover:text-blue-500`} onClick={() => handleDeposit(balance.address)} disabled={loadingDeposit[balance.address]}>
Deposit
</button>
<button className={`inline-flex items-center px-4 py-2 text-sm font-medium text-white ${loadingWithdraw[balance.address] ? 'bg-gray-600' : 'bg-gray-800'} border-t border-b border-gray-700 hover:bg-gray-700 hover:text-blue-500`} onClick={() => handleWithdraw(balance.address)} disabled={loadingWithdraw[balance.address]}>
Withdraw
</button>
<button className={`inline-flex items-center px-4 py-2 text-sm font-medium text-white ${loadingStake[balance.address] ? 'bg-gray-600' : 'bg-gray-800'} border-t border-b border-gray-700 hover:bg-gray-700 hover:text-blue-500`} onClick={() => handleStake(balance.address)} disabled={loadingStake[balance.address]}>
Stake
</button>
<button className={`inline-flex items-center px-4 py-2 text-sm font-medium text-white ${loadingUnstake[balance.address] ? 'bg-gray-600' : 'bg-gray-800'} border border-gray-700 rounded-r-full hover:bg-gray-700 hover:text-blue-500`} onClick={() => handleUnstake(balance.address)} disabled={loadingUnstake[balance.address]}>
Unstake
</button>
</div>
</div>
</div>
))}
</div>
);
};

export default AccountList;
14 changes: 14 additions & 0 deletions ui/src/components/Orchestration/ChainSelector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';

const ChainSelector = ({ setSelectedChain }) => (
<select
className="select select-bordered mb-4 rounded-lg border-0 w-full max-w-xs text-lg"
onChange={(e) => setSelectedChain(e.target.value)}
>
<option disabled selected>Select Remote Chain</option>
<option value="osmosis">Osmosis</option>
<option value="agoric">Agoric</option>
</select>
);

export default ChainSelector;
18 changes: 18 additions & 0 deletions ui/src/components/Orchestration/CreateAccountButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

const CreateAccountButton = ({ handleCreateAccount, loadingCreateAccount }) => (
<button
className={`daisyui-btn daisyui-btn-info mt-4 w-full self-center text-sm ${loadingCreateAccount ? 'bg-gray-600' : 'bg-blue-500'}`}
onClick={handleCreateAccount}
disabled={loadingCreateAccount}
>
{loadingCreateAccount ? (
<svg aria-hidden="true" role="status" className="inline w-4 h-4 me-3 text-gray-200 animate-spin dark:text-gray-600" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where do these path numbers come from? how do we maintain this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a raw svg path for a common spinner. I was going to sub it out for a lib component, prob from daisy since its a dep

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's often OK to copy from an open source package, but we need to acknowledge the source. And we need to check that the license isn't copyleft; it has to be compatible with ours (Apache 2).

<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="#1C64F2"/>
</svg>
) : 'Create Account'}
</button>
);

export default CreateAccountButton;
49 changes: 49 additions & 0 deletions ui/src/components/Orchestration/FetchBalances.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { StargateClient } from "@cosmjs/stargate";

const rpcEndpoints = {
osmosis: 'http://127.0.0.1:26655',
agoric: 'http://127.0.0.1:26657',
};

export const fetchBalances = async (addresses) => {
return Promise.all(
addresses.map(async (address) => {
console.log("address", address)
let chain = '';
if (address.startsWith('osmo1')) {
chain = 'osmosis';
} else if (address.startsWith('agoric1')) {
chain = 'agoric';
} else {
return {
address,
balances: []
};
}

const rpcEndpoint = rpcEndpoints[chain];
try {
const balance = await fetchBalanceFromRpc(address, rpcEndpoint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this trigger a "used before defined" eslint error?

return {
address,
balances: balance
};
} catch (e) {
console.log("e:", e)
return {
address,
balances: []
}
}
})
);
};

const fetchBalanceFromRpc = async (address, rpcEndpoint) => {
const client = await StargateClient.connect(rpcEndpoint);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope we can avoid this sort of ambient authority.

see:

const balances = await client.getAllBalances(address);
return balances.map(coin => ({
denom: coin.denom,
amount: coin.amount
}));
};
44 changes: 44 additions & 0 deletions ui/src/components/Orchestration/KeplrInitializer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export const initializeKeplr = async () => {
await window.keplr.experimentalSuggestChain({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about passing in window.keplr explicitly rather than using ambient authority?

modules should not export powerful objects (for example, objects that close over fs or process.env)
-- OCap Discipline

window and window.keplr are in the same class as fs and process and process.env.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another possibility is to export the data and call window.keplr.experimentalSuggestChain elsewhere.

chainId: "osmosislocal",
chainName: "Osmosis Local",
rpc: "http://127.0.0.1:26655",
rest: "http://127.0.0.1:1315",
bip44: {
coinType: 118,
},
bech32Config: {
bech32PrefixAccAddr: "osmo",
bech32PrefixAccPub: "osmopub",
bech32PrefixValAddr: "osmovaloper",
bech32PrefixValPub: "osmovaloperpub",
bech32PrefixConsAddr: "osmovalcons",
bech32PrefixConsPub: "osmovalconspub",
},
currencies: [
{
coinDenom: "OSMO",
coinMinimalDenom: "uosmo",
coinDecimals: 6,
},
],
feeCurrencies: [
{
coinDenom: "OSMO",
coinMinimalDenom: "uosmo",
coinDecimals: 6,
},
],
stakeCurrency: {
coinDenom: "OSMO",
coinMinimalDenom: "uosmo",
coinDecimals: 6,
},
coinType: 118,
gasPriceStep: {
low: 0.01,
average: 0.025,
high: 0.04,
},
});
};
Loading