Skip to content

Commit

Permalink
Merge branch 'master' into turadg-sync-endo-2022-10-24-21-57-11
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] committed Oct 24, 2022
2 parents e31d2f5 + 8948ecc commit fb205c6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
11 changes: 10 additions & 1 deletion packages/wallet/ui/src/components/SmartWalletConnection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { makeFollower, makeLeader } from '@agoric/casting';
import { observeIterator } from '@agoric/notifier';
import { NO_SMART_WALLET_ERROR } from '@agoric/smart-wallet/src/utils';
import { makeImportContext } from '@agoric/wallet/api/src/marshal-contexts';
import { Far } from '@endo/marshal';
import MuiAlert from '@mui/material/Alert';
import Snackbar from '@mui/material/Snackbar';
import React, { useEffect, useState, useMemo } from 'react';
Expand All @@ -24,6 +25,14 @@ const Alert = React.forwardRef(function Alert({ children, ...props }, ref) {
);
});

/**
* Wallet UI doesn't use objects as presences, only as identities.
* Use this to override the defaultMakePresence of makeImportContext.
*
* @param {string} iface
*/
const inertPresence = iface => Far(iface.replace(/^Alleged: /, ''), {});

const SmartWalletConnection = ({
connectionConfig,
setConnectionStatus,
Expand Down Expand Up @@ -77,7 +86,7 @@ const SmartWalletConnection = ({
};

const [context, leader] = useMemo(
() => [makeImportContext(), makeLeader(href)],
() => [makeImportContext(inertPresence), makeLeader(href)],
[connectionConfig, keplrConnection],
);

Expand Down
7 changes: 7 additions & 0 deletions packages/wallet/ui/src/contexts/Provider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ import {
} from '../util/keyManagement';
import { onLoadP } from '../util/onLoad';

/**
* @typedef KeplrUtils
* @property {string} address
* @property {{ interactiveSigner: import('../util/keyManagement').InteractiveSigner, backgroundSigner: import('../util/keyManagement').BackgroundSigner}} signers
* @property {string} chainId,
*/

const useDebugLogging = (state, watch) => {
useEffect(() => console.debug('useDebugLogging', { state }), watch);
};
Expand Down
7 changes: 5 additions & 2 deletions packages/wallet/ui/src/service/Offers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const getOfferService = (
chainOffersNotifier,
boardIdMarshaller,
) => {
/** @type {Map<number, Offer>} */
const offers = new Map();
const { notifier, updater } = makeNotifierKit();
const broadcastUpdates = () => updater.updateState([...offers.values()]);
Expand Down Expand Up @@ -106,16 +107,17 @@ export const getOfferService = (
broadcastUpdates();
};

const declineOffer = (/** @type {string} */ id) => {
const declineOffer = (/** @type {number} */ id) => {
const offer = offers.get(id);
assert(offer, `Tried to decline undefined offer ${id}`);
upsertOffer({ ...offer, status: OfferUIStatus.declined });
broadcastUpdates();
};

const acceptOffer = async (/** @type {string} */ id) => {
const acceptOffer = async (/** @type {number} */ id) => {
const offer = offers.get(id);
assert(offer, `Tried to accept undefined offer ${id}`);
assert(offer.spendAction, 'Missing spendAction');
return signSpendAction(offer.spendAction);
};

Expand All @@ -137,6 +139,7 @@ export const getOfferService = (
...oldOffer,
id: status.id,
status: OfferUIStatus.rejected,
// @ts-expect-error xxx types debt
error: `${status.error}`,
});
remove(smartWalletKey, status.id);
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/ui/src/util/WalletBackendAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const makeBackendFromWalletBridge = (
* @param {ReturnType<import('@endo/marshal').makeMarshal>} marshaller
* @param {import('@agoric/casting').ValueFollower<import('@agoric/smart-wallet/src/smartWallet').CurrentWalletRecord>} currentFollower
* @param {import('@agoric/casting').ValueFollower<import('@agoric/smart-wallet/src/smartWallet').UpdateRecord>} updateFollower
* @param {object} keplrConnection
* @param {import('../contexts/Provider.jsx').KeplrUtils} keplrConnection
* @param {(e: unknown) => void} [errorHandler]
* @param {() => void} [firstCallback]
*/
Expand Down Expand Up @@ -169,6 +169,7 @@ export const makeWalletBridgeFromFollowers = (
notifierKits.purses.updater.updateState(harden(purses));
};

/** @param {string} data */
const signSpendAction = async data => {
const {
signers: { interactiveSigner },
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/ui/src/util/keyManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export const makeBackgroundSigner = async ({ localStorage, csprng }) => {
queryGrants,
});
};

/** @typedef {Awaited<ReturnType<typeof makeBackgroundSigner>>} BackgroundSigner */
/**
* @param {string} granter bech32 address
* @param {string} grantee bech32 address
Expand Down Expand Up @@ -520,3 +520,4 @@ export const makeInteractiveSigner = async (
},
});
};
/** @typedef {Awaited<ReturnType<typeof makeInteractiveSigner>>} InteractiveSigner */

0 comments on commit fb205c6

Please sign in to comment.