diff --git a/packages/dapp-svelte-wallet/api/src/lib-wallet.js b/packages/dapp-svelte-wallet/api/src/lib-wallet.js index f9131cddb5b..4f4b5dda8a7 100644 --- a/packages/dapp-svelte-wallet/api/src/lib-wallet.js +++ b/packages/dapp-svelte-wallet/api/src/lib-wallet.js @@ -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} */ @@ -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; } @@ -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, @@ -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) { @@ -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 }; } @@ -602,7 +613,6 @@ export async function makeWallet({ const amount = { brand, value, - displayInfo: brandTable.getByBrand(brand).displayInfo, }; return [keyword, amount]; }, @@ -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); } @@ -968,6 +977,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 +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, 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.