From 5639d549418e8e2dd64d6dcfd74b2ee8fd9c3f63 Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 20 Aug 2024 07:26:32 +0100 Subject: [PATCH 1/6] add to menu --- src/common/components/community-menu/index.tsx | 2 ++ src/common/i18n/locales/en-US.json | 2 ++ src/common/store/global/types.ts | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/components/community-menu/index.tsx b/src/common/components/community-menu/index.tsx index 40cc9296b7f..f81ce1d707c 100644 --- a/src/common/components/community-menu/index.tsx +++ b/src/common/components/community-menu/index.tsx @@ -59,6 +59,8 @@ export class CommunityMenu extends Component { EntryFilter.created, EntryFilter.payout, EntryFilter.muted, + EntryFilter.tags, + EntryFilter.authors, ].map((x) => { return { label: _t(`entry-filter.filter-${x}`), diff --git a/src/common/i18n/locales/en-US.json b/src/common/i18n/locales/en-US.json index 3b55267a9f1..228ba3b29c6 100644 --- a/src/common/i18n/locales/en-US.json +++ b/src/common/i18n/locales/en-US.json @@ -74,6 +74,8 @@ "filter-promoted": "Promoted", "filter-payout": "Payouts", "filter-muted": "Muted", + "filter-tags": "Tags", + "filter-authors": "Authors", "filter-feed": "Feed", "filter-feed-friends": "Friends", "filter-feed-subscriptions": "Communities", diff --git a/src/common/store/global/types.ts b/src/common/store/global/types.ts index c69ed9a1dc0..390ec1fd9fa 100644 --- a/src/common/store/global/types.ts +++ b/src/common/store/global/types.ts @@ -19,7 +19,9 @@ export enum EntryFilter { created = "created", payout = "payout", payout_comments = "payout_comments", - muted = "muted" + muted = "muted", + tags = "tags", + authors = "authors" } export enum ProfileFilter { From 798b9a7de4e7992048a6d9ba6c1111c4b872f58f Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 27 Aug 2024 12:02:47 +0100 Subject: [PATCH 2/6] fetch bac authors post --- src/common/api/breakaway.ts | 3 +- src/common/api/bridge.ts | 4 +- .../components/authors-and-tags/index.tsx | 72 ++++++++++++++ src/common/components/comment/index.tsx | 2 +- .../components/entry-reblog-btn/index.tsx | 2 +- .../components/entry-vote-btn/index.tsx | 2 +- src/common/helper/test-helper.ts | 3 +- src/common/pages/community.tsx | 96 ++++++++++++++++--- src/common/pages/profile.tsx | 7 +- src/common/pages/submit.tsx | 2 +- src/common/store/global/index.ts | 3 +- src/common/store/global/types.ts | 1 + src/config.ts | 3 +- src/server/state.ts | 1 + 14 files changed, 178 insertions(+), 23 deletions(-) create mode 100644 src/common/components/authors-and-tags/index.tsx diff --git a/src/common/api/breakaway.ts b/src/common/api/breakaway.ts index 0323289f5fa..bf5643e1ec2 100644 --- a/src/common/api/breakaway.ts +++ b/src/common/api/breakaway.ts @@ -88,11 +88,12 @@ export const getBaUserPoints = async (username: string, community: string): Pro } }; -export const updateUserPoints = async (username: string, community: string, pointType: string) => { +export const updateUserPoints = async (username: string, community: string, communityId: string, pointType: string) => { try { const requestData = { username, community, + communityId, pointType, }; diff --git a/src/common/api/bridge.ts b/src/common/api/bridge.ts index 46ab40fc2d7..e2caf0f48ad 100644 --- a/src/common/api/bridge.ts +++ b/src/common/api/bridge.ts @@ -62,8 +62,8 @@ export const getPostsRanked = ( } export const getAccountPosts = ( - sort: string, - account: string, + sort?: string, + account?: string, start_author: string = "", start_permlink: string = "", limit: number = dataLimit, diff --git a/src/common/components/authors-and-tags/index.tsx b/src/common/components/authors-and-tags/index.tsx new file mode 100644 index 00000000000..671b6b064ae --- /dev/null +++ b/src/common/components/authors-and-tags/index.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import EntryListContent from '../entry-list'; +import {History, Location} from "history"; +import _ from 'lodash' + +import {Global} from "../../store/global/types"; +import {Account} from "../../store/accounts/types"; +import {DynamicProps} from "../../store/dynamic-props/types"; +import { Entry } from "../../store/entries/types"; +import { Community, Communities } from "../../store/communities/types"; +import { User } from "../../store/users/types"; +import { ActiveUser } from "../../store/active-user/types"; +import { Reblogs } from "../../store/reblogs/types"; +import { UI, ToggleType } from "../../store/ui/types"; + +import { EntryPinTracker } from "../../store/entry-pin-tracker/types"; +import { _t } from "../../i18n"; + +interface AuthorsPostsProps { + global: any; + community: any; + promoted: any[]; + loading: boolean; + entries: any; + promotedEntries: any; + authorsPosts: any; +} +interface Props { + history: History; + location: Location; + global: Global; + dynamicProps: DynamicProps; + entries: Entry[]; + promotedEntries: Entry[]; + communities: Communities; + community?: Community | null; + users: User[]; + activeUser: ActiveUser | null; + reblogs: Reblogs; + loading: boolean; + ui: UI; + entryPinTracker: EntryPinTracker; + signingKey: string; + addAccount: (data: Account) => void; + updateEntry: (entry: Entry) => void; + setActiveUser: (username: string | null) => void; + updateActiveUser: (data?: Account) => void; + deleteUser: (username: string) => void; + fetchReblogs: () => void; + addReblog: (author: string, permlink: string) => void; + deleteReblog: (author: string, permlink: string) => void; + toggleUIProp: (what: ToggleType) => void; + addCommunity: (data: Community) => void; + trackEntryPin: (entry: Entry) => void; + setSigningKey: (key: string) => void; + setEntryPin: (entry: Entry, pin: boolean) => void; +} + +const AuthorsPosts: React.FC = (props: any) => { + + return ( +
+
+ +
+
+ ); +}; + +export default AuthorsPosts; diff --git a/src/common/components/comment/index.tsx b/src/common/components/comment/index.tsx index 9df7201ea8d..f0c18cd62a7 100644 --- a/src/common/components/comment/index.tsx +++ b/src/common/components/comment/index.tsx @@ -137,7 +137,7 @@ export class Comment extends Component { const {onSubmit, activeUser} = this.props; try { onSubmit(text); - const res = await updateUserPoints(activeUser!.username, communityData.title, "comments") + const res = await updateUserPoints(activeUser!.username, communityData.title, communityData.name, "comments") } catch (error) { } diff --git a/src/common/components/entry-reblog-btn/index.tsx b/src/common/components/entry-reblog-btn/index.tsx index 592fa6cbe25..92d268466cd 100644 --- a/src/common/components/entry-reblog-btn/index.tsx +++ b/src/common/components/entry-reblog-btn/index.tsx @@ -77,7 +77,7 @@ export class EntryReblogBtn extends BaseComponent { reblog(activeUser?.username!, entry.author, entry.permlink) .then(async () => { addReblog(entry.author, entry.permlink); - const baResponse = await updateUserPoints(activeUser!.username, communityData.title, "reblog") + const baResponse = await updateUserPoints(activeUser!.username, communityData.title, communityData.name, "reblog") success(_t("entry-reblog.success")); }) .catch((e) => { diff --git a/src/common/components/entry-vote-btn/index.tsx b/src/common/components/entry-vote-btn/index.tsx index 6246ee0df9f..9e2d46c09ac 100644 --- a/src/common/components/entry-vote-btn/index.tsx +++ b/src/common/components/entry-vote-btn/index.tsx @@ -400,7 +400,7 @@ export class EntryVoteBtn extends BaseComponent { afterVote(votes, estimated); updateActiveUser(); // refresh voting power - const baResponse = await updateUserPoints(activeUser!.username, communityData.title, "upvote") + const baResponse = await updateUserPoints(activeUser!.username, communityData.title,communityData.name, "upvote") }) .catch((e) => { error(formatError(e)); diff --git a/src/common/helper/test-helper.ts b/src/common/helper/test-helper.ts index d8cc4377e9a..e9c8da370a9 100644 --- a/src/common/helper/test-helper.ts +++ b/src/common/helper/test-helper.ts @@ -127,7 +127,8 @@ export const globalInstance: Global = { hive_id: "", ctheme: "", baseApiUrl: "", - communityTitle: "" + communityTitle: "", + baAuthors: [] }; export const TrendingTagsInstance: TrendingTags = { diff --git a/src/common/pages/community.tsx b/src/common/pages/community.tsx index 6fc5e0bb710..3a6a3c74308 100644 --- a/src/common/pages/community.tsx +++ b/src/common/pages/community.tsx @@ -35,7 +35,7 @@ import CommunityActivities from "../components/community-activities"; import CommunityRoles from "../components/community-roles"; import ScrollToTop from "../components/scroll-to-top"; -import { getCommunity, getSubscriptions } from "../api/bridge"; +import { getAccountPosts, getCommunity, getSubscriptions } from "../api/bridge"; import { _t } from "../i18n"; @@ -45,6 +45,9 @@ import capitalize from "../util/capitalize"; import defaults from "../constants/defaults.json"; import SearchBox from "../components/search-box"; import { setupConfig } from "../../setup"; +import { FormControl } from "react-bootstrap"; +import { Entry } from "../store/entries/types"; +import AuthorsPosts from "../components/authors-and-tags"; interface MatchParams { filter: string; @@ -61,6 +64,9 @@ interface State { search: string; searchDataLoading: boolean; searchData: SearchResult[]; + authorsPosts: any; + baAuthor: string; + baTag: string; } class CommunityPage extends BaseComponent { @@ -70,6 +76,9 @@ class CommunityPage extends BaseComponent { search: "", searchDataLoading: false, searchData: [], + authorsPosts: [], + baAuthor: this.props.global.baAuthors[1], + baTag: this.props.global.tags[0] }; constructor(props: Props) { @@ -90,6 +99,9 @@ class CommunityPage extends BaseComponent { search: searchParam, searchDataLoading: searchParam.length > 0, searchData: [], + authorsPosts: [], + baAuthor: this.props.global.baAuthors[1], + baTag: this.props.global.tags[0] }; } @@ -110,6 +122,7 @@ class CommunityPage extends BaseComponent { if (r) updateSubscriptions(r); }); } + this.getPostsByUser() } componentDidUpdate(prevProps: Readonly): void { @@ -126,7 +139,7 @@ class CommunityPage extends BaseComponent { // community or filter changed if ( - (filter !== prevParams.filter || name !== prevParams.name) && + (filter !== prevParams?.filter || name !== prevParams.name) && EntryFilter[filter as EntryFilter] ) { fetchEntries(match.params.filter, match.params.name, false); @@ -241,13 +254,31 @@ class CommunityPage extends BaseComponent { this.delayedSearch(value); }; + getPostsByUser = async () => { + const authorsPosts = await getAccountPosts("posts",this.state.baAuthor); + console.log(authorsPosts) + this.setState({authorsPosts}) + } + + authorsChanged = (e: { target: { value: any; }; })=>{ + const baAuthor = e.target.value + console.log(e.target.value) + this.setState({baAuthor}) + } + tagsChanged = (e: { target: { value: any; }; })=>{ + const baTag = e.target.value + console.log(e.target.value) + this.setState({baTag}) + } + render() { const { global, entries, communities, accounts, match } = this.props; - const { loading, search, searchData, searchDataLoading, typing } = + const { loading, search, searchData, searchDataLoading, typing, authorsPosts } = this.state; - const { filter } = match.params; - const { hive_id: name, tags } = global; + const { hive_id: name, tags, baAuthors } = global; + console.log(baAuthors) + console.log(tags) const community = communities.find((x) => x.name === name); const account = accounts.find((x) => x.name === name); @@ -350,6 +381,47 @@ class CommunityPage extends BaseComponent { return ; } + if (filter === "tags") return ( + <> + + + {global.tags.map(x => ( + + ))} + +
+ +
+ + ) + + if (filter === "authors") return ( + <> + + + {global.baAuthors.map(x => ( + + ))} + +
+ +
+ + ) + const groupKey = makeGroupKey(filter, name); const data = entries[groupKey]; @@ -417,13 +489,13 @@ class CommunityPage extends BaseComponent { {loading && entryList.length === 0 && ( )} - {EntryListContent({ - ...this.props, - entries: entryList, - promotedEntries: promoted, - community, - loading, - })} + )} diff --git a/src/common/pages/profile.tsx b/src/common/pages/profile.tsx index 220de703ed8..7217de3fdb0 100644 --- a/src/common/pages/profile.tsx +++ b/src/common/pages/profile.tsx @@ -472,7 +472,12 @@ class ProfilePage extends BaseComponent {
{loading && entryList.length === 0 && } - {EntryListContent({...this.props, entries: entryList, promotedEntries: [], loading})} +
{loading && entryList.length > 0 ? : ""} diff --git a/src/common/pages/submit.tsx b/src/common/pages/submit.tsx index cc4ccbb7e04..c633d9249a3 100644 --- a/src/common/pages/submit.tsx +++ b/src/common/pages/submit.tsx @@ -603,7 +603,7 @@ class SubmitPage extends BaseComponent { percent_hbd: options.percent_hbd }; addEntry(entry); - const baResponse = await updateUserPoints(activeUser!.username, communityData.title, "posts"); + const baResponse = await updateUserPoints(activeUser!.username, communityData.title,communityData.name, "posts"); success(_t("submit.published")); this.clear(); diff --git a/src/common/store/global/index.ts b/src/common/store/global/index.ts index 0a491fa0efb..6f57e27e667 100644 --- a/src/common/store/global/index.ts +++ b/src/common/store/global/index.ts @@ -56,7 +56,8 @@ export const initialState: Global = { tags: ["spk", "3speak"], hive_id: "hive-112019", baseApiUrl: "https://account-creator.3speak.tv/api", - communityTitle: "" + communityTitle: "", + baAuthors: [] }; export default (state: Global = initialState, action: Actions): Global => { diff --git a/src/common/store/global/types.ts b/src/common/store/global/types.ts index 390ec1fd9fa..d781adbe693 100644 --- a/src/common/store/global/types.ts +++ b/src/common/store/global/types.ts @@ -71,6 +71,7 @@ export interface Global { hive_id: string; tags: string[]; communityTitle: string; + baAuthors: string[]; } export enum ActionTypes { diff --git a/src/config.ts b/src/config.ts index a4fc88ffc0c..a800655644d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -7,5 +7,6 @@ export default { theme: process.env.THEME || "", tags: process.env.TAGS?.split(",") || "", availibleAccounts: process.env.ACCOUNTS ? +process.env.ACCOUNTS : 0, - baseApiUrl: process.env.API_URL || "https://account-creator.3speak.tv/api" + baseApiUrl: process.env.API_URL || "https://account-creator.3speak.tv/api", + authors: process.env.AUTHORS?.split(",") || "", }; diff --git a/src/server/state.ts b/src/server/state.ts index 08da00ddd53..fde5c6025dc 100644 --- a/src/server/state.ts +++ b/src/server/state.ts @@ -56,6 +56,7 @@ export const makePreloadedState = async ( ctheme: config.theme, tags: [...config.tags], baseApiUrl: config.baseApiUrl, + baAuthors: [...config.authors], communityTitle: communityData!.title }; From a4df72926ffb441a5df21814e42026d7653e1f0f Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 27 Aug 2024 13:45:43 +0100 Subject: [PATCH 3/6] fixed aothors select --- src/common/pages/community.tsx | 46 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/common/pages/community.tsx b/src/common/pages/community.tsx index 3a6a3c74308..0f0de3aa401 100644 --- a/src/common/pages/community.tsx +++ b/src/common/pages/community.tsx @@ -67,6 +67,7 @@ interface State { authorsPosts: any; baAuthor: string; baTag: string; + loadingb: boolean; } class CommunityPage extends BaseComponent { @@ -78,7 +79,8 @@ class CommunityPage extends BaseComponent { searchData: [], authorsPosts: [], baAuthor: this.props.global.baAuthors[1], - baTag: this.props.global.tags[0] + baTag: this.props.global.tags[0], + loadingb: false, }; constructor(props: Props) { @@ -101,7 +103,8 @@ class CommunityPage extends BaseComponent { searchData: [], authorsPosts: [], baAuthor: this.props.global.baAuthors[1], - baTag: this.props.global.tags[0] + baTag: this.props.global.tags[0], + loadingb: false, }; } @@ -122,7 +125,7 @@ class CommunityPage extends BaseComponent { if (r) updateSubscriptions(r); }); } - this.getPostsByUser() + this.getPostsByUser(); } componentDidUpdate(prevProps: Readonly): void { @@ -255,16 +258,27 @@ class CommunityPage extends BaseComponent { }; getPostsByUser = async () => { - const authorsPosts = await getAccountPosts("posts",this.state.baAuthor); - console.log(authorsPosts) - this.setState({authorsPosts}) + this.setState({loadingb: true}) + try { + const authorsPosts = await getAccountPosts("posts",this.state.baAuthor); + console.log(authorsPosts) + this.setState({authorsPosts, loadingb: false}) + } catch (error) { + console.log(error); + this.setState({loadingb: false}) + } } - authorsChanged = (e: { target: { value: any; }; })=>{ - const baAuthor = e.target.value - console.log(e.target.value) - this.setState({baAuthor}) - } + authorsChanged = async (e: any) => { + e.preventDefault(); + e.stopPropagation(); + const baAuthor = e.target.value; + + this.setState({ baAuthor }, () => { + this.getPostsByUser(); + }); +} + tagsChanged = (e: { target: { value: any; }; })=>{ const baTag = e.target.value console.log(e.target.value) @@ -273,7 +287,7 @@ class CommunityPage extends BaseComponent { render() { const { global, entries, communities, accounts, match } = this.props; - const { loading, search, searchData, searchDataLoading, typing, authorsPosts } = + const { loading, search, searchData, searchDataLoading, typing, authorsPosts, loadingb } = this.state; const { filter } = match.params; const { hive_id: name, tags, baAuthors } = global; @@ -400,16 +414,16 @@ class CommunityPage extends BaseComponent { ) - + if (filter === "authors") return ( <> - + {/* */} {global.baAuthors.map(x => ( ))} -
+ { loadingb ? :
{ community={community} loading={loading} /> -
+
} ) From b455999dda9cec33e36d30d3cf226dc1fd57a58e Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 3 Sep 2024 04:41:03 +0100 Subject: [PATCH 4/6] merge all posts --- src/common/pages/community.tsx | 93 +++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 30 deletions(-) diff --git a/src/common/pages/community.tsx b/src/common/pages/community.tsx index 0f0de3aa401..004549c3acf 100644 --- a/src/common/pages/community.tsx +++ b/src/common/pages/community.tsx @@ -78,7 +78,7 @@ class CommunityPage extends BaseComponent { searchDataLoading: false, searchData: [], authorsPosts: [], - baAuthor: this.props.global.baAuthors[1], + baAuthor: this.props.global.baAuthors[0], baTag: this.props.global.tags[0], loadingb: false, }; @@ -258,16 +258,25 @@ class CommunityPage extends BaseComponent { }; getPostsByUser = async () => { - this.setState({loadingb: true}) + this.setState({ loadingb: true }); + + const authors = this.props.global.baAuthors; + console.log(authors) + let allPosts: any = []; + try { - const authorsPosts = await getAccountPosts("posts",this.state.baAuthor); - console.log(authorsPosts) - this.setState({authorsPosts, loadingb: false}) + // Fetch posts for each author + for (const author of authors) { + const authorPosts: any = await getAccountPosts("posts", author); + allPosts = [...allPosts, ...authorPosts]; // Merge posts into a single array + } + console.log("allPosts.......", allPosts); + this.setState({ authorsPosts: allPosts, loadingb: false }); } catch (error) { console.log(error); - this.setState({loadingb: false}) + this.setState({ loadingb: false }); } - } + }; authorsChanged = async (e: any) => { e.preventDefault(); @@ -285,14 +294,30 @@ class CommunityPage extends BaseComponent { this.setState({baTag}) } + ////might not be needed again + interleaveArrays = (arr1: any, arr2: any) => { + const newArray = [...arr1, ...arr2] + // const length = newArray.length + + // for (let start = 0; start < length; start++) { + // const randomPosition = Math.floor((newArray.length - start) * Math.random()) + // const randomItem = newArray.splice(randomPosition, 1) + + // newArray.push(...randomItem) + // } + // console.log(arr2, "_.shuffle(newArray)") + return _.shuffle(newArray) + } + + render() { const { global, entries, communities, accounts, match } = this.props; const { loading, search, searchData, searchDataLoading, typing, authorsPosts, loadingb } = this.state; const { filter } = match.params; const { hive_id: name, tags, baAuthors } = global; - console.log(baAuthors) - console.log(tags) + // console.log(baAuthors) + // console.log(tags) const community = communities.find((x) => x.name === name); const account = accounts.find((x) => x.name === name); @@ -394,27 +419,8 @@ class CommunityPage extends BaseComponent { if (filter === "roles") { return ; } - - if (filter === "tags") return ( - <> - - - {global.tags.map(x => ( - - ))} - -
- -
- - ) + ///might not need this anymore if (filter === "authors") return ( <> @@ -441,7 +447,34 @@ class CommunityPage extends BaseComponent { if (data !== undefined) { const entryList = data?.entries; + // console.log("object....", entryList) const loading = data?.loading; + const interleavedEntries = this.interleaveArrays(authorsPosts, entryList); + + //////IF COMMUNITY TYPE === AUTHORS + const postToRender = [...authorsPosts, ...entryList].sort((a, b) => Number(new Date(b.created)) - Number(new Date(a.created))); + console.log(postToRender) + + /////might not need this also anymore + if (filter === "tags") return ( + <> + + + {global.tags.map(x => ( + + ))} + +
+ +
+ + ) return ( <> @@ -505,7 +538,7 @@ class CommunityPage extends BaseComponent { )} Date: Thu, 5 Sep 2024 17:15:37 +0100 Subject: [PATCH 5/6] add communirt types --- src/common/helper/test-helper.ts | 3 ++- src/common/pages/community.tsx | 8 +++++--- src/common/store/global/index.ts | 3 ++- src/common/store/global/types.ts | 1 + src/config.ts | 1 + src/server/state.ts | 3 ++- 6 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/common/helper/test-helper.ts b/src/common/helper/test-helper.ts index e9c8da370a9..2fd634f8990 100644 --- a/src/common/helper/test-helper.ts +++ b/src/common/helper/test-helper.ts @@ -128,7 +128,8 @@ export const globalInstance: Global = { ctheme: "", baseApiUrl: "", communityTitle: "", - baAuthors: [] + baAuthors: [], + communityType: "" }; export const TrendingTagsInstance: TrendingTags = { diff --git a/src/common/pages/community.tsx b/src/common/pages/community.tsx index 004549c3acf..183ae0694e1 100644 --- a/src/common/pages/community.tsx +++ b/src/common/pages/community.tsx @@ -315,8 +315,8 @@ class CommunityPage extends BaseComponent { const { loading, search, searchData, searchDataLoading, typing, authorsPosts, loadingb } = this.state; const { filter } = match.params; - const { hive_id: name, tags, baAuthors } = global; - // console.log(baAuthors) + const { hive_id: name, tags, baAuthors, communityType } = global; + console.log(global) // console.log(tags) const community = communities.find((x) => x.name === name); @@ -538,7 +538,9 @@ class CommunityPage extends BaseComponent { )} { diff --git a/src/common/store/global/types.ts b/src/common/store/global/types.ts index d781adbe693..dfd91dd13f1 100644 --- a/src/common/store/global/types.ts +++ b/src/common/store/global/types.ts @@ -72,6 +72,7 @@ export interface Global { tags: string[]; communityTitle: string; baAuthors: string[]; + communityType: string | undefined; } export enum ActionTypes { diff --git a/src/config.ts b/src/config.ts index a800655644d..1e4fba62088 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,4 +9,5 @@ export default { availibleAccounts: process.env.ACCOUNTS ? +process.env.ACCOUNTS : 0, baseApiUrl: process.env.API_URL || "https://account-creator.3speak.tv/api", authors: process.env.AUTHORS?.split(",") || "", + communityType: process.env.COMMUNITY_TYPE, }; diff --git a/src/server/state.ts b/src/server/state.ts index fde5c6025dc..179eea7978b 100644 --- a/src/server/state.ts +++ b/src/server/state.ts @@ -57,7 +57,8 @@ export const makePreloadedState = async ( tags: [...config.tags], baseApiUrl: config.baseApiUrl, baAuthors: [...config.authors], - communityTitle: communityData!.title + communityTitle: communityData!.title, + communityType: config.communityType }; const dynamicProps = await getDynamicProps(); From 56be943f218f58914e00fda20d37642f97daee87 Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Thu, 19 Sep 2024 16:27:09 +0100 Subject: [PATCH 6/6] add bitcoin ordinals --- .../components/bitcoin-ordinals/index.tsx | 253 ++++++++++++++++++ src/common/img/btc-ord.jpeg | Bin 0 -> 5265 bytes src/common/pages/sign-up.tsx | 18 +- 3 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 src/common/components/bitcoin-ordinals/index.tsx create mode 100644 src/common/img/btc-ord.jpeg diff --git a/src/common/components/bitcoin-ordinals/index.tsx b/src/common/components/bitcoin-ordinals/index.tsx new file mode 100644 index 00000000000..40e6bf5f810 --- /dev/null +++ b/src/common/components/bitcoin-ordinals/index.tsx @@ -0,0 +1,253 @@ +import React, { useState, useRef } from 'react' +import { _t } from '../../i18n'; +import { Button, Form } from 'react-bootstrap'; +import { handleInvalid, handleOnInput } from "../../util/input-util"; +import { Link } from 'react-router-dom'; +// import { GetAddressConfig, getAddress, signMessage } from 'sats-connect'; +// import { getAddress, signMessage } from '@sats-connect/core'; +// import * as Test from "sats-connect" + +const spkLogo = require("../../img/spklogo.png"); +const btcLogo = require("../../img/btc-ord.jpeg"); + +interface WalletAddress { + address: string; +} + +interface SignMessageResponse { + signature: string; +} + +interface ServerResponse { + [key: string]: any; +} + +export const BitcoinOrdinals = (props: any) => { + const { inProgress, spinner, step, setStep, setInProgress } = props; + const form = useRef(null); + + const [email, setEmail] = useState("") + const [error, setError] = useState(""); + const [username, setUsername] = useState(''); + const [walletAddress, setWalletAddress] = useState(null); + const [signedMessage, setSignedMessage] = useState(null); + const [serverResponse, setServerResponse] = useState(null); + + const emailChanged =(e: { target: { value: React.SetStateAction; }; })=>{ + setEmail(e.target.value) + } + + const usernameChanged =(e: { target: { value: React.SetStateAction; }; })=>{ + setUsername(e.target.value) + // const geta: GetAddressConfig | any = "hgsddhjhjfdhjdef" + } + + const handleCreateAccount = async () => { + // event.preventDefault(); + + try { + const walletAddresses = await getWalletAddress(); + + console.log('Wallet Addresses:', walletAddresses); + + if (walletAddresses && walletAddresses.length > 0) { + const bitcoinAddress = walletAddresses[0].address; + const messageToSign = `Hive:${username}`; + + const signedMessageResponse = await signMessageFromWallet(messageToSign, bitcoinAddress); + + setWalletAddress(bitcoinAddress); + setSignedMessage(signedMessageResponse); + + console.log('Bitcoin Address:', bitcoinAddress); + console.log('Signed Message:', signedMessageResponse); + + // Send data to the server + const response = await sendToServer(username, bitcoinAddress, messageToSign, signedMessageResponse.signature); + setServerResponse(response); + + } else { + throw new Error('No addresses found in the response.'); + } + } catch (error: any) { + console.error('An error occurred:', error); + setServerResponse(`Error: ${error.message}`); + } + }; + + const getWalletAddress = (): Promise => { + return new Promise((resolve, reject) => { + const getAddressOptions: any = { + payload: { + purposes: ['payment'], + message: 'Address for creating Hive account', + network: { + type: 'Mainnet' + }, + }, + onFinish: (response: { addresses: WalletAddress[] }) => { + console.log('onFinish response:', response); + resolve(response.addresses); + }, + onCancel: () => reject(new Error('Request canceled')), + }; + + // getAddress(getAddressOptions); + }); + }; + + const signMessageFromWallet = (message: string, address: string): Promise => { + return new Promise((resolve, reject) => { + const signMessageOptions: any = { + payload: { + network: { + type: 'Mainnet', + }, + address: address, + message: message, + }, + onFinish: (response: SignMessageResponse) => { + console.log('Signature response:', response); + resolve(response); + }, + onCancel: () => reject(new Error('Signing canceled')), + }; + + // signMessage(signMessageOptions); + }); + }; + + const sendToServer = async (username: string, address: string, message: string, signature: string): Promise => { + try { + const response = await fetch('http://localhost:7000/create-account', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + username, + address, + message, + signature, + }), + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data: ServerResponse = await response.json(); + return data; + } catch (error) { + console.error('Error sending data to server:', error); + throw error; + } + }; + + return ( + <> + {step === 1 &&
+
+
Register with Btc Ordinals
+
{_t("sign-up.description")}
+
+ SpkNetwork + btc +
+ {(() => { + return ( +
+
+ + + handleInvalid(e, "sign-up.", "validation-username") + } + onInput={handleOnInput} + /> + + + + handleInvalid(e, "sign-up.", "validation-email") + } + onInput={handleOnInput} + /> + +
+ +
+
+ + +
+ ); + })()} +
+
} + {step == 2 && !error && ( +
+
+

+ Account created succesfully +

+ Login +
+
+ )} + {step == 2 && error && ( +
+
+

+ {error} +

+ +
+
+ )} + + ) +} diff --git a/src/common/img/btc-ord.jpeg b/src/common/img/btc-ord.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..2aa6c805b073b68636d55baad617d69fa621a816 GIT binary patch literal 5265 zcmYjV2|QHY`@a)PD%r-qCBra`WT%7}W`wL`8I++0WnUsouaIOaW6PFo*>_@+k!%sN z46=;u``!#`;Xl2<_kBPA@BQ3!p65KzeZJ>D=iKwT=Nx@Gng-ZV2qXdkfdBwRzks6& zAQCuv`~(}@SuopK4)A~A27`J2DBN@b4CWPrit_S9guvi)^5-B@FgP5}BchNSix*;JTM^HsBatWjM)r;sgWJ-%fOuossF>aSnM- zF>TYE-hahspSW1n0@g9}A>?dxU3J1nd>A;dkN`3Ft=ZwG#}J_BfX?t=c)IWp1Kp^= z{x<>RNycLg|M>h(a890yL)(<|;-C0c1KVQREi*bhT;TI&$B)K=(+nW`3ox()SAZQ} zc?mHQ(PN^2qG~a6{ma6n!}8#y7)mGAjTcqD@7lYsV=}L7Br{P-P4AD2vHqdi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*uO(+!rqyMh)fqZ3iNa=bq)K6GM}Hc8y|m-@X6HIgn#o=kIsP7un>PWnl8$+h0+w|LVjBJ$O7ODCO1A*NoA zvh;W1`Re~YEdS#M)ceWLE7&o$>;5KUN5H=IR^8e6G46L?YC4ike^y4&>OPLNwrR>c z$bGp#u1LI6Ph5v*KTEx<$q{vc8klmlx^&=JJTNnd{kRiUE>{1uuGmQPk&0*Q`&XFU zNYcP^oR_hR>^4D5DNpP; ziwSUDs4aw<;~VcCq|#uq1t { const form = useRef(null); const { global, communities, activeUser, history } = props; + console.log(global) const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); @@ -55,7 +57,7 @@ const SignUpPage = (props: Props | any) => { const [step, setStep] = useState(1); const [error, setError] = useState(""); const [isDownloaded, setIsDownloaded] = useState(false); - const [accountType, setAccountType] = useState("Hive"); + const [accountType, setAccountType] = useState(global.communityType === "btc_ordinals" ? "btc_ordinals" : "Hive"); useEffect(() => { getCurrentCommunity(); @@ -240,7 +242,7 @@ const SignUpPage = (props: Props | any) => { : NavBar({ ...props })}
- {step === 1 && ( + {(step === 1 && global.communityType !== "btc_ordinals") && (
{/*

Sign up with

*/}
{
)}
- {accountType === "Hive" && ( + {(accountType === "Hive" && global.communityType !== "btc_ordinals" )&& ( <> {step == 1 && (
@@ -499,6 +501,16 @@ const SignUpPage = (props: Props | any) => { /> )} + {(step === 1 && accountType === "btc_ordinals") && ( + <> + + + )}