Skip to content

Commit 9aef816

Browse files
Merge pull request #52 from push-protocol/UI-KIT-49-fixed-ui-kit-export-for-account
Redefining UI-Kit component and functions exports
2 parents 4be018f + 295aad8 commit 9aef816

File tree

15 files changed

+183
-313
lines changed

15 files changed

+183
-313
lines changed

examples/core-connection/src/context/GlobalContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ const mockRecipients = [
2727
];
2828

2929
export const GlobalProvider = ({ children }: { children: ReactNode }) => {
30-
const { account, handleSendSignRequestToPushWallet } = usePushWalletContext();
30+
const { universalAddress, handleSendSignRequestToPushWallet } =
31+
usePushWalletContext();
3132

3233
const [pushNetwork, setPushNetwork] = useState<PushNetwork | null>(null);
3334
const [mockTx, setMockTx] = useState<Transaction | null>(null);
@@ -54,7 +55,7 @@ export const GlobalProvider = ({ children }: { children: ReactNode }) => {
5455
return (
5556
<GlobalContext.Provider
5657
value={{
57-
account,
58+
account: universalAddress ? universalAddress.address : null,
5859
pushNetwork,
5960
mockTx,
6061
handleSendSignRequestToPushWallet,

examples/core-connection/src/helpers/walletHelper.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UniversalAddress } from '@pushprotocol/pushchain-ui-kit';
2+
13
export function centerMaskString(str: string) {
24
if (str && str.length > 15) {
35
const start = str.substring(0, 6);
@@ -61,3 +63,11 @@ export const convertCaipToObject = (
6163
};
6264
}
6365
};
66+
67+
export const convertToCaip = ({
68+
address,
69+
chain,
70+
chainId,
71+
}: UniversalAddress) => {
72+
return `${chain}:${chainId}:${address}`;
73+
};

examples/core-connection/src/modules/landingPage/components/LandingPageLeftComponent.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import { css } from 'styled-components';
22
import { Box, Button, Front, Sale, Text } from 'shared-components';
3-
import { ConnectPushWalletButton } from '@pushprotocol/pushchain-ui-kit';
43
import { useGlobalContext } from '../../../context/GlobalContext';
54
import { LandingPageBanner } from './LandingPageBanner';
65
import { SimulateTxText } from './SimulateTxText';
6+
import {
7+
PushWalletButton,
8+
usePushWalletContext,
9+
} from '@pushprotocol/pushchain-ui-kit';
710

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

14+
const { universalAddress } = usePushWalletContext();
15+
1116
const featuresCard = [
1217
{
1318
id: 1,
@@ -106,7 +111,13 @@ const LandingPageLeftComponent = () => {
106111
justifyContent="center"
107112
width="-webkit-fill-available"
108113
>
109-
<ConnectPushWalletButton />
114+
<PushWalletButton
115+
universalAddress={universalAddress}
116+
title="Connect Push Wallet"
117+
styling={{
118+
width: 'inherit',
119+
}}
120+
/>
110121
</Box>
111122
)}
112123

examples/core-connection/src/modules/simulatePage/components/MockSendTransaction.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ import { css } from 'styled-components';
44
import { TransactionSnippet } from '../../../common/components';
55
import { useGlobalContext } from '../../../context/GlobalContext';
66
import { Transaction } from '@pushprotocol/push-chain/src/lib/generated/tx';
7-
import { centerMaskString } from '../../../helpers';
7+
import { centerMaskString, convertToCaip } from '../../../helpers';
8+
import { usePushWalletContext } from '@pushprotocol/pushchain-ui-kit';
9+
810
const MockSendTransaction = () => {
9-
const { pushNetwork, mockTx, account, handleSendSignRequestToPushWallet } =
10-
useGlobalContext();
11+
const { pushNetwork, mockTx } = useGlobalContext();
12+
13+
const { handleSendSignRequestToPushWallet, universalAddress } =
14+
usePushWalletContext();
1115

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

1620
const handleSendTransaction = async (mockTx: Transaction) => {
1721
try {
18-
if (pushNetwork && account) {
22+
if (pushNetwork && universalAddress) {
1923
setIsSendingTxn(true);
2024
const txHash = await pushNetwork.tx.send(mockTx, {
21-
account,
25+
account: convertToCaip(universalAddress), // This will get changed to utils usage in pushchain devnet package
2226
signMessage: async (data: Uint8Array) => {
2327
return await handleSendSignRequestToPushWallet(data);
2428
},

examples/core-connection/src/modules/simulatePage/components/SimulateHeader.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { Box } from 'shared-components';
2-
import { useGlobalContext } from '../../../context/GlobalContext';
3-
import { TogglePushWalletButton } from '@pushprotocol/pushchain-ui-kit';
2+
import {
3+
PushWalletButton,
4+
usePushWalletContext,
5+
} from '@pushprotocol/pushchain-ui-kit';
46

57
const SimulateHeader = () => {
6-
const { account } = useGlobalContext();
8+
const { universalAddress } = usePushWalletContext();
79

810
return (
911
<Box display="flex" justifyContent="end" width="100%">
10-
{account && <TogglePushWalletButton account={account} />}
12+
<PushWalletButton universalAddress={universalAddress} />
1113
</Box>
1214
);
1315
};

examples/core-connection/yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,7 +6822,7 @@ __metadata:
68226822

68236823
"shared-components@file:../../packages/shared-components::locator=core-connection%40workspace%3A.":
68246824
version: 0.1.0
6825-
resolution: "shared-components@file:../../packages/shared-components#../../packages/shared-components::hash=7ec6fd&locator=core-connection%40workspace%3A."
6825+
resolution: "shared-components@file:../../packages/shared-components#../../packages/shared-components::hash=9fe31a&locator=core-connection%40workspace%3A."
68266826
dependencies:
68276827
"@emotion/react": "npm:^11.13.0"
68286828
"@radix-ui/react-dialog": "npm:^1.1.1"
@@ -6843,7 +6843,7 @@ __metadata:
68436843
peerDependencies:
68446844
react: ^18.3.1
68456845
react-dom: ^18.3.1
6846-
checksum: 10/043be10cccbe754a00ed3a41688d8cdbca487e56abe72b78aded4e7617ed723c5e08314960c3b410356b57475d28ac0162119ffff0c7516f0e465d97bc5f3d37
6846+
checksum: 10/7d96c35a77cdbd873e64bb718d9fa8f44607528009e0586c7100f24b6a77d47ba5a89b2ee715086738fc39e6413a3880a32f1e32e53adedd86b586cce29fcbda
68476847
languageName: node
68486848
linkType: hard
68496849

packages/ui-kit/src/lib/common/spinner/Spinner.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ const Container = styled.div`
1818
align-items: center;
1919
justify-content: center;
2020
animation: ${spin} 1s linear infinite;
21-
width: 24px;
22-
height: 24px;
23-
color:#D548EC;
21+
width: 20px;
22+
height: 20px;
23+
color: #fff;
2424
`;
2525

2626
// Spinner functional component
2727
const Spinner = () => {
28-
return (
29-
<Container>
30-
<Ellipse />
31-
</Container>
32-
);
28+
return (
29+
<Container>
30+
<Ellipse />
31+
</Container>
32+
);
3333
};
3434

3535
export default Spinner;
Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { FC } from 'react';
1+
import React, { FC } from 'react';
22
import { usePushWalletContext } from './PushWalletProvider';
3-
import { walletConnectionButtonStatusMapper } from '../wallet.constants';
4-
import styled from 'styled-components'
3+
import styled from 'styled-components';
54
import { Spinner } from '../../common';
65

76
export type ConnectPushWalletButtonProps = {
87
showLogOutButton?: boolean;
8+
title?: string;
9+
styling?: React.CSSProperties;
910
};
1011

11-
const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = () => {
12+
const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = ({
13+
title,
14+
styling,
15+
}) => {
1216
const {
1317
connectionStatus,
1418
handleConnectToPushWallet,
@@ -34,41 +38,54 @@ const ConnectPushWalletButton: FC<ConnectPushWalletButtonProps> = () => {
3438
<ConnectButton
3539
onClick={handleConnectWalletButton}
3640
disabled={isConnectButtonDisbaled || isLoading}
41+
customStyle={styling}
3742
>
38-
{walletConnectionButtonStatusMapper[connectionStatus]}
39-
{isLoading && (<SpinnerContainer><Spinner /></SpinnerContainer>)}
43+
{connectionStatus === 'notConnected' ? title : connectionStatus}
44+
{isLoading && (
45+
<SpinnerContainer>
46+
<Spinner />
47+
</SpinnerContainer>
48+
)}
4049
</ConnectButton>
4150
</>
4251
);
4352
};
4453

4554
export { ConnectPushWalletButton };
4655

47-
const ConnectButton = styled.button`
48-
align-items: center;
49-
cursor: pointer;
50-
display: flex;
51-
justify-content: center;
52-
white-space: nowrap;
53-
flex-shrink: 0;
54-
border: none;
55-
background-color: #D548EC;
56-
color: rgba(255,255,255,1);
57-
border-radius: 12px;
58-
gap: 4px;
59-
height: 48px;
60-
padding: 16px 24px;
61-
min-width: 100px;
62-
leading-trim: both;
63-
text-edge: cap;
64-
font-family:FK Grotesk Neu;
65-
font-size: 16px;
66-
font-style: normal;
67-
font-weight: 500;
68-
line-height: 16px;
69-
width:inherit;
56+
const ConnectButton = styled.button<{ customStyle?: React.CSSProperties }>`
57+
align-items: center;
58+
cursor: pointer;
59+
display: flex;
60+
justify-content: center;
61+
white-space: nowrap;
62+
flex-shrink: 0;
63+
border: none;
64+
background-color: #d548ec;
65+
color: rgba(255, 255, 255, 1);
66+
border-radius: 12px;
67+
gap: 4px;
68+
height: 48px;
69+
padding: 16px 24px;
70+
min-width: 100px;
71+
leading-trim: both;
72+
text-edge: cap;
73+
font-family: FK Grotesk Neu;
74+
font-size: 16px;
75+
font-style: normal;
76+
font-weight: 500;
77+
line-height: 16px;
78+
width: inherit;
7079
71-
`
80+
${(props) =>
81+
props.customStyle &&
82+
Object.entries(props.customStyle)
83+
.map(
84+
([key, value]) =>
85+
`${key.replace(/([A-Z])/g, '-$1').toLowerCase()}: ${value};`
86+
)
87+
.join('\n')}
88+
`;
7289
const SpinnerContainer = styled.div`
73-
padding:5px;
74-
`
90+
padding: 4px;
91+
`;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React, { ReactNode } from 'react';
2+
import { ConnectPushWalletButton } from './ConnectPushWalletButton';
3+
import { TogglePushWalletButton } from './TogglePushWalletButton';
4+
import { UniversalAddress } from '../wallet.types';
5+
6+
type PushWalletButtonProps = {
7+
universalAddress: UniversalAddress | null;
8+
component?: ReactNode;
9+
title?: string;
10+
styling?: React.CSSProperties;
11+
};
12+
13+
const PushWalletButton: React.FC<PushWalletButtonProps> = ({
14+
universalAddress,
15+
component,
16+
title = 'Login',
17+
styling,
18+
}) => {
19+
// If universal address is present render the button
20+
if (universalAddress) {
21+
return <TogglePushWalletButton universalAddress={universalAddress} />;
22+
} else if (component) {
23+
// If no UA and custom component, then render the component
24+
return <>{component}</>;
25+
} else return <ConnectPushWalletButton title={title} styling={styling} />; // If no UA and no custom component, then render the connect button
26+
};
27+
28+
export { PushWalletButton };

0 commit comments

Comments
 (0)