Skip to content

Commit

Permalink
service ui
Browse files Browse the repository at this point in the history
  • Loading branch information
mujahidkay committed Sep 5, 2024
1 parent d8ac30e commit 6a6b2cc
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 91 deletions.
2 changes: 1 addition & 1 deletion contract/src/offer-up-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const startOfferUpContract = async permittedPowers => {
const istBrand = await istBrandP;

const terms = {
subscriptionPrice: AmountMath.make(istBrand, 500n),
subscriptionPrice: AmountMath.make(istBrand, 10000000n),
};

// agoricNames gets updated each time; the promise space only once XXXXXXX
Expand Down
12 changes: 6 additions & 6 deletions contract/test/test-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('Start the contract', async t => {

const money = makeIssuerKit('PlayMoney');
const issuers = { Price: money.issuer };
const terms = { subscriptionPrice: AmountMath.make(money.brand, 500n) };
const terms = { subscriptionPrice: AmountMath.make(money.brand, 10000000n) };
t.log('terms:', terms);

/** @type {ERef<Installation<AssetContractFn>>} */
Expand Down Expand Up @@ -120,15 +120,15 @@ test('Alice trades: give some play money, want subscription', async t => {

const money = makeIssuerKit('PlayMoney');
const issuers = { Price: money.issuer };
const terms = { subscriptionPrice: AmountMath.make(money.brand, 500n) };
const terms = { subscriptionPrice: AmountMath.make(money.brand, 10000000n) };
/** @type {ERef<Installation<AssetContractFn>>} */
const installation = E(zoe).install(bundle);
const { instance } = await E(zoe).startInstance(installation, issuers, terms);
t.log(instance);
t.is(typeof instance, 'object');

const alicePurse = money.issuer.makeEmptyPurse();
const amountOfMoney = AmountMath.make(money.brand, 500n);
const amountOfMoney = AmountMath.make(money.brand, 10000000n);
const moneyPayment = money.mint.mintPayment(amountOfMoney);
alicePurse.deposit(moneyPayment);
await alice(t, zoe, instance, alicePurse);
Expand All @@ -146,7 +146,7 @@ test('Trade in IST rather than play money', async t => {
const installation = E(zoe).install(bundle);
const feeIssuer = await E(zoe).getFeeIssuer();
const feeBrand = await E(feeIssuer).getBrand();
const subscriptionPrice = AmountMath.make(feeBrand, 500n);
const subscriptionPrice = AmountMath.make(feeBrand, 10000000n);
return E(zoe).startInstance(
installation,
{ Price: feeIssuer },
Expand All @@ -157,7 +157,7 @@ test('Trade in IST rather than play money', async t => {
const { zoe, bundle, bundleCache, feeMintAccess } = t.context;
const { instance } = await startContract({ zoe, bundle });
const { faucet } = makeStableFaucet({ bundleCache, feeMintAccess, zoe });
await alice(t, zoe, instance, await faucet(5n * UNIT6));
await alice(t, zoe, instance, await faucet(10n * UNIT6));
});

test('use the code that will go on chain to start the contract', async t => {
Expand Down Expand Up @@ -231,5 +231,5 @@ test('use the code that will go on chain to start the contract', async t => {
// Now that we have the instance, resume testing as above.
const { feeMintAccess, bundleCache } = t.context;
const { faucet } = makeStableFaucet({ bundleCache, feeMintAccess, zoe });
await alice(t, zoe, instance, await faucet(5n * UNIT6));
await alice(t, zoe, instance, await faucet(10n * UNIT6));
});
4 changes: 0 additions & 4 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
"vitest": "^1.2.1",
"zustand": "^4.4.1"
},
"resolutions": {
"**/ses": "^1.3.0",
"**/@agoric/xsnap": "0.14.3-dev-9f085d3.0"
},
"prettier": {
"trailingComma": "all",
"arrowParens": "avoid",
Expand Down
12 changes: 8 additions & 4 deletions ui/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
.selected {
outline: 2px solid #007bff;
}

.card {
padding: 1em;
}


.read-the-docs {
color: #888;
}
Expand All @@ -54,6 +53,11 @@
margin: 10px;
}

.service {
height: 48px;
width: 48px;
}

.trade {
display: flex;
flex-direction: column;
Expand Down
27 changes: 19 additions & 8 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import { subscribeLatest } from '@agoric/notifier';
import { makeCopyBag } from '@agoric/store';
import { Logos } from './components/Logos';
import { Inventory } from './components/Inventory';
import { Trade } from './components/Trade';
import { Subscribe } from './components/Trade';

import { AmountMath } from '@agoric/ertp';

const { entries, fromEntries } = Object;

Expand Down Expand Up @@ -86,15 +88,21 @@ const connectWallet = async () => {
}
};

const makeOffer = (giveValue: bigint, wantChoices: Record<string, bigint>) => {
const makeOffer = (giveValue: bigint, wantChoice: string) => {
const { wallet, offerUpInstance, brands } = useAppStore.getState();
if (!offerUpInstance) throw Error('no contract instance');
if (!(brands && brands.IST && brands.Item))
throw Error('brands not available');

const value = makeCopyBag(entries(wantChoices));
const want = { Items: { brand: brands.Item, value } };
const give = { Price: { brand: brands.IST, value: giveValue } };
const choiceBag = makeCopyBag([
[{ expiryTime: '123', serviceType: wantChoice }, 1n],
]);

// want: { Items: AmountMath.make(brands.Item, choiceBag) }

// const value = makeCopyBag(entries(wantChoices));
const want = { Items: AmountMath.make(brands.Item, choiceBag) };
const give = { Price: AmountMath.make(brands.IST, 10000000n) };

wallet?.makeOffer(
{
Expand All @@ -103,7 +111,10 @@ const makeOffer = (giveValue: bigint, wantChoices: Record<string, bigint>) => {
publicInvitationMaker: 'makeTradeInvitation',
},
{ give, want },
undefined,
{
userAddress: wallet.address,
serviceType: wantChoice,
},
(update: { status: string; data?: unknown }) => {
if (update.status === 'error') {
alert(`Offer error: ${update.data}`);
Expand Down Expand Up @@ -145,10 +156,10 @@ function App() {
return (
<>
<Logos />
<h1>Items Listed on Offer Up</h1>
<h1>All-in-One Subscription Service</h1>

<div className="card">
<Trade
<Subscribe
makeOffer={makeOffer}
istPurse={istPurse as Purse}
walletConnected={!!wallet}
Expand Down
51 changes: 51 additions & 0 deletions ui/src/assets/amazon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/src/assets/disney.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/src/assets/hbomax.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions ui/src/assets/netflix.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ui/src/components/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Inventory = ({ address, istPurse, itemsPurse }: InventoryProps) => (
istPurse.displayInfo.decimalPlaces,
)}
</div>
<div>
{/* <div>
<b>Items:</b>
{itemsPurse ? (
<ul style={{ marginTop: 0, textAlign: 'left' }}>
Expand All @@ -40,7 +40,7 @@ const Inventory = ({ address, istPurse, itemsPurse }: InventoryProps) => (
) : (
'None'
)}
</div>
</div> */}
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit 6a6b2cc

Please sign in to comment.