Skip to content

Commit 6184470

Browse files
authored
feat(react-components): modal customization and offer status updates (#120)
* feat(react-components): allow custom styling on modals * chore: remove unused type import * fix(react-components): update offer status when provision notice closed * fixup! fix(react-components): update offer status when provision notice closed
1 parent e6f79e0 commit 6184470

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

packages/react-components/src/lib/context/AgoricContext.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import { createContext } from 'react';
22
import { makeAgoricWalletConnection } from '@agoric/web-components';
33
import type { ChainStorageWatcher } from '@agoric/rpc';
4-
import type {
5-
Brand,
6-
Amount,
7-
AssetKind,
8-
AmountValue,
9-
} from '@agoric/ertp/src/types';
4+
import type { Brand, Amount, AssetKind } from '@agoric/ertp/src/types';
105

116
export type PurseJSONState<T extends AssetKind> = {
127
brand: Brand;

packages/react-components/src/lib/context/AgoricProvider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ChainProvider } from '@cosmos-kit/react';
1+
import { ChainProvider, type ThemeCustomizationProps } from '@cosmos-kit/react';
22
import { AgoricProviderLite } from './AgoricProviderLite';
33
import { chains, assets } from 'chain-registry';
44
import { makeAssetList, makeChainInfo } from '../config';
@@ -17,6 +17,7 @@ export type AgoricProviderProps = PropsWithChildren<{
1717
walletConnectOptions?: WalletConnectOptions;
1818
onConnectionError?: (e: unknown) => void;
1919
provisionNoticeContent?: ProvisionNoticeProps['mainContent'];
20+
modalTheme?: ThemeCustomizationProps;
2021
}>;
2122

2223
export const AgoricProvider = (props: AgoricProviderProps) => {
@@ -37,6 +38,7 @@ const AgoricProviderInner = ({
3738
children,
3839
onConnectionError,
3940
provisionNoticeContent,
41+
modalTheme,
4042
}: AgoricProviderProps) => {
4143
const { networkConfig } = useContext(NetworkContext);
4244
assert(networkConfig, 'Network config missing from context');
@@ -57,6 +59,7 @@ const AgoricProviderInner = ({
5759
endpoints: { [chainName]: apis },
5860
isLazy: true,
5961
}}
62+
modalTheme={modalTheme}
6063
>
6164
<AgoricProviderLite
6265
chainName={chainName}

packages/react-components/src/lib/context/AgoricProviderLite.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ export type AgoricProviderLiteProps = PropsWithChildren<{
3939
provisionNoticeContent?: ProvisionNoticeProps['mainContent'];
4040
}>;
4141

42+
interface PostProvisionOffer {
43+
makeOffer: () => void;
44+
onStatusChange: (change: { status: string; data: any }) => void;
45+
}
46+
4247
/**
4348
* Provides access to Agoric-specific account features such as smart wallet
4449
* provisioning, purses, offer signing, and more.
@@ -74,7 +79,7 @@ export const AgoricProviderLite = ({
7479
bigint | undefined
7580
>(undefined);
7681
const [postProvisionOffer, setPostProvisionOffer] = useState<
77-
(() => void) | undefined
82+
PostProvisionOffer | undefined
7883
>(undefined);
7984

8085
const { status, client } = useWalletClient();
@@ -224,9 +229,12 @@ export const AgoricProviderLite = ({
224229
walletConnection?.makeOffer(...offerArgs);
225230
return;
226231
}
227-
setPostProvisionOffer(() => () => {
228-
walletConnection?.makeOffer(...offerArgs);
229-
setPostProvisionOffer(undefined);
232+
setPostProvisionOffer({
233+
makeOffer: () => {
234+
walletConnection?.makeOffer(...offerArgs);
235+
setPostProvisionOffer(undefined);
236+
},
237+
onStatusChange: offerArgs[3],
230238
});
231239
}
232240
: undefined;
@@ -251,8 +259,14 @@ export const AgoricProviderLite = ({
251259
{children}
252260
<ProvisionNoticeModal
253261
mainContent={provisionNoticeContent}
254-
onClose={() => setPostProvisionOffer(undefined)}
255-
proceed={postProvisionOffer}
262+
onClose={() => {
263+
postProvisionOffer?.onStatusChange({
264+
status: 'error',
265+
data: new Error('User cancelled'),
266+
});
267+
setPostProvisionOffer(undefined);
268+
}}
269+
proceed={postProvisionOffer?.makeOffer}
256270
/>
257271
</AgoricContext.Provider>
258272
);

0 commit comments

Comments
 (0)