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

Redefining UI-Kit component and functions exports #52

Merged
merged 5 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion examples/core-connection/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getBlocksCSSVariables, themeConfig } from 'shared-components';
import { useDarkMode } from './common/hooks';
import { RouterContainer } from './common/components';
import { GlobalProvider } from './context/GlobalContext';
import { CONSTANTS, PushWalletProvider } from '@pushprotocol/pushchain-ui-kit';
import { CONSTANTS, PushWalletProvider } from '../../../packages/ui-kit';

const GlobalStyle = createGlobalStyle`
:root{
Expand Down
1 change: 1 addition & 0 deletions examples/core-connection/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const APP_ROUTES = {
LANDING_PAGE: '/',
SIMULATE: '/simulate',
WALLETPAGE: '/wallet-page',
};
7 changes: 4 additions & 3 deletions examples/core-connection/src/context/GlobalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
useEffect,
useState,
} from 'react';
import { usePushWalletContext } from '@pushprotocol/pushchain-ui-kit';
import { usePushWalletContext } from '../../../../packages/ui-kit';

// Define a type for the context value
type GlobalContextType = {
Expand All @@ -27,7 +27,8 @@ const mockRecipients = [
];

export const GlobalProvider = ({ children }: { children: ReactNode }) => {
const { account, handleSendSignRequestToPushWallet } = usePushWalletContext();
const { universalAddress, handleSendSignRequestToPushWallet } =
usePushWalletContext();

const [pushNetwork, setPushNetwork] = useState<PushNetwork | null>(null);
const [mockTx, setMockTx] = useState<Transaction | null>(null);
Expand All @@ -54,7 +55,7 @@ export const GlobalProvider = ({ children }: { children: ReactNode }) => {
return (
<GlobalContext.Provider
value={{
account,
account: universalAddress ? universalAddress.address : null,
pushNetwork,
mockTx,
handleSendSignRequestToPushWallet,
Expand Down
10 changes: 10 additions & 0 deletions examples/core-connection/src/helpers/walletHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UniversalAddress } from '../../../../packages/ui-kit/src';

export function centerMaskString(str: string) {
if (str && str.length > 15) {
const start = str.substring(0, 6);
Expand Down Expand Up @@ -61,3 +63,11 @@ export const convertCaipToObject = (
};
}
};

export const convertToCaip = ({
address,
chain,
chainId,
}: UniversalAddress) => {
return `${chain}:${chainId}:${address}`;
};
59 changes: 59 additions & 0 deletions examples/core-connection/src/modules/WalletTestPage/WalletPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import {
usePushWalletContext,
centerMaskString,
PushWalletButton,
} from '../../../../../packages/ui-kit/src';
import { Box, Button, Text } from 'shared-components';

const WalletPage = () => {
const { universalAddress } = usePushWalletContext();
console.log('Universal Address', universalAddress);

return (
<Box display="flex" flexDirection="column" gap="spacing-lg">
<Text variant="h3-bold">Wallet Page Example</Text>
<Box display="flex" flexDirection="column" gap="spacing-lg">
<Box display="flex" flexDirection="column" gap="spacing-xxs">
<Text variant="h6-regular">Default Button:</Text>
<PushWalletButton universalAddress={universalAddress} />
</Box>
<Box display="flex" flexDirection="column" gap="spacing-xxs">
<Text variant="h6-regular">Custom Title:</Text>
<PushWalletButton
universalAddress={universalAddress}
title="Connect Wallet"
/>
</Box>
<Box display="flex" flexDirection="column" gap="spacing-xxs">
<Text variant="h6-regular">Custom Style Button:</Text>
<PushWalletButton
universalAddress={universalAddress}
styling={{
backgroundColor: '#10B981',
borderRadius: '9999px',
padding: '12px 24px',
}}
/>
</Box>
<Box display="flex" flexDirection="column" gap="spacing-xxs">
<Text variant="h6-regular">Custom Component Button:</Text>
<PushWalletButton
universalAddress={universalAddress}
component={
<Button variant="secondary">
{universalAddress ? (
<>{centerMaskString(universalAddress.address)}</>
) : (
<> Connect With Push Wallet</>
)}
</Button>
}
/>
</Box>
</Box>
</Box>
);
};

export default WalletPage;
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { css } from 'styled-components';
import { Box, Button, Front, Sale, Text } from 'shared-components';
import { ConnectPushWalletButton } from '@pushprotocol/pushchain-ui-kit';
import { useGlobalContext } from '../../../context/GlobalContext';
import { LandingPageBanner } from './LandingPageBanner';
import { SimulateTxText } from './SimulateTxText';
import {
PushWalletButton,
usePushWalletContext,
} from '../../../../../../packages/ui-kit/src';

const LandingPageLeftComponent = () => {
const { pushNetwork, mockTx } = useGlobalContext();

const { universalAddress } = usePushWalletContext();

const featuresCard = [
{
id: 1,
Expand Down Expand Up @@ -106,7 +111,13 @@ const LandingPageLeftComponent = () => {
justifyContent="center"
width="-webkit-fill-available"
>
<ConnectPushWalletButton />
<PushWalletButton
universalAddress={universalAddress}
title="Connect Push Wallet"
styling={{
width: 'inherit',
}}
/>
</Box>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import { css } from 'styled-components';
import { TransactionSnippet } from '../../../common/components';
import { useGlobalContext } from '../../../context/GlobalContext';
import { Transaction } from '@pushprotocol/push-chain/src/lib/generated/tx';
import { centerMaskString } from '../../../helpers';
import { centerMaskString, convertToCaip } from '../../../helpers';
import { usePushWalletContext } from '../../../../../../packages/ui-kit/src';

const MockSendTransaction = () => {
const { pushNetwork, mockTx, account, handleSendSignRequestToPushWallet } =
useGlobalContext();
const { pushNetwork, mockTx } = useGlobalContext();

const { handleSendSignRequestToPushWallet, universalAddress } =
usePushWalletContext();

const [isSendingTxn, setIsSendingTxn] = useState(false);
const [txnHash, setTxnHash] = useState<string | null>(null);
const [txnError, setTxnError] = useState<unknown | null>(null);

const handleSendTransaction = async (mockTx: Transaction) => {
try {
if (pushNetwork && account) {
if (pushNetwork && universalAddress) {
setIsSendingTxn(true);
const txHash = await pushNetwork.tx.send(mockTx, {
account,
account: convertToCaip(universalAddress), // This will get changed to utils usage in pushchain devnet package
signMessage: async (data: Uint8Array) => {
return await handleSendSignRequestToPushWallet(data);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Box } from 'shared-components';
import { useGlobalContext } from '../../../context/GlobalContext';
import { TogglePushWalletButton } from '@pushprotocol/pushchain-ui-kit';
import {
PushWalletButton,
usePushWalletContext,
} from '../../../../../../packages/ui-kit';

const SimulateHeader = () => {
const { account } = useGlobalContext();
const { universalAddress } = usePushWalletContext();

return (
<Box display="flex" justifyContent="end" width="100%">
{account && <TogglePushWalletButton account={account} />}
<PushWalletButton universalAddress={universalAddress} />
</Box>
);
};
Expand Down
4 changes: 2 additions & 2 deletions examples/core-connection/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6822,7 +6822,7 @@ __metadata:

"shared-components@file:../../packages/shared-components::locator=core-connection%40workspace%3A.":
version: 0.1.0
resolution: "shared-components@file:../../packages/shared-components#../../packages/shared-components::hash=7ec6fd&locator=core-connection%40workspace%3A."
resolution: "shared-components@file:../../packages/shared-components#../../packages/shared-components::hash=9fe31a&locator=core-connection%40workspace%3A."
dependencies:
"@emotion/react": "npm:^11.13.0"
"@radix-ui/react-dialog": "npm:^1.1.1"
Expand All @@ -6843,7 +6843,7 @@ __metadata:
peerDependencies:
react: ^18.3.1
react-dom: ^18.3.1
checksum: 10/043be10cccbe754a00ed3a41688d8cdbca487e56abe72b78aded4e7617ed723c5e08314960c3b410356b57475d28ac0162119ffff0c7516f0e465d97bc5f3d37
checksum: 10/7d96c35a77cdbd873e64bb718d9fa8f44607528009e0586c7100f24b6a77d47ba5a89b2ee715086738fc39e6413a3880a32f1e32e53adedd86b586cce29fcbda
languageName: node
linkType: hard

Expand Down
16 changes: 8 additions & 8 deletions packages/ui-kit/src/lib/common/spinner/Spinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ const Container = styled.div`
align-items: center;
justify-content: center;
animation: ${spin} 1s linear infinite;
width: 24px;
height: 24px;
color:#D548EC;
width: 20px;
height: 20px;
color: #fff;
`;

// Spinner functional component
const Spinner = () => {
return (
<Container>
<Ellipse />
</Container>
);
return (
<Container>
<Ellipse />
</Container>
);
};

export default Spinner;
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { FC } from 'react';
import React, { FC } from 'react';
import { usePushWalletContext } from './PushWalletProvider';
import { walletConnectionButtonStatusMapper } from '../wallet.constants';
import styled from 'styled-components'
import styled from 'styled-components';
import { Spinner } from '../../common';

export type ConnectPushWalletButtonProps = {
showLogOutButton?: boolean;
title?: string;
styling?: React.CSSProperties;
};

const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = () => {
const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = ({
title,
styling,
}) => {
const {
connectionStatus,
handleConnectToPushWallet,
Expand All @@ -34,41 +39,55 @@ const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = () => {
<ConnectButton
onClick={handleConnectWalletButton}
disabled={isConnectButtonDisbaled || isLoading}
customStyle={styling}
>
{walletConnectionButtonStatusMapper[connectionStatus]}
{isLoading && (<SpinnerContainer><Spinner /></SpinnerContainer>)}
{/* {walletConnectionButtonStatusMapper[connectionStatus]} */}
{connectionStatus === 'notConnected' ? title : connectionStatus}
{isLoading && (
<SpinnerContainer>
<Spinner />
</SpinnerContainer>
)}
</ConnectButton>
</>
);
};

export { ConnectPushWalletButton };

const ConnectButton = styled.button`
align-items: center;
cursor: pointer;
display: flex;
justify-content: center;
white-space: nowrap;
flex-shrink: 0;
border: none;
background-color: #D548EC;
color: rgba(255,255,255,1);
border-radius: 12px;
gap: 4px;
height: 48px;
padding: 16px 24px;
min-width: 100px;
leading-trim: both;
text-edge: cap;
font-family:FK Grotesk Neu;
font-size: 16px;
font-style: normal;
font-weight: 500;
line-height: 16px;
width:inherit;
const ConnectButton = styled.button<{ customStyle?: React.CSSProperties }>`
align-items: center;
cursor: pointer;
display: flex;
justify-content: center;
white-space: nowrap;
flex-shrink: 0;
border: none;
background-color: #d548ec;
color: rgba(255, 255, 255, 1);
border-radius: 12px;
gap: 4px;
height: 48px;
padding: 16px 24px;
min-width: 100px;
leading-trim: both;
text-edge: cap;
font-family: FK Grotesk Neu;
font-size: 16px;
font-style: normal;
font-weight: 500;
line-height: 16px;
width: inherit;

`
${(props) =>
props.customStyle &&
Object.entries(props.customStyle)
.map(
([key, value]) =>
`${key.replace(/([A-Z])/g, '-$1').toLowerCase()}: ${value};`
)
.join('\n')}
`;
const SpinnerContainer = styled.div`
padding:5px;
`
padding: 4px;
`;
35 changes: 35 additions & 0 deletions packages/ui-kit/src/lib/wallet/components/PushWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { ReactNode } from 'react';
import { ConnectPushWalletButton } from './ConnectPushWalletButton';
import { TogglePushWalletButton } from './TogglePushWalletButton';
import { UniversalAddress } from '../wallet.types';

type PushWalletButtonProps = {
universalAddress: UniversalAddress | null;
component?: ReactNode;
title?: string;
styling?: React.CSSProperties;
};

const PushWalletButton: React.FC<PushWalletButtonProps> = ({
universalAddress,
component,
title = 'Login',
styling,
}) => {
// If a custom component is provided, render it
if (component) {
abhishek-01k marked this conversation as resolved.
Show resolved Hide resolved
return <>{component}</>;
}

return (
<>
{universalAddress ? (
<TogglePushWalletButton universalAddress={universalAddress} />
) : (
<ConnectPushWalletButton title={title} styling={styling} />
)}
</>
);
};

export { PushWalletButton };
Loading