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

Feat/community onboarding #19

Merged
merged 27 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
253df70
added check for user discord details
rushidhanwant Mar 15, 2023
71d5746
fixed community list panel ui | added create communit button
rushidhanwant Mar 15, 2023
6e1e256
user reducer and thunk to updated the user's redux state
rushidhanwant Mar 16, 2023
7e6f904
dispatch thunk to update user details when wallet address is updated
rushidhanwant Mar 16, 2023
425ffc1
index.ts
rushidhanwant Mar 16, 2023
e896217
fixed community list panel ui and added create community button
rushidhanwant Mar 16, 2023
00ddb2d
added tests for redux store
ap-atul Mar 15, 2023
eea4ae9
added tests for fp ts
ap-atul Mar 15, 2023
3e61c54
added and updated query to fetch single thread
ap-atul Mar 16, 2023
660fc18
updated avatar card with link comp
ap-atul Mar 16, 2023
80fa047
updated thread info component with tests
ap-atul Mar 16, 2023
dea4840
refactored thread details component
ap-atul Mar 16, 2023
ab57fe6
added secondary button with loading animation
ap-atul Mar 16, 2023
1ac7e36
refactored comment component and added tests
ap-atul Mar 16, 2023
05de06d
added thread details page with commenting
ap-atul Mar 16, 2023
718d013
upated query
rushidhanwant Mar 20, 2023
0e8e2fe
optional check
rushidhanwant Mar 20, 2023
d43360b
updated redux to store user state and did session
rushidhanwant Mar 20, 2023
8bb928f
added community router and apis to create/update community and social…
rushidhanwant Mar 20, 2023
7850629
integrated community onboard and interface model | composedb integra…
rushidhanwant Mar 20, 2023
9b8092b
updated interface model to take user/commuity prop
rushidhanwant Mar 20, 2023
ba6f6f0
integration with discord oauth url to add bot to dicord server and f…
rushidhanwant Mar 20, 2023
01d544e
removed useLocastorge hook and added states in redux
rushidhanwant Mar 20, 2023
ca4d2c2
added function to discord avatar url using guildId and icon hash
rushidhanwant Mar 20, 2023
29c6054
added update did reducer function and initialised states with null
rushidhanwant Mar 20, 2023
cb815b6
resolved build issues and updated comment router
ap-atul Mar 21, 2023
434abd8
merged dev and resolved conflicts
ap-atul Mar 21, 2023
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
4 changes: 2 additions & 2 deletions apps/discord-bot/src/handlers/onCommentCreateWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export const onCommentCreateWeb = async (

const user = await queryHandler.fetchUserDetailsFromPlatformId("discord",platformId )

if (user == null || !user.node ) {
if (user == null || !user?.node ) {
return {
result: false,
value: "user not signed in from discord or did session has expired",
};
}

const {id} = user.node;
const {id} = user?.node;

if (existhreaingThread) {
const thread = client.channels.cache.get(
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot/src/handlers/onMessageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ export const onMessageCreate = async (message: Message) => {
.catch(() => {
return null;
});
const {id} = user.node;
const {id} = user?.node;
//If the user does not have a devnode account, delete it and tell the user to create one
if (user == null || !user.node) {
if (user == null || !user?.node) {
await new Promise((r) => setTimeout(r, 3000));

if (existingMessage) {
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot/src/handlers/onThreadCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const onThreadCreate = async (thread: ThreadChannel) => {

const user = await queryHandler.fetchUserDetailsFromPlatformId("discord", threadOwner.user.id);

if (user == null || !user.node) {
if (user == null || !user?.node) {
//User account does not exist at all
await new Promise((r) => setTimeout(r, 3000));

Expand All @@ -63,7 +63,7 @@ export const onThreadCreate = async (thread: ThreadChannel) => {
const socialPlatform = await queryHandler.fetchSocialPlatform(thread.guildId as string);
const {communityId } = socialPlatform.node;

const {id} = user.node;
const {id} = user?.node;

const threadDetails = {
communityId: communityId as string,
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot/src/handlers/onThreadCreateWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export const onThreadCreateWeb = async (
if (!channel) return { result: false, value: "channel missing" };

const user = await queryHandler.fetchUserDetailsFromPlatformId("discord", platformId);
if (user == null || !user.node ) {
if (user == null || !user?.node ) {
return {
result: false,
value: "user not signed in from discord or did session has expired",
};
}

const {id} = user.node;
const {id} = user?.node;

const socialPlatform = await queryHandler.fetchSocialPlatform(community as string);
const {communityId } = socialPlatform.node;
Expand Down
4 changes: 2 additions & 2 deletions apps/discord-bot/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ const updateCommunities = async () => {


const socialPlatformInput = {
userId: userRespose.data.createUser.document.id as string,
userId: userRespose.data.createUser?.document?.id as string,
platform: "discord",
platformId: guild?.id as string,
communityId: communityRespose.data.createCommunity.document.id as string,
communityId: communityRespose.data.createCommunity?.document?.id as string,
communityName: guild.name,
communityAvatar: guild.iconURL() || "",
};
Expand Down
Binary file added apps/web/public/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import {useWeb3Modal} from '@web3modal/react';
import {useState} from 'react';
import {useAccount, useDisconnect} from 'wagmi';
import { useWeb3Modal } from "@web3modal/react";
import { useState } from "react";
import { useAccount, useDisconnect } from "wagmi";
import * as utils from "../../../utils";
import {EthereumWebAuth, getAccountId} from "@didtools/pkh-ethereum";
import {DIDSession} from "did-session";
import {config} from "../../../config";
import {toast} from "react-toastify";
import useLocalStorage from "../../../hooks/useLocalStorage";
import {ConnectWalletProps} from "./types";
import { EthereumWebAuth, getAccountId } from "@didtools/pkh-ethereum";
import { DIDSession } from "did-session";
import { config } from "../../../config";
import { toast } from "react-toastify";
import { ConnectWalletProps } from "./types";
import { useAppDispatch, updateDidSession, updateDid } from "../../../store";

export const ConnectWalletButton = (props: ConnectWalletProps) => {
const {open} = useWeb3Modal()
const {disconnect} = useDisconnect()
const [loading, setLoading] = useState(false)
const [, setDid, removeDid] = useLocalStorage("did", "");

const { open } = useWeb3Modal();
const { disconnect } = useDisconnect();
const [loading, setLoading] = useState(false);
const dispatch = useAppDispatch();

const generateDidSession = async (address: string, connector: any) => {
const provider = await connector.getProvider();
Expand All @@ -24,50 +23,54 @@ export const ConnectWalletButton = (props: ConnectWalletProps) => {
resources: [`ceramic://*`],
expiresInSecs: config.didSession.expiresInSecs,
});
props.setDidSession(session.serialize());
setDid(session.did.id);

dispatch(updateDidSession(session.serialize()));
dispatch(updateDid(session.did.id));
};

const {address, isConnected} = useAccount({
const { address, isConnected } = useAccount({
onConnect(context) {
if (!context.isReconnected) {
generateDidSession(context.address, context.connector).then(() => {
props.onSessionCreated(context.address);
}).catch(() => {
toast.error("Error initiating did session!")
});
generateDidSession(context.address, context.connector)
.then(() => {
props.onSessionCreated(context.address);
})
.catch(() => {
toast.error("Error initiating did session!");
});
}
},
onDisconnect() {
removeDid();
props.removeDidSession();
}
dispatch(updateDid(null));
dispatch(updateDidSession(null));
},
});

const onOpen = async () => {
setLoading(true)
await open()
setLoading(false)
}
setLoading(true);
await open();
setLoading(false);
};

const onClick = async () => {
isConnected ? disconnect() : await onOpen()
}
isConnected ? disconnect() : await onOpen();
};

const getAddress = () => {
return address ? utils.formatWalletAddress(address) : "";
}
};

return (
<button
className={utils.classNames(
"flex h-[48px] items-center justify-center",
"rounded-[10px] border-[1px] border-[#DAD8E2] bg-white px-8 py-3 hover:border-[#08010D] focus:outline-none",
"font-medium text-[#97929B] hover:text-[#08010D]",
"font-medium text-[#97929B] hover:text-[#08010D]"
)}
onClick={onClick}
disabled={loading}>
disabled={loading}
>
{isConnected ? getAddress() : "Connect Wallet"}
</button>
)
}
);
};
2 changes: 0 additions & 2 deletions apps/web/src/components/Button/ConnectWallet/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export interface ConnectWalletProps {
onSessionCreated(address: string): void;
setDidSession(session: string): void;
removeDidSession(): void;
}
50 changes: 30 additions & 20 deletions apps/web/src/components/CommunityAvatar/CommunityAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
import {CommunityAvatarProps} from "./types";
import { CommunityAvatarProps } from "./types";
import Image from "next/image";
import * as utils from "../../utils";

export const CommunityAvatar = (props: CommunityAvatarProps) => {
return (
<div
id="community-avatar"
className={utils.classNames(
"group relative cursor-pointer",
props.classes
)}
onClick={props.onClick}
className={utils.classNames(
" inline-block px-5 ",
props.selected ? " border-r-[3px] rounded-r-sm border-black" : ""
)}
>
<span
id="tooltip"
className="absolute hidden z-50 group-hover:flex top-1.5 left-20 w-max px-2 py-1 bg-black rounded-lg text-center text-white">
{props.name}
</span>
<Image
width={45}
height={45}
className={props.selected ? `rounded-xl` : `rounded-full hover:rounded-xl`}
src={props.image}
alt={`${props.name} community`}
/>
<div
id="community-avatar"
className={utils.classNames(
"group relative flex h-12 w-12 cursor-pointer items-center justify-center ",
props.classes
)}
onClick={props.onClick}
>
<span
id="tooltip"
className="absolute top-1.5 left-20 z-50 hidden w-max rounded-lg bg-gray-300 px-2 py-1 text-center text-white group-hover:flex"
>
{props.name}
</span>
<Image
width={props.width ?? 45}
height={props.width ?? 45}
className={
props.selected ? `rounded-xl` : `rounded-full hover:rounded-xl`
}
src={props.image}
alt={`${props.name} community`}
/>
</div>
</div>
);
}
};
2 changes: 2 additions & 0 deletions apps/web/src/components/CommunityAvatar/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export interface CommunityAvatarProps {
width?: number;
height?: number;
name: string;
image: string;
onClick?(): void;
Expand Down
Loading