Skip to content

Commit

Permalink
fixup! feat(types): real imports
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Apr 17, 2024
1 parent 4c4d232 commit 924c90e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const zeroFee = (): StdFee => {
};

/**
* Use a signing client to
* Use a signing client to create a signer for Agoric-specific transactions
* @param signingClient
* @param address
* Ref: https://docs.keplr.app/api/
Expand Down
60 changes: 30 additions & 30 deletions packages/web-components/src/wallet-connection/watchWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import type { ChainStorageWatcher } from '@agoric/rpc';
import type { Petname } from '@agoric/smart-wallet/src/types.js';
import type { Coin } from '@keplr-wallet/types';
import type { Brand } from '@agoric/ertp/exported.js';
import type {
CurrentWalletRecord,
UpdateRecord,
} from '@agoric/smart-wallet/src/smartWallet.js';

interface PurseInfo {
brand?: Brand;
Expand All @@ -37,9 +41,7 @@ export const watchWallet = (
/* noop */
},
) => {
const pursesNotifierKit = makeNotifierKit(
/** @type {PurseInfo[] | null} */ null,
);
const pursesNotifierKit = makeNotifierKit<PurseInfo[] | null>(null);

const updatePurses = brandToPurse => {
const purses = [] as PurseInfo[];
Expand All @@ -52,23 +54,21 @@ export const watchWallet = (
pursesNotifierKit.updater.updateState(harden(purses));
};

const publicSubscriberPathsNotifierKit = makeNotifierKit(
/** @type { import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord['offerToPublicSubscriberPaths'] | null } */ null,
);
const publicSubscriberPathsNotifierKit = makeNotifierKit<
CurrentWalletRecord['offerToPublicSubscriberPaths'] | null
>(null);

const walletUpdatesNotifierKit = makeNotifierKit(
/** @type { import('@agoric/smart-wallet/src/smartWallet.js').UpdateRecord | null } */ null,
);
const walletUpdatesNotifierKit = makeNotifierKit<UpdateRecord | null>(null);

const smartWalletStatusNotifierKit = makeNotifierKit(
/** @type { {provisioned: boolean} | null } */ null,
);
const smartWalletStatusNotifierKit = makeNotifierKit<{
provisioned: boolean;
} | null>();

let lastPaths;
let isWalletMissing = false;
chainStorageWatcher.watchLatest(
[AgoricChainStoragePathKind.Data, `published.wallet.${address}.current`],
value => {
(value?: { offerToPublicSubscriberPaths: Record<string, string> }) => {
if (!value) {
if (!isWalletMissing) {
smartWalletStatusNotifierKit.updater.updateState(
Expand All @@ -82,7 +82,6 @@ export const watchWallet = (
smartWalletStatusNotifierKit.updater.updateState(
harden({ provisioned: true }),
);
// @ts-expect-error xxx
const { offerToPublicSubscriberPaths: currentPaths } = value;
if (currentPaths === lastPaths) return;

Expand Down Expand Up @@ -121,8 +120,7 @@ export const watchWallet = (
updatePurses(brandToPurse);
};

/** @type {Tendermint34Client} */
let tendermintClient;
let tendermintClient: Tendermint34Client;
const watchBank = async (attempts = 0) => {
await null;

Expand All @@ -145,8 +143,7 @@ export const watchWallet = (
const watchVbankAssets = () => {
chainStorageWatcher.watchLatest(
[AgoricChainStoragePathKind.Data, 'published.agoricNames.vbankAsset'],
value => {
// @ts-expect-error cast
(value: VBankAssets) => {
vbankAssets = value;
possiblyUpdateBankPurses();
},
Expand All @@ -158,12 +155,9 @@ export const watchWallet = (
}

{
/** @type { [string, unknown][] } */
let agoricBrands;
/** @type { {balance: unknown, brand: unknown}[] } */
let nonBankPurses;
/** @type { Map<unknown, { displayInfo: unknown }> } */
let brandToBoardAux;
let agoricBrands: [string, unknown][];
let nonBankPurses: { balance: unknown; brand: unknown }[];
let brandToBoardAux: Map<unknown, { displayInfo: unknown }>;

const possiblyUpdateNonBankPurses = () => {
if (!agoricBrands || !nonBankPurses || !brandToBoardAux) return;
Expand All @@ -189,7 +183,7 @@ export const watchWallet = (
const watchBrands = () => {
chainStorageWatcher.watchLatest(
[AgoricChainStoragePathKind.Data, 'published.agoricNames.brand'],
value => {
(value: [string, unknown][]) => {
agoricBrands = value;
possiblyUpdateNonBankPurses();
},
Expand Down Expand Up @@ -236,14 +230,20 @@ export const watchWallet = (
const watchWalletUpdates = async () => {
const watch = async () => {
const leader = makeLeader(rpc);
const follower = makeFollower(`:published.wallet.${address}`, leader, {
proof: 'none',
unserializer: Far('marshaller', { ...chainStorageWatcher.marshaller }),
});
const follower = makeFollower<{ error?: unknown; value: unknown }>(
`:published.wallet.${address}`,
leader,
{
proof: 'none',
unserializer: Far('marshaller', {
...chainStorageWatcher.marshaller,
}),
},
);

for await (const update of iterateEach(follower)) {
console.debug('wallet update', update);
// @ts-expect-error xxx
// @ts-expect-error update unknown bc iterateEach() losing the type
if ('error' in update) continue;

// @ts-expect-error xxx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('stringifyRatio', () => {
const ethPrice = harden(
makeRatio(
158724n, // value of 1 eth in cents
// @ts-expect-error fake brand
dollarBrand,
10n ** 18n,
ethBrand,
Expand Down Expand Up @@ -59,7 +58,6 @@ describe('stringifyRatio', () => {
const ethPrice = harden(
makeRatio(
1909113516n, // value of 1 eth in smallest IST denomination
// @ts-expect-error fake brand
istBrand,
10n ** 18n,
ethBrand,
Expand Down

0 comments on commit 924c90e

Please sign in to comment.