diff --git a/packages/dapp-svelte-wallet/api/src/lib-wallet.js b/packages/dapp-svelte-wallet/api/src/lib-wallet.js index f9131cddb5b..2e860f88ce1 100644 --- a/packages/dapp-svelte-wallet/api/src/lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/src/lib-wallet.js @@ -151,7 +151,8 @@ export async function makeWallet({ depositBoardId = brandToDepositFacetId.get(brand); } - const issuerRecord = brandTable.getByBrand(brand); + const issuerRecord = + brandTable.hasByBrand(brand) && brandTable.getByBrand(brand); /** * @type {PursesJSONState} */ @@ -213,7 +214,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; } @@ -228,7 +229,14 @@ 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, @@ -242,12 +250,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) { @@ -431,7 +439,17 @@ export async function makeWallet({ return undefined; }), ); - }); + }) + .finally(() => + // Try reclaiming any payments that were left on the table. + keywords.forEach((keyword, i) => { + const purse = purseKeywordRecord[keyword]; + if (purse && payments[i]) { + // eslint-disable-next-line no-use-before-define + addPayment(payments[i], purse); + } + }), + ); return { depositedP, seat }; } @@ -602,7 +620,6 @@ export async function makeWallet({ const amount = { brand, value, - displayInfo: brandTable.getByBrand(brand).displayInfo, }; return [keyword, amount]; }, @@ -924,7 +941,6 @@ export async function makeWallet({ }) .catch(rejected); } catch (e) { - console.error('Have error', e); if (offer.actions) { E(offer.actions).error(offer, e); } @@ -968,6 +984,17 @@ export async function makeWallet({ const brand = await E(payment).getAllegedBrand(); const depositedPK = makePromiseKit(); + /** @type {ERef} */ + 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, @@ -993,7 +1020,8 @@ export async function makeWallet({ } else { purse = purseOrPetname; } - const brandRecord = brandTable.getByBrand(brand); + const brandRecord = + brandTable.hasByBrand(brand) && brandTable.getByBrand(brand); paymentRecord = { ...paymentRecord, ...brandRecord, @@ -1055,7 +1083,7 @@ export async function makeWallet({ } // Try an automatic deposit. - return paymentRecord.actions.deposit(depositTo); + await paymentRecord.actions.deposit(depositTo); }; // Allow people to send us payments. diff --git a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js index 06f58db0df3..14f7c7007e2 100644 --- a/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/test/test-lib-wallet.js @@ -712,6 +712,9 @@ test('lib-wallet offer methods', async t => { petname: 'moola', }, value: 1, + displayInfo: { + amountMathKind: 'nat', + }, }, }, }, @@ -740,6 +743,9 @@ test('lib-wallet offer methods', async t => { petname: 'moola', }, value: 1, + displayInfo: { + amountMathKind: 'nat', + }, }, }, }, diff --git a/packages/dapp-svelte-wallet/ui/src/Transaction.svelte b/packages/dapp-svelte-wallet/ui/src/Transaction.svelte index 01db89e3d15..c7617de9260 100644 --- a/packages/dapp-svelte-wallet/ui/src/Transaction.svelte +++ b/packages/dapp-svelte-wallet/ui/src/Transaction.svelte @@ -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 = { @@ -99,16 +99,16 @@
- {#each Object.entries(give) as [role, { amount, displayInfo, pursePetname }], i} + {#each Object.entries(give) as [role, { amount, pursePetname }], i}
Give
- from + from
{/each} {#each Object.entries(want) as [role, { amount, displayInfo, pursePetname }], i}
Want
- into + into
{/each}
diff --git a/packages/dapp-svelte-wallet/ui/src/captp.js b/packages/dapp-svelte-wallet/ui/src/captp.js index d3c25f5ee78..3daa042bf5a 100644 --- a/packages/dapp-svelte-wallet/ui/src/captp.js +++ b/packages/dapp-svelte-wallet/ui/src/captp.js @@ -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. diff --git a/scripts/create-agoric-cli.cjs b/scripts/create-agoric-cli.cjs index 734214232f8..ea4008b55a2 100755 --- a/scripts/create-agoric-cli.cjs +++ b/scripts/create-agoric-cli.cjs @@ -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);