Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve purse types #93

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/react-components/src/lib/context/AgoricContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { createContext } from 'react';
import { makeAgoricWalletConnection } from '@agoric/web-components';
import {
type AmountValue,
makeAgoricWalletConnection,
} from '@agoric/web-components';
import type { ChainStorageWatcher } from '@agoric/rpc';
import type { Brand, Amount, AssetKind } from '@agoric/ertp/src/types';

export type PursesJSONState<T extends AssetKind> = {
export type PurseJSONState<T extends AssetKind> = {
brand: Brand;
/** The board ID for this purse's brand */
brandBoardId: string;
Expand All @@ -14,9 +17,13 @@ export type PursesJSONState<T extends AssetKind> = {
/** The petname for this purse */
pursePetname: string;
/** The brand's displayInfo */
displayInfo: unknown;
// XXX Copied from @agoric/ertp/src/types-ambient.js
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question

Just curious, what does XXX stand for here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it just signals a code smell that isn't really actionable enough for a TODO. Ideally the types would be exported from agoric-sdk as a module instead of being ambient. I'm not sure if there's an issue to track this exactly (my search).

displayInfo: {
assetKind: AssetKind;
decimalPlaces?: number;
};
/** The purse's current balance */
value: unknown;
value: AmountValue;
currentAmountSlots: unknown;
currentAmount: Amount<T>;
};
Expand All @@ -31,7 +38,7 @@ export type AgoricState = {
connect?: () => Promise<void>;
chainStorageWatcher?: ChainStorageWatcher;
walletConnection?: AgoricWalletConnection;
purses?: PursesJSONState<AssetKind>[];
purses?: PurseJSONState<AssetKind>[];
offerIdsToPublicSubscribers?: Record<string, Record<string, string>>;
isSmartWalletProvisioned?: boolean;
provisionSmartWallet?: AgoricWalletConnection['provisionSmartWallet'];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PropsWithChildren, useState } from 'react';
import {
AgoricContext,
type PursesJSONState,
type PurseJSONState,
type AgoricWalletConnection,
} from './AgoricContext';
import { SigningStargateClient } from '@cosmjs/stargate';
Expand Down Expand Up @@ -55,9 +55,9 @@ export const AgoricProviderLite = ({
const [chainStorageWatcher, setChainStorageWatcher] = useState<
ChainStorageWatcher | undefined
>(undefined);
const [purses, setPurses] = useState<
PursesJSONState<AssetKind>[] | undefined
>(undefined);
const [purses, setPurses] = useState<PurseJSONState<AssetKind>[] | undefined>(
undefined,
);
const [offerIdsToPublicSubscribers, setOfferIdsToPublicSubscribers] =
useState<Record<string, Record<string, string>> | undefined>(undefined);
const [isSmartWalletProvisioned, setIsSmartWalletProvisioned] = useState<
Expand Down
Loading