Skip to content

Commit

Permalink
Merge pull request #17 from push-protocol/SIMULATE-16-Retry-logic-for…
Browse files Browse the repository at this point in the history
…-Connect-Push-Wallet-Button

Fixed the retry logic for ConnectPushWallet Button
  • Loading branch information
rohitmalhotra1420 authored Dec 9, 2024
2 parents d14b261 + 066a786 commit f56b14d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ConnectPushWalletButtonProps = {
};

const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = () => {
const { connectionStatus, handleConnectToPushWallet } =
const { connectionStatus, handleConnectToPushWallet, handleNewConnectionRequest } =
usePushWalletContext();

const isConnectButtonDisbaled =
Expand All @@ -18,11 +18,15 @@ const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = () => {
const isLoading =
connectionStatus === 'connecting' || connectionStatus === 'authenticating';

const handleConnectWalletButton = () => {
connectionStatus === 'retry' ? handleNewConnectionRequest() : handleConnectToPushWallet()
}

return (
<div>
<button
className="send-button"
onClick={handleConnectToPushWallet}
onClick={handleConnectWalletButton}
disabled={isConnectButtonDisbaled}
style={{
backgroundColor: '#d548ec',
Expand Down
9 changes: 4 additions & 5 deletions packages/ui-kit/src/lib/wallet/components/WalletProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type WalletContextType = {
account: string | null;
connectionStatus: ConnectionStatus;
handleConnectToPushWallet: () => void;
handleNewConnectionRequest: () => void;
handleSendSignRequestToPushWallet: (data: Uint8Array) => Promise<Uint8Array>;
};

Expand Down Expand Up @@ -72,6 +73,7 @@ export const WalletProvider: React.FC<WalletProviderProps> = ({
};

const handleNewConnectionRequest = () => {
setConnectionStatus('authenticating');
sendMessageToPushWallet({
type: APP_TO_WALLET_ACTION.NEW_CONNECTION_REQUEST,
});
Expand All @@ -82,7 +84,6 @@ export const WalletProvider: React.FC<WalletProviderProps> = ({
setConnectionStatus('connected');
setAccount(response.account);
} else {
setConnectionStatus('authenticating');
handleNewConnectionRequest();
}
};
Expand All @@ -93,17 +94,14 @@ export const WalletProvider: React.FC<WalletProviderProps> = ({
};

const handleAppConnectionRejection = () => {
setConnectionStatus('notConnected');
setConnectionStatus('retry');
setAccount(null);
};

const handleUserLogOutEvent = () => {
// TODO: Fix this case
setConnectionStatus('notConnected');
setAccount(null);

// TODO: Fix this afterwards
window.location.reload();
};

const handleWalletTabClosed = () => {
Expand Down Expand Up @@ -197,6 +195,7 @@ export const WalletProvider: React.FC<WalletProviderProps> = ({
connectionStatus,
handleConnectToPushWallet,
handleSendSignRequestToPushWallet,
handleNewConnectionRequest,
}}
>
{children}
Expand Down
18 changes: 11 additions & 7 deletions packages/ui-kit/src/lib/wallet/wallet.constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ConnectionStatus } from "./wallet.types";
import { ConnectionStatus } from './wallet.types';

export const walletConnectionButtonStatusMapper: Record<ConnectionStatus, string> = {
notConnected: "Connect to Push Wallet",
connecting: "Connecting to Push Wallet",
authenticating: "Authenticating Push Wallet",
connected: "Connected to Push Wallet",
}
export const walletConnectionButtonStatusMapper: Record<
ConnectionStatus,
string
> = {
notConnected: 'Connect to Push Wallet',
connecting: 'Connecting to Push Wallet',
authenticating: 'Authenticating Push Wallet',
connected: 'Connected to Push Wallet',
retry: 'Retry Connecting to Push Wallet',
};
3 changes: 2 additions & 1 deletion packages/ui-kit/src/lib/wallet/wallet.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export type ConnectionStatus =
| 'notConnected'
| 'connecting'
| 'authenticating'
| 'connected';
| 'connected'
| 'retry';

export type WalletEventRespoonse = {
signature?: Uint8Array;
Expand Down

0 comments on commit f56b14d

Please sign in to comment.