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

fix install wallet instruction modal, don't pop up when click wallet icon #461

Merged
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
1 change: 1 addition & 0 deletions packages/react/src/context/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useSelectedWalletContext'
18 changes: 18 additions & 0 deletions packages/react/src/context/useSelectedWalletContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createContext, useContext, useState } from "react";


export const SelectedWalletRepoContext = createContext(null)


export const SelectedWalletRepoProvider = ({ children }) => {

const [selectedWalletRepo, selectWalletRepo] = useState(null)

return <SelectedWalletRepoContext.Provider value={{
selectedWalletRepo, selectWalletRepo
}}>
{children}
</SelectedWalletRepoContext.Provider>
}

export const useSelectedWalletRepoContext = () => useContext(SelectedWalletRepoContext)
4 changes: 4 additions & 0 deletions packages/react/src/modal/components/views/WalletList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConnectModalHead, ConnectModalWalletList } from '@interchain-ui/react';
import { useCallback, useEffect, useMemo, useState } from 'react';

import { getWalletProp } from './config';
import { useSelectedWalletRepoContext } from '../../../context';

interface DynamicWalletListProps {
wallets: WalletListViewProps['wallets'];
Expand All @@ -12,7 +13,10 @@ interface DynamicWalletListProps {
function DynamicWalletList({ wallets, onClose }: DynamicWalletListProps) {
const [isLargeScreen, setIsLargeScreen] = useState(true);

const { selectWalletRepo } = useSelectedWalletRepoContext()

const onWalletClicked = useCallback(async (wallet: ChainWalletBase) => {
selectWalletRepo(wallet)
await wallet.connect(wallet.walletStatus !== 'NotExist');
if (!['Rejected', 'NotExist'].includes(wallet.walletStatus)) {
onClose();
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
WalletListImplGetter,
WalletViewImplGetter,
} from './components/views';
import { useSelectedWalletRepoContext } from '../context';

export type ModalCustomizationProps = {
modalContainerClassName?: string;
Expand Down Expand Up @@ -80,7 +81,8 @@ export function WalletModal({
beforeConnect: { disconnect: disconnectOptions },
});

const current = walletRepo?.current;
const { selectedWalletRepo } = useSelectedWalletRepoContext()
const current = walletRepo?.wallets.find(w => w.walletName === selectedWalletRepo?.walletName);

(current?.client as any)?.setActions?.({
qrUrl: {
Expand Down
37 changes: 20 additions & 17 deletions packages/react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ReactNode, useCallback, useMemo } from 'react';

import { ThemeCustomizationProps, WalletModal } from './modal';
import { defaultModalViews } from './modal/components/views';
import { SelectedWalletRepoProvider } from './context';

export const ChainProvider = ({
chains,
Expand Down Expand Up @@ -70,23 +71,25 @@ export const ChainProvider = ({
const withChainProvider = (
modal: (props: WalletModalProps) => JSX.Element
) => (
<ChainProviderLite
chains={chains}
assetLists={assetLists}
wallets={wallets}
walletModal={modal}
throwErrors={throwErrors}
subscribeConnectEvents={subscribeConnectEvents}
defaultNameService={defaultNameService}
walletConnectOptions={walletConnectOptions}
signerOptions={signerOptions}
endpointOptions={endpointOptions}
sessionOptions={sessionOptions}
logLevel={logLevel}
allowedIframeParentOrigins={allowedIframeParentOrigins}
>
{children}
</ChainProviderLite>
<SelectedWalletRepoProvider>
<ChainProviderLite
chains={chains}
assetLists={assetLists}
wallets={wallets}
walletModal={modal}
throwErrors={throwErrors}
subscribeConnectEvents={subscribeConnectEvents}
defaultNameService={defaultNameService}
walletConnectOptions={walletConnectOptions}
signerOptions={signerOptions}
endpointOptions={endpointOptions}
sessionOptions={sessionOptions}
logLevel={logLevel}
allowedIframeParentOrigins={allowedIframeParentOrigins}
>
{children}
</ChainProviderLite>
</SelectedWalletRepoProvider>
);

if (walletModal) {
Expand Down
Loading