Skip to content

Commit

Permalink
Billboard widget enhancements2 (#511)
Browse files Browse the repository at this point in the history
* useAuth stores more than one account

* use empty placeholder if avatar is undefined

* show users message in a different color

* release 0.2.7
  • Loading branch information
AlexNi245 authored Jun 2, 2023
1 parent 2899722 commit 3f0bed7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/billboard-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm3-billboard-widget",
"version": "0.2.6",
"version": "0.2.7",
"files": [
"dist"
],
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions packages/billboard-widget/src/components/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContext } from 'react';
import { GlobalContext } from '../context/GlobalContext';
import AvatarPlaceholder from '../assets/avatar-placeholder.svg';
interface Props {
identifier: string;
}
Expand All @@ -20,9 +21,16 @@ function Avatar(props: Props) {
? avatarSrc
: avatarSrc(identifier)
}
alt={`cute robot avatar of dm3 user: ${identifier}`}
alt={`avatar of ${identifier}`}
/>
) : null}
) : (
<img
width="38px"
height="38px"
src={AvatarPlaceholder}
alt="Avatar image"
/>
)}
</div>
);
}
Expand Down
12 changes: 10 additions & 2 deletions packages/billboard-widget/src/components/MessageItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Message } from 'dm3-lib-messaging';

import { useContext } from 'react';
import { AuthContext } from '../context/AuthContext';
import Avatar from './Avatar';
import MessageFooter from './MessageFooter';

Expand All @@ -11,12 +13,18 @@ interface Props {

function MessageItem(props: Props) {
const { message } = props;
const { ensName } = useContext(AuthContext);

const messageStyle =
'content text-sm ' +
' ' +
(message.metadata.from === ensName ? 'own' : '');

return (
<div className="item-container">
<Avatar identifier={message.metadata.from} />
<div className="message">
<div className="content text-sm">{message.message}</div>
<div className="message ">
<div className={messageStyle}>{message.message}</div>
<MessageFooter {...message.metadata} />
</div>
</div>
Expand Down
21 changes: 14 additions & 7 deletions packages/billboard-widget/src/hooks/useAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import { DeliveryServiceClient } from '../http/DeliveryServiceClient';
import { OffchainResolverClient } from '../http/OffchainResolverClient';
import { ClientProps } from '../types';

const RANDOM_HOTWALLET_KEY = 'Billboard-Random-Hotwallet-Key';
const RANDOM_HOTWALLET_KEY = 'DM3-Hotwallet-Key-';

const getDm3HotWalletKey = (address: string) => {
return RANDOM_HOTWALLET_KEY + address;
};

interface BillboardHotWallet {
keys: ProfileKeys;
Expand All @@ -22,11 +26,6 @@ export const useAuth = (
clientProps: ClientProps,
) => {
const getWallet = async (): Promise<BillboardHotWallet> => {
const hotWallet = localStorage.getItem(RANDOM_HOTWALLET_KEY);
//User has used the widget before hence we have a keypair in the local storage
if (hotWallet) {
return JSON.parse(hotWallet) as BillboardHotWallet;
}
if (
!clientProps.siweAddress ||
!clientProps.siweSig ||
Expand All @@ -35,6 +34,14 @@ export const useAuth = (
throw 'user is not logged in yet';
}

const hotWallet = localStorage.getItem(
getDm3HotWalletKey(clientProps.siweAddress),
);
//User has used the widget before hence we have a keypair in the local storage
if (hotWallet) {
return JSON.parse(hotWallet) as BillboardHotWallet;
}

const deliverServiceProfile = await getDeliveryServiceProfile(
clientProps.deliveryServiceEnsName,
web3Provider,
Expand Down Expand Up @@ -102,7 +109,7 @@ export const useAuth = (

//Keep the KeyPair we just generated in the local storage so we can use them later
localStorage.setItem(
RANDOM_HOTWALLET_KEY,
getDm3HotWalletKey(clientProps.siweAddress),
JSON.stringify(newHotWallet),
);
return newHotWallet;
Expand Down
4 changes: 4 additions & 0 deletions packages/billboard-widget/src/styles/app.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
.common-styles {
--mainBg: #1f2029;
--messageBg: #3a3c50;
--messageBgOwn: #3a3c50;
--messageBg25: rgba(58, 60, 80, 0.25);
--borderInputColor: #b4b8c9;
--inputBg: #434450;
Expand Down Expand Up @@ -158,6 +159,9 @@
white-space: wrap;
}

.own {
background-color: var(--messageBgOwn);
}
.meta {
display: flex;
justify-content: space-between;
Expand Down
23 changes: 12 additions & 11 deletions packages/billboard-widget/src/styles/classic.pcss
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.common-styles {
--mainBg: #FFF;
--messageBg: #F8F8F8;
--messageBg25: #FFF;
--borderInputColor: #E0E0E0;
--inputBg: #FFF;
--mainBg: #fff;
--messageBg: #f8f8f8;
--messageBgOwn: #dfdfdf;
--messageBg25: #fff;
--borderInputColor: #e0e0e0;
--inputBg: #fff;
--textColorPrimary: #000;
--textColorSecondary: #808080;
--borderRadiusS: 0;
Expand All @@ -12,14 +13,14 @@
}

.styled-scrollbars {
--scrollbar-foreground: #FF0050;
--scrollbar-background: #F8F8F8;
--scrollbar-foreground: #ff0050;
--scrollbar-background: #f8f8f8;
}

.dm3-loading-btn {
--timeoutActiveForeground: #FFFFFF;
--timeoutRunningForeground: #FF0050;
--timeoutCircleBackground: #E0E0E0;
--timeoutActiveForeground: #ffffff;
--timeoutRunningForeground: #ff0050;
--timeoutCircleBackground: #e0e0e0;
}

.create-message {
Expand Down Expand Up @@ -47,7 +48,7 @@

&:focus {
outline: none;
border-color: #CCC;
border-color: #ccc;
}
}

Expand Down

0 comments on commit 3f0bed7

Please sign in to comment.