@@ -17,7 +17,7 @@ import { makeIssuerTable } from '@agoric/zoe/src/issuerTable';
17
17
18
18
import { E } from '@agoric/eventual-send' ;
19
19
20
- import { makeMarshal } from '@agoric/marshal' ;
20
+ import { makeMarshal , passStyleOf } from '@agoric/marshal' ;
21
21
import {
22
22
makeNotifierKit ,
23
23
observeIteration ,
@@ -88,6 +88,11 @@ export function makeWallet({
88
88
// Offers that the wallet knows about (the inbox).
89
89
const idToOffer = makeStore ( 'offerId' ) ;
90
90
const idToNotifierP = makeStore ( 'offerId' ) ;
91
+ /** @type {Store<string, any> } */
92
+ const idToOfferResult = makeStore ( 'id' ) ;
93
+
94
+ /** @type {WeakStore<Handle<'invitation'>, any> } */
95
+ const invitationHandleToOfferResult = makeWeakStore ( 'invitationHandle' ) ;
91
96
92
97
// Compiled offers (all ready to execute).
93
98
const idToCompiledOfferP = new Map ( ) ;
@@ -809,11 +814,15 @@ export function makeWallet({
809
814
return dappOrigins . get ( origin ) ;
810
815
}
811
816
817
+ function makeId ( dappOrigin , rawId ) {
818
+ return `${ dappOrigin } #${ rawId } ` ;
819
+ }
820
+
812
821
async function addOffer ( rawOffer , requestContext = { } ) {
813
822
const dappOrigin =
814
823
requestContext . dappOrigin || requestContext . origin || 'unknown' ;
815
824
const { id : rawId } = rawOffer ;
816
- const id = ` ${ dappOrigin } # ${ rawId } ` ;
825
+ const id = makeId ( dappOrigin , rawId ) ;
817
826
const offer = harden ( {
818
827
...rawOffer ,
819
828
id,
@@ -898,7 +907,7 @@ export function makeWallet({
898
907
return undefined ;
899
908
}
900
909
901
- /** @type {{ outcome?: any, depositedP?: Promise<any[]>, dappContext?: any } } */
910
+ /** @type {{ depositedP?: Promise<any[]>, dappContext?: any } } */
902
911
let ret = { } ;
903
912
let alreadyResolved = false ;
904
913
const rejected = e => {
@@ -940,16 +949,10 @@ export function makeWallet({
940
949
}
941
950
} ) ;
942
951
943
- // The outcome is most often a string that can be returned, but
944
- // it could be an object. We don't do anything currently if it
945
- // is an object, but we will store it here for future use.
946
- const outcome = await E ( seat ) . getOfferResult ( ) ;
947
- if ( offer . actions ) {
948
- E ( offer . actions ) . result ( offer , outcome ) ;
949
- }
952
+ const offerResult = await E ( seat ) . getOfferResult ( ) ;
953
+ idToOfferResult . init ( id , offerResult ) ;
950
954
951
955
ret = {
952
- outcome,
953
956
depositedP,
954
957
dappContext : offer . dappContext ,
955
958
} ;
@@ -1311,14 +1314,23 @@ export function makeWallet({
1311
1314
return issuerManager ;
1312
1315
}
1313
1316
1314
- const offerResultStore = makeWeakStore ( 'invitationHandle' ) ;
1315
-
1316
1317
async function saveOfferResult ( invitationHandle , offerResult ) {
1317
- offerResultStore . init ( invitationHandle , offerResult ) ;
1318
+ invitationHandleToOfferResult . init ( invitationHandle , offerResult ) ;
1318
1319
}
1319
1320
1320
1321
async function getOfferResult ( invitationHandle ) {
1321
- return offerResultStore . get ( invitationHandle ) ;
1322
+ return invitationHandleToOfferResult . get ( invitationHandle ) ;
1323
+ }
1324
+
1325
+ async function getUINotifier ( rawId , dappOrigin = 'unknown' ) {
1326
+ const id = makeId ( dappOrigin , rawId ) ;
1327
+ const offerResult = idToOfferResult . get ( id ) ;
1328
+ assert (
1329
+ passStyleOf ( offerResult ) === 'copyRecord' ,
1330
+ `offerResult must be a record to have a uiNotifier` ,
1331
+ ) ;
1332
+ assert ( offerResult . uiNotifier , `offerResult does not have a uiNotifier` ) ;
1333
+ return offerResult . uiNotifier ;
1322
1334
}
1323
1335
1324
1336
const wallet = harden ( {
@@ -1396,6 +1408,7 @@ export function makeWallet({
1396
1408
getPaymentsNotifier ( ) {
1397
1409
return paymentsNotifier ;
1398
1410
} ,
1411
+ getUINotifier,
1399
1412
} ) ;
1400
1413
1401
1414
const initialize = async ( ) => {
0 commit comments