Skip to content

Commit

Permalink
Merge pull request #3737 from Agoric/mfig-3735-display-wallet-fees
Browse files Browse the repository at this point in the history
Display wallet fees
  • Loading branch information
michaelfig authored Aug 21, 2021
2 parents 5ece888 + 8aec514 commit cf569cc
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 14 deletions.
38 changes: 35 additions & 3 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ export function makeWallet({
/** @type {WeakStore<Issuer, string>} */
const issuerToBoardId = makeScalarWeakMap('issuer');

/** @type {Petname} */
let feePursePetname;

// Idempotently initialize the issuer's synchronous boardId mapping.
const initIssuerToBoardId = async issuer => {
if (issuerToBoardId.has(issuer)) {
Expand Down Expand Up @@ -331,6 +334,23 @@ export function makeWallet({

const display = value => fillInSlots(dehydrate(harden(value)));

const expandInvitationBrands = async invitationDetails => {
// We currently only add the fee's brand.
const { fee } = invitationDetails;
if (!fee) {
return invitationDetails;
}

// Add display info for the fee.
const displayInfo = await E(E(zoe).getFeeIssuer()).getDisplayInfo();
const augmentedDetails = {
...invitationDetails,
feePursePetname,
fee: { ...fee, displayInfo },
};
return display(augmentedDetails);
};

const displayProposal = proposalTemplate => {
const { want, give, exit = { onDemand: null } } = proposalTemplate;
const displayRecord = pursePetnameValueKeywordRecord => {
Expand Down Expand Up @@ -391,6 +411,10 @@ export function makeWallet({
const alreadyDisplayed =
inboxState.has(id) && inboxState.get(id).proposalForDisplay;

const augmentedInvitationDetails = await expandInvitationBrands(
invitationDetails,
);

const offerForDisplay = {
...offer,
// We cannot store the actions, installation, and instance in the
Expand All @@ -400,7 +424,7 @@ export function makeWallet({
installation: undefined,
instance: undefined,
proposalTemplate,
invitationDetails: display(invitationDetails),
invitationDetails: display(augmentedInvitationDetails),
instancePetname: instanceDisplay.petname,
installationPetname: installationDisplay.petname,
proposalForDisplay: displayProposal(alreadyDisplayed || proposalTemplate),
Expand Down Expand Up @@ -731,6 +755,8 @@ export function makeWallet({
console.error(`failed updateState observer`, reason);
},
});

return petnameForPurse;
};

// This function is exposed to the walletAdmin.
Expand Down Expand Up @@ -964,7 +990,7 @@ export function makeWallet({

// Our inbox state may have an enriched offer.
await updateInboxState(id, idToOffer.get(id));
const { installation, instance } = await compiledOfferP;
const { installation, instance, invitationDetails } = await compiledOfferP;

if (!idToOffer.has(id)) {
return rawId;
Expand All @@ -975,6 +1001,7 @@ export function makeWallet({
...idToOffer.get(id),
installation,
instance,
invitationDetails,
}),
);
await updateInboxState(id, idToOffer.get(id));
Expand Down Expand Up @@ -1652,7 +1679,12 @@ export function makeWallet({
const feePurse = await feePurseP;
const feeIssuer = await E(zoe).getFeeIssuer();
const issuerName = await addIssuer('RUN', feeIssuer);
await internalUnsafeImportPurse(issuerName, 'Zoe fees', false, feePurse);
feePursePetname = await internalUnsafeImportPurse(
issuerName,
'Zoe fees',
false,
feePurse,
);
};
return { admin: wallet, initialized: initialize(), importBankAssets };
}
69 changes: 69 additions & 0 deletions packages/dapp-svelte-wallet/api/test/test-lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,21 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t
{
id: 'unknown#1588645041696',
rawId: '1588645041696',
invitationDetails: {
description: 'getRefund',
handle: {
kind: 'unnamed',
petname: 'unnamed-1',
},
installation: {
kind: 'installation',
petname: 'automaticRefund',
},
instance: {
kind: 'instance',
petname: 'automaticRefund',
},
},
inviteHandleBoardId: '727995140',
proposalTemplate: {},
requestContext: { dappOrigin: 'unknown' },
Expand Down Expand Up @@ -594,6 +609,21 @@ test('lib-wallet dapp suggests issuer, instance, installation petnames', async t
{
id: 'unknown#1588645041696',
rawId: '1588645041696',
invitationDetails: {
description: 'getRefund',
handle: {
kind: 'unnamed',
petname: 'unnamed-1',
},
installation: {
kind: 'installation',
petname: 'automaticRefund2',
},
instance: {
kind: 'instance',
petname: 'automaticRefund',
},
},
inviteHandleBoardId: '727995140',
proposalTemplate: {},
requestContext: { dappOrigin: 'unknown' },
Expand Down Expand Up @@ -668,6 +698,15 @@ test('lib-wallet offer methods', async t => {
{
id: 'unknown#1588645041696',
rawId: '1588645041696',
invitationDetails: {
description: 'getRefund',
expiry: undefined,
fee: undefined,
handle: inviteHandle,
installation,
instance,
zoeTimeAuthority: undefined,
},
inviteHandleBoardId: '727995140',
instance,
installation,
Expand Down Expand Up @@ -769,6 +808,21 @@ test('lib-wallet offer methods', async t => {
{
id: 'unknown#1588645041696',
rawId: '1588645041696',
invitationDetails: {
description: 'getRefund',
handle: {
kind: 'unnamed',
petname: 'unnamed-1',
},
installation: {
kind: 'unnamed',
petname: 'unnamed-2',
},
instance: {
kind: 'unnamed',
petname: 'unnamed-3',
},
},
inviteHandleBoardId: '727995140',
proposalTemplate: {
give: { Contribution: { pursePetname: 'Fun budget', value: 1 } },
Expand Down Expand Up @@ -801,6 +855,21 @@ test('lib-wallet offer methods', async t => {
{
id: 'unknown#1588645230204',
rawId: '1588645230204',
invitationDetails: {
description: 'getRefund',
handle: {
kind: 'unnamed',
petname: 'unnamed-6',
},
installation: {
kind: 'unnamed',
petname: 'unnamed-2',
},
instance: {
kind: 'unnamed',
petname: 'unnamed-3',
},
},
inviteHandleBoardId: '371571443',
proposalTemplate: {
give: { Contribution: { pursePetname: 'Fun budget', value: 1 } },
Expand Down
3 changes: 1 addition & 2 deletions packages/dapp-svelte-wallet/ui/src/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@
instancePetname,
instanceHandleBoardId,
installationHandleBoardId,
feePursePetname,
offerId,
requestContext: { date, dappOrigin, origin = "unknown origin" } = {},
invitationDetails: { fee, expiry } = {},
invitationDetails: { fee, feePursePetname, expiry } = {},
proposalForDisplay: { give = {}, want = {} } = {},
} = item);
Expand Down
2 changes: 1 addition & 1 deletion packages/deployment/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ show-config display the client connection parameters
if (subOpts.genesis) {
// Fetch the specified genesis, don't generate it.
const loc = new URL(subOpts.genesis, `file://${cwd()}`);
if (loc.protocol === 'file') {
if (loc.protocol === 'file:') {
genJSON = await trimReadFile(loc.pathname);
} else {
const res = await fetch(subOpts.genesis);
Expand Down
17 changes: 9 additions & 8 deletions packages/solo/src/chain-cosmos-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import {

const console = anylogger('chain-cosmos-sdk');

// the `ag-cosmos-helper` tool in our repo is built by 'cd golang/cosmos &&
// make'. It lives in the build tree along with `bin/ag-solo`, in case there are
// multiple checkouts of `agoric-sdk`.
export const HELPER = new URL(
'../../../golang/cosmos/build/ag-cosmos-helper',
import.meta.url,
Expand Down Expand Up @@ -94,14 +97,12 @@ export async function connectToChain(
// query/tx functions directly without the overhead of spawning a
// subprocess and encoding everything as strings over stdio.

// the 'ag-cosmos-helper' tool in our repo is built by 'make install' and
// put into the user's $GOPATH/bin . That's a bit intrusive, ideally it
// would live in the build tree along with bin/ag-solo . But for now we
// assume that 'ag-cosmos-helper' is on $PATH somewhere.

const rpcHrefs = rpcAddresses.map(
rpcAddr =>
new URL(rpcAddr.includes('://') ? rpcAddr : `http://${rpcAddr}`).href,
const rpcHrefs = rpcAddresses.map(rpcAddr =>
// Don't remove explicit port numbers from the URL, because the Cosmos
// `--node=xxx` flag requires them (it doesn't just assume that
// `--node=https://testnet.rpc.agoric.net` is the same as
// `--node=https://testnet.rpc.agoric.net:443`)
rpcAddr.includes('://') ? rpcAddr : `http://${rpcAddr}`,
);

// Shuffle our rpcHrefs, to help distribute load.
Expand Down

0 comments on commit cf569cc

Please sign in to comment.