diff --git a/examples/core-connection/src/context/GlobalContext.tsx b/examples/core-connection/src/context/GlobalContext.tsx index 0452590a..1783c6ca 100644 --- a/examples/core-connection/src/context/GlobalContext.tsx +++ b/examples/core-connection/src/context/GlobalContext.tsx @@ -27,7 +27,8 @@ const mockRecipients = [ ]; export const GlobalProvider = ({ children }: { children: ReactNode }) => { - const { account, handleSendSignRequestToPushWallet } = usePushWalletContext(); + const { universalAddress, handleSendSignRequestToPushWallet } = + usePushWalletContext(); const [pushNetwork, setPushNetwork] = useState(null); const [mockTx, setMockTx] = useState(null); @@ -54,7 +55,7 @@ export const GlobalProvider = ({ children }: { children: ReactNode }) => { return ( 15) { const start = str.substring(0, 6); @@ -61,3 +63,11 @@ export const convertCaipToObject = ( }; } }; + +export const convertToCaip = ({ + address, + chain, + chainId, +}: UniversalAddress) => { + return `${chain}:${chainId}:${address}`; +}; diff --git a/examples/core-connection/src/modules/landingPage/components/LandingPageLeftComponent.tsx b/examples/core-connection/src/modules/landingPage/components/LandingPageLeftComponent.tsx index 189f9d7a..5a4e6e04 100644 --- a/examples/core-connection/src/modules/landingPage/components/LandingPageLeftComponent.tsx +++ b/examples/core-connection/src/modules/landingPage/components/LandingPageLeftComponent.tsx @@ -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 '@pushprotocol/pushchain-ui-kit'; const LandingPageLeftComponent = () => { const { pushNetwork, mockTx } = useGlobalContext(); + const { universalAddress } = usePushWalletContext(); + const featuresCard = [ { id: 1, @@ -106,7 +111,13 @@ const LandingPageLeftComponent = () => { justifyContent="center" width="-webkit-fill-available" > - + )} diff --git a/examples/core-connection/src/modules/simulatePage/components/MockSendTransaction.tsx b/examples/core-connection/src/modules/simulatePage/components/MockSendTransaction.tsx index 77d9b822..62bc1b7c 100644 --- a/examples/core-connection/src/modules/simulatePage/components/MockSendTransaction.tsx +++ b/examples/core-connection/src/modules/simulatePage/components/MockSendTransaction.tsx @@ -4,10 +4,14 @@ 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 '@pushprotocol/pushchain-ui-kit'; + 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(null); @@ -15,10 +19,10 @@ const MockSendTransaction = () => { 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); }, diff --git a/examples/core-connection/src/modules/simulatePage/components/SimulateHeader.tsx b/examples/core-connection/src/modules/simulatePage/components/SimulateHeader.tsx index a2a0a748..2ba3ca44 100644 --- a/examples/core-connection/src/modules/simulatePage/components/SimulateHeader.tsx +++ b/examples/core-connection/src/modules/simulatePage/components/SimulateHeader.tsx @@ -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 '@pushprotocol/pushchain-ui-kit'; const SimulateHeader = () => { - const { account } = useGlobalContext(); + const { universalAddress } = usePushWalletContext(); return ( - {account && } + ); }; diff --git a/examples/core-connection/yarn.lock b/examples/core-connection/yarn.lock index dd372d31..2b906a5d 100644 --- a/examples/core-connection/yarn.lock +++ b/examples/core-connection/yarn.lock @@ -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" @@ -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 diff --git a/packages/ui-kit/src/lib/common/spinner/Spinner.tsx b/packages/ui-kit/src/lib/common/spinner/Spinner.tsx index d920871a..db3b79ff 100644 --- a/packages/ui-kit/src/lib/common/spinner/Spinner.tsx +++ b/packages/ui-kit/src/lib/common/spinner/Spinner.tsx @@ -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 ( - - - - ); + return ( + + + + ); }; export default Spinner; diff --git a/packages/ui-kit/src/lib/wallet/components/ConnectPushWalletButton.tsx b/packages/ui-kit/src/lib/wallet/components/ConnectPushWalletButton.tsx index 6f13e5c7..e6eab5b9 100644 --- a/packages/ui-kit/src/lib/wallet/components/ConnectPushWalletButton.tsx +++ b/packages/ui-kit/src/lib/wallet/components/ConnectPushWalletButton.tsx @@ -1,14 +1,18 @@ -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 = () => { +const ConnectPushWalletButton: FC = ({ + title, + styling, +}) => { const { connectionStatus, handleConnectToPushWallet, @@ -34,9 +38,14 @@ const ConnectPushWalletButton: FC = () => { - {walletConnectionButtonStatusMapper[connectionStatus]} - {isLoading && ()} + {connectionStatus === 'notConnected' ? title : connectionStatus} + {isLoading && ( + + + + )} ); @@ -44,31 +53,39 @@ const ConnectPushWalletButton: FC = () => { 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; -` \ No newline at end of file + padding: 4px; +`; diff --git a/packages/ui-kit/src/lib/wallet/components/PushWalletButton.tsx b/packages/ui-kit/src/lib/wallet/components/PushWalletButton.tsx new file mode 100644 index 00000000..f16e0c41 --- /dev/null +++ b/packages/ui-kit/src/lib/wallet/components/PushWalletButton.tsx @@ -0,0 +1,28 @@ +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 = ({ + universalAddress, + component, + title = 'Login', + styling, +}) => { + // If universal address is present render the button + if (universalAddress) { + return ; + } else if (component) { + // If no UA and custom component, then render the component + return <>{component}; + } else return ; // If no UA and no custom component, then render the connect button +}; + +export { PushWalletButton }; diff --git a/packages/ui-kit/src/lib/wallet/components/PushWalletIFrame.tsx b/packages/ui-kit/src/lib/wallet/components/PushWalletIFrame.tsx deleted file mode 100644 index 2ca32cc2..00000000 --- a/packages/ui-kit/src/lib/wallet/components/PushWalletIFrame.tsx +++ /dev/null @@ -1,174 +0,0 @@ -import { FC } from 'react'; -import { usePushWalletContext } from './PushWalletProvider'; -import config from '../../config'; -import styled from 'styled-components'; -import { CrossIcon, DashIcon, Spinner } from '../../common'; - -const PushWalletIFrame: FC = () => { - const { - env, - account, - iframeRef, - isWalletMinimised, - isWalletVisible, - setMinimiseWallet, - handleUserLogOutEvent, - isIframeLoading, - setIframeLoading, - } = usePushWalletContext(); - - return ( - <> - {isWalletVisible ? ( - - {isIframeLoading && ( - - { - handleUserLogOutEvent(); - }} - > - - - - Loading... - - - - )} - - - - {account ? ( - setMinimiseWallet(true)}> - - - ) : ( - { - handleUserLogOutEvent(); - }} - > - - - )} - -