-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 1 commit
1d1f248
8348651
46d25a0
ae2c772
56ffa02
6900063
e57f79c
65c6f11
ea55e9c
096aee7
47e9ec8
28dabc2
d43ebe6
6ace05f
753f4e7
6694e67
31fe985
520485d
0d5c05e
72c6416
919cf28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 ''; | ||
} | ||
}; | ||
|
||
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 }; |
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; |
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; |
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"/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where do these path numbers come from? how do we maintain this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
const balances = await client.getAllBalances(address); | ||
return balances.map(coin => ({ | ||
denom: coin.denom, | ||
amount: coin.amount | ||
})); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export const initializeKeplr = async () => { | ||
await window.keplr.experimentalSuggestChain({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about passing in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another possibility is to export the data and call |
||
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, | ||
}, | ||
}); | ||
}; |
There was a problem hiding this comment.
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?