Skip to content

Commit

Permalink
turned iframeOptions.autoConnect back into boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed May 9, 2024
1 parent ad01673 commit 3449a4b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/docs/provider/grazProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function CustomApp({ Component, pageProps }: AppProps) {
iframeOptions?: {
// for integrating using WalletType.COSMIFRAME
allowedIframeParentOrigins: string[]
autoConnect?: string | string[] | null
autoConnect?: boolean
}
}
```
Expand Down
15 changes: 2 additions & 13 deletions packages/graz/src/provider/events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,18 @@ export const useGrazEvents = () => {
useEffect(() => {
if (
!iframeOptions ||
iframeOptions.autoConnect === null ||
iframeOptions.autoConnect === false ||
!iframeOptions.allowedIframeParentOrigins.length ||
!chains
) {
return;
}

const autoConnectChains = [iframeOptions.autoConnect || []].flat();
// Select auto-connect chains from provided chains.
const chainIds = autoConnectChains.length
? chains.flatMap((c) => (autoConnectChains.includes(c.chainId) ? c.chainId : []))
: // If no auto-connect chains, attempt connection to all provided.
chains.map((c) => c.chainId);

if (!chainIds.length) {
return;
}

const cosmiframe = new Cosmiframe(iframeOptions.allowedIframeParentOrigins);
void cosmiframe.isReady().then((ready) => {
if (ready) {
return connect({
chainId: chainIds,
chainId: chains.map((c) => c.chainId),
walletType: WalletType.COSMIFRAME,
});
}
Expand Down
10 changes: 5 additions & 5 deletions packages/graz/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { persist, subscribeWithSelector } from "zustand/middleware";

import type { Dictionary } from "../types/core";
import { WalletType } from "../types/wallet";
import type { ChainId } from "../utils/multi-chain";

export interface ChainConfig {
path?: string;
Expand Down Expand Up @@ -41,11 +40,12 @@ export interface IframeOptions {
*/
allowedIframeParentOrigins: string[];
/**
* The chain or chains to auto connect to when it detects that we're in an
* iframe running Cosmiframe. Set to null to disable autoconnect. By default
* it will use the first chain in the provided chains list.
* Whether or not to auto connect when in an iframe running Cosmiframe. This
* will attempt to connect to all chains provided to GrazProvider.
*
* Defaults to true.
*/
autoConnect?: ChainId | null;
autoConnect?: boolean;
}

export interface GrazInternalStore {
Expand Down

0 comments on commit 3449a4b

Please sign in to comment.