Skip to content

Commit

Permalink
Merge pull request #6217 from Agoric/wallet-offer-status
Browse files Browse the repository at this point in the history
feat: Wallet UI offer status
  • Loading branch information
mergify[bot] authored Sep 16, 2022
2 parents 7d9afc0 + 6e8811f commit ece86db
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/cosmic-swingset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ scenario2-setup-nobuild:
$(AGCH) --home=t1/bootstrap keys add bootstrap --keyring-backend=test
$(AGCH) --home=t1/bootstrap keys show -a bootstrap --keyring-backend=test > t1/bootstrap-address
$(AGCH) --home=t1/n0 add-genesis-account `cat t1/bootstrap-address` $(BOOT_COINS)
# Create
# Create the (singleton) chain node.
$(AGCH) --home=t1/n0 --keyring-dir=t1/bootstrap gentx --keyring-backend=test bootstrap 73000000ubld --chain-id=$(CHAIN_ID)
$(AGCH) --home=t1/n0 collect-gentxs
Expand Down Expand Up @@ -214,7 +213,7 @@ t1-provision-one-with-powers: wait-for-cosmos
t1/$(BASE_PORT) $$addr $(AGORIC_POWERS) -ojson | tee /dev/stderr | grep -q '"code":0'; }

# Send some USDC to the vbank/provision module account where it can be traded for IST.
fund-provision-pool: wait-for-cosmos
fund-provision-pool:
$(MAKE) ACCT_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346 SOLO_COINS=1234000000ibc/usdc1234 fund-acct

fund-acct: wait-for-cosmos
Expand Down
9 changes: 6 additions & 3 deletions packages/wallet/api/src/marshal-contexts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const { details: X, quote: q } = assert;
* @returns {specimen is BoardId}
*/
const isBoardId = specimen => {
return typeof specimen === 'string' && !!specimen.match(/board[^:]/);
return typeof specimen === 'string' && !!specimen.match(/^board[^:]/);
};

/**
Expand Down Expand Up @@ -104,6 +104,7 @@ const initSlotVal = (table, slot, val) => {

/**
* Make context for exporting wallet data where brands etc. can be recognized by boardId.
* Export for use outside the smart wallet.
*
* When serializing wallet state for, there's a tension between
*
Expand Down Expand Up @@ -235,7 +236,8 @@ const defaultMakePresence = iface => {
};

/**
* Make context for unserializing wallet or board data.
* Make context for marshalling wallet or board data.
* To be imported into the client, which never exports objects.
*
* @param {(iface: string) => unknown} [makePresence]
*/
Expand Down Expand Up @@ -295,7 +297,8 @@ export const makeImportContext = (makePresence = defaultMakePresence) => {
*/
fromMyWallet: (slot, iface) => {
if (!slot) {
return makePresence('dummy');
// Empty or null slots are neither in the wallet nor the board.
return makePresence(`${slot}`);
}
const { kind, id } = parseWalletSlot(walletObjects, slot);
return kind
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/ui/src/service/Offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export const getOfferService = (
const acceptOffer = async id => {
const offer = offers.get(id);
assert(offer, `Tried to accept undefined offer ${id}`);
const action = offer.spendAction;
return signSpendAction(action);
return signSpendAction(offer.spendAction);
};

const cancelOffer = _id => {
Expand All @@ -64,6 +63,7 @@ export const getOfferService = (
chainOffersNotifier,
)) {
state?.forEach(offer => {
console.log('chain offer', offer);
const splitId = offer.id.split('#');
const rawId = splitId[splitId.length - 1];
if (offers.has(rawId)) {
Expand Down
25 changes: 20 additions & 5 deletions packages/wallet/ui/src/util/WalletBackendAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,22 @@ export const makeWalletBridgeFromFollower = (
}
case 'offerStatus': {
const { status } = updateRecord;
offers[status.id] = status;
notifierKits.offers.updater.updateState(
harden(Object.values(offers)),
);
console.log('offerStatus', { status, offers });
const oldOffer = offers[status.id];
if (
oldOffer &&
oldOffer.status !== 'accept' &&
'numWantsSatisfied' in status
) {
offers[status.id] = {
...oldOffer,
id: `${status.id}`,
status: 'accept',
};
notifierKits.offers.updater.updateState(
harden(Object.values(offers)),
);
}
break;
}
default: {
Expand Down Expand Up @@ -253,6 +265,7 @@ export const makeWalletBridgeFromFollower = (
// smart-wallet format.
const addOfferPSMHack = async details => {
const {
id,
instanceHandleBoardId: instance, // This actually is the instance handle, not an ID.
invitationMaker: { method },
proposalTemplate: { give, want },
Expand Down Expand Up @@ -297,7 +310,9 @@ export const makeWalletBridgeFromFollower = (
instancePetname: `instance@${instanceBoardId}`,
spendAction: JSON.stringify(spendAction),
};
return offerService.addOffer(fullOffer);
offerService.addOffer(fullOffer);
offers[id] = fullOffer;
return id;
};

const walletBridge = Far('follower wallet bridge', {
Expand Down

0 comments on commit ece86db

Please sign in to comment.