Skip to content

Commit

Permalink
chore: add alerts in App.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
amessbee committed Jan 10, 2025
1 parent f551a3e commit 716ae4e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const setup = async () => {
};

const connectWallet = async () => {
try {
await fetch(ENDPOINTS.RPC);
} catch (error) {
throw new Error('Chain is not running. Please start the chain first!');
}
await suggestChain('https://local.agoric.net/network-config');
const wallet = await makeAgoricWalletConnection(watcher, ENDPOINTS.RPC);
useAppStore.setState({ wallet });
Expand All @@ -88,9 +93,14 @@ const connectWallet = async () => {

const makeOffer = (giveValue: bigint, wantChoices: Record<string, bigint>) => {
const { wallet, offerUpInstance, brands } = useAppStore.getState();
if (!offerUpInstance) throw Error('no contract instance');
if (!(brands && brands.IST && brands.Item))
if (!offerUpInstance) {
alert('No contract instance found on the chain RPC: ' + ENDPOINTS.RPC);
throw Error('no contract instance');
}
if (!(brands && brands.IST && brands.Item)) {
alert('Brands not available');
throw Error('brands not available');
}

const value = makeCopyBag(entries(wantChoices));
const want = { Items: { brand: brands.Item, value } };
Expand Down

0 comments on commit 716ae4e

Please sign in to comment.