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

feat(react-components): modal customization and offer status updates #120

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 1 addition & 6 deletions packages/react-components/src/lib/context/AgoricContext.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { createContext } from 'react';
import { makeAgoricWalletConnection } from '@agoric/web-components';
import type { ChainStorageWatcher } from '@agoric/rpc';
import type {
Brand,
Amount,
AssetKind,
AmountValue,
} from '@agoric/ertp/src/types';
import type { Brand, Amount, AssetKind } from '@agoric/ertp/src/types';

export type PurseJSONState<T extends AssetKind> = {
brand: Brand;
Expand Down
5 changes: 4 additions & 1 deletion packages/react-components/src/lib/context/AgoricProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChainProvider } from '@cosmos-kit/react';
import { ChainProvider, type ThemeCustomizationProps } from '@cosmos-kit/react';
import { AgoricProviderLite } from './AgoricProviderLite';
import { chains, assets } from 'chain-registry';
import { makeAssetList, makeChainInfo } from '../config';
Expand All @@ -17,6 +17,7 @@ export type AgoricProviderProps = PropsWithChildren<{
walletConnectOptions?: WalletConnectOptions;
onConnectionError?: (e: unknown) => void;
provisionNoticeContent?: ProvisionNoticeProps['mainContent'];
modalTheme?: ThemeCustomizationProps;
}>;

export const AgoricProvider = (props: AgoricProviderProps) => {
Expand All @@ -37,6 +38,7 @@ const AgoricProviderInner = ({
children,
onConnectionError,
provisionNoticeContent,
modalTheme,
}: AgoricProviderProps) => {
const { networkConfig } = useContext(NetworkContext);
assert(networkConfig, 'Network config missing from context');
Expand All @@ -57,6 +59,7 @@ const AgoricProviderInner = ({
endpoints: { [chainName]: apis },
isLazy: true,
}}
modalTheme={modalTheme}
>
<AgoricProviderLite
chainName={chainName}
Expand Down
25 changes: 19 additions & 6 deletions packages/react-components/src/lib/context/AgoricProviderLite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export const AgoricProviderLite = ({
bigint | undefined
>(undefined);
const [postProvisionOffer, setPostProvisionOffer] = useState<
(() => void) | undefined
| {
Copy link
Member

Choose a reason for hiding this comment

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

consider a type alias

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, TY4R

makeOffer: () => void;
onStatusChange: (change: { status: string; data: any }) => void;
}
| undefined
>(undefined);

const { status, client } = useWalletClient();
Expand Down Expand Up @@ -224,9 +228,12 @@ export const AgoricProviderLite = ({
walletConnection?.makeOffer(...offerArgs);
return;
}
setPostProvisionOffer(() => () => {
walletConnection?.makeOffer(...offerArgs);
setPostProvisionOffer(undefined);
setPostProvisionOffer({
makeOffer: () => {
walletConnection?.makeOffer(...offerArgs);
setPostProvisionOffer(undefined);
},
onStatusChange: offerArgs[3],
});
}
: undefined;
Expand All @@ -251,8 +258,14 @@ export const AgoricProviderLite = ({
{children}
<ProvisionNoticeModal
mainContent={provisionNoticeContent}
onClose={() => setPostProvisionOffer(undefined)}
proceed={postProvisionOffer}
onClose={() => {
postProvisionOffer?.onStatusChange({
status: 'error',
data: new Error('User cancelled'),
});
setPostProvisionOffer(undefined);
}}
proceed={postProvisionOffer?.makeOffer}
/>
</AgoricContext.Provider>
);
Expand Down
Loading