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

Wallet fixes #1991

Merged
merged 3 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
42 changes: 31 additions & 11 deletions packages/dapp-svelte-wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export async function makeWallet({
depositBoardId = brandToDepositFacetId.get(brand);
}

const issuerRecord = brandTable.getByBrand(brand);
const issuerRecord = brandTable.hasByBrand(brand) && brandTable.getByBrand(brand);
/**
* @type {PursesJSONState}
*/
Expand Down Expand Up @@ -213,7 +213,7 @@ export async function makeWallet({

const displayProposal = proposalTemplate => {
const { want, give, exit = { onDemand: null } } = proposalTemplate;
const compile = pursePetnameValueKeywordRecord => {
const displayRecord = pursePetnameValueKeywordRecord => {
if (pursePetnameValueKeywordRecord === undefined) {
return undefined;
}
Expand All @@ -228,7 +228,9 @@ export async function makeWallet({
pursePetname = purseMapping.valToPetname.get(purse);
}

amount = harden({ ...amount, brand: purseToBrand.get(purse) });
const brand = purseToBrand.get(purse);
const issuerRecord = brandTable.hasByBrand(brand) && brandTable.getByBrand(brand);
amount = harden({ ...amount, brand, displayInfo: issuerRecord && issuerRecord.displayInfo });
const displayAmount = display(amount);
return [
keyword,
Expand All @@ -242,12 +244,12 @@ export async function makeWallet({
),
);
};
const proposal = {
want: compile(want),
give: compile(give),
const proposalForDisplay = {
want: displayRecord(want),
give: displayRecord(give),
exit,
};
return proposal;
return proposalForDisplay;
};

async function updateInboxState(id, offer, doPush = true) {
Expand Down Expand Up @@ -431,7 +433,16 @@ export async function makeWallet({
return undefined;
}),
);
});
})
.finally(() =>
// Try reclaiming any payments that were left on the table.
keywords.map((keyword, i) => {
const purse = purseKeywordRecord[keyword];
if (purse && payments[i]) {
return addPayment(payments[i], purse);
}
})
);

return { depositedP, seat };
}
Expand Down Expand Up @@ -602,7 +613,6 @@ export async function makeWallet({
const amount = {
brand,
value,
displayInfo: brandTable.getByBrand(brand).displayInfo,
};
return [keyword, amount];
},
Expand Down Expand Up @@ -924,7 +934,6 @@ export async function makeWallet({
})
.catch(rejected);
} catch (e) {
console.error('Have error', e);
if (offer.actions) {
E(offer.actions).error(offer, e);
}
Expand Down Expand Up @@ -968,6 +977,17 @@ export async function makeWallet({
const brand = await E(payment).getAllegedBrand();
const depositedPK = makePromiseKit();

/** @type {ERef<boolean>} */
let isAliveP = true;
if (brandTable.hasByBrand(brand)) {
isAliveP = E(brandTable.getByBrand(brand).issuer).isLive(payment);
}
const isAlive = await isAliveP;
if (!isAlive) {
// Nothing to do.
return;
}

/** @type {PaymentRecord} */
let paymentRecord = {
payment,
Expand All @@ -993,7 +1013,7 @@ export async function makeWallet({
} else {
purse = purseOrPetname;
}
const brandRecord = brandTable.getByBrand(brand);
const brandRecord = brandTable.hasByBrand(brand) && brandTable.getByBrand(brand);
paymentRecord = {
...paymentRecord,
...brandRecord,
Expand Down
6 changes: 6 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 @@ -712,6 +712,9 @@ test('lib-wallet offer methods', async t => {
petname: 'moola',
},
value: 1,
displayInfo: {
amountMathKind: 'nat',
},
},
},
},
Expand Down Expand Up @@ -740,6 +743,9 @@ test('lib-wallet offer methods', async t => {
petname: 'moola',
},
value: 1,
displayInfo: {
amountMathKind: 'nat',
},
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions packages/dapp-svelte-wallet/ui/src/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

const makeRejected = context =>
function rejected(e) {
// TODO: Do something less blatant.
alert(`${context}: ${e}`);
// We expect our caller to see this result, so just log an error.
console.error(context, e);
};

const statusText = {
Expand Down Expand Up @@ -99,16 +99,16 @@
<Debug title="Offer Detail" target={item} />
</div>
<div>
{#each Object.entries(give) as [role, { amount, displayInfo, pursePetname }], i}
{#each Object.entries(give) as [role, { amount, pursePetname }], i}
<div>
<h6>Give</h6>
<Amount {amount} /> from <Petname name={pursePetname} {displayInfo} />
<Amount {amount} displayInfo={amount.displayInfo} /> from <Petname name={pursePetname} />
</div>
{/each}
{#each Object.entries(want) as [role, { amount, displayInfo, pursePetname }], i}
<div>
<h6>Want</h6>
<Amount {amount} /> into <Petname name={pursePetname} {displayInfo} />
<Amount {amount} displayInfo={amount.displayInfo} /> into <Petname name={pursePetname} />
</div>
{/each}
</div>
Expand Down
12 changes: 10 additions & 2 deletions packages/dapp-svelte-wallet/ui/src/captp.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,16 @@ export function makeCapTPConnection(makeConnection, { onReset }) {
abort = ctpAbort;
dispatch = ctpDispatch;

// Wait for the other side to finish loading.
await E.G(getBootstrap()).LOADING;
// Wait for the wallet to finish loading.
let lastUpdateCount;
while (true) {
const update = await E(E.G(getBootstrap()).loadingNotifier).getUpdateSince(lastUpdateCount);
console.log('waiting for wallet');
lastUpdateCount = update.updateCount;
if (!update.value.includes('wallet')) {
break;
}
}

// Begin the flow of messages to our wallet, which
// we refetch from the new, loaded, bootstrap promise.
Expand Down
3 changes: 3 additions & 0 deletions scripts/create-agoric-cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ exec ${cli} \$opts \${1+"\$@"}
`;

console.log(`creating ${script}`);
if (fs.existsSync(script)) {
throw Error(`${script} must not already exist; you should use a fresh path.`);
}
try {
// Unlink the old version in case it's a symlink.
fs.unlinkSync(script);
Expand Down