Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion src/common/api/breakaway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
4 changes: 2 additions & 2 deletions src/common/api/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
72 changes: 72 additions & 0 deletions src/common/components/authors-and-tags/index.tsx
Original file line number Diff line number Diff line change
@@ -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<AuthorsPostsProps | Props> = (props: any) => {

return (
<div>
<div>
<EntryListContent
{...props}
/>
</div>
</div>
);
};

export default AuthorsPosts;
253 changes: 253 additions & 0 deletions src/common/components/bitcoin-ordinals/index.tsx
Original file line number Diff line number Diff line change
@@ -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<string>('');
const [walletAddress, setWalletAddress] = useState<string | null>(null);
const [signedMessage, setSignedMessage] = useState<SignMessageResponse | null>(null);
const [serverResponse, setServerResponse] = useState<ServerResponse | any>(null);

const emailChanged =(e: { target: { value: React.SetStateAction<string>; }; })=>{
setEmail(e.target.value)
}

const usernameChanged =(e: { target: { value: React.SetStateAction<string>; }; })=>{
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<WalletAddress[]> => {
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<SignMessageResponse> => {
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<ServerResponse> => {
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 && <div className="sign-up">
<div className="the-form">
<div className="form-title">Register with Btc Ordinals</div>
<div className="form-sub-title mt-3">{_t("sign-up.description")}</div>
<div className="form-icons d-flex justify-content-center">
<img
style={{ borderRadius: "50%" }}
src={spkLogo}
alt="SpkNetwork"
title="SpkNetwork"
/>
<img
style={{ borderRadius: "50%" }}
src={btcLogo}
alt="btc"
title="Btc"
/>
</div>
{(() => {
return (
<div className="form-content">
<Form
ref={form}
>
<Form.Group className="d-flex flex-column">
<Form.Control
type="text"
placeholder={"enter username"}
value={username}
onChange={usernameChanged}
autoFocus={true}
required={true}
onInvalid={(e: any) =>
handleInvalid(e, "sign-up.", "validation-username")
}
onInput={handleOnInput}
/>
</Form.Group>
<Form.Group>
<Form.Control
type="email"
placeholder={_t("sign-up.email")}
value={email}
onChange={emailChanged}
required={true}
onInvalid={(e: any) =>
handleInvalid(e, "sign-up.", "validation-email")
}
onInput={handleOnInput}
/>
</Form.Group>
<div className="d-flex justify-content-center">
<Button
variant="primary"
block={true}
disabled={inProgress}
onClick={handleCreateAccount}
>
{inProgress && spinner} {_t("sign-up.submit")}
</Button>
</div>
</Form>

<div className="text-center">
{_t("sign-up.login-text-1")}
<a
href="#"
onClick={(e) => {
e.preventDefault();
const { toggleUIProp } = props;
toggleUIProp("login");
}}
>
{" "}
{_t("sign-up.login-text-2")}
</a>
</div>
</div>
);
})()}
</div>
</div>}
{step == 2 && !error && (
<div className="success-wrapper">
<div className="success-info">
<h3 className="text-success">
Account created succesfully
</h3>
<Link to={``}>Login</Link>
</div>
</div>
)}
{step == 2 && error && (
<div className="success-wrapper">
<div className="success-info">
<h3 className="text-danger">
{error}
</h3>
<Button onClick={()=> setStep(1)}>Try again</Button>
</div>
</div>
)}
</>
)
}
2 changes: 1 addition & 1 deletion src/common/components/comment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class Comment extends Component<Props, State> {
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) {

}
Expand Down
2 changes: 2 additions & 0 deletions src/common/components/community-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class CommunityMenu extends Component<Props> {
EntryFilter.created,
EntryFilter.payout,
EntryFilter.muted,
EntryFilter.tags,
EntryFilter.authors,
].map((x) => {
return {
label: _t(`entry-filter.filter-${x}`),
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/entry-reblog-btn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class EntryReblogBtn extends BaseComponent<Props> {
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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/common/components/entry-vote-btn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class EntryVoteBtn extends BaseComponent<Props, State> {
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));
Expand Down
4 changes: 3 additions & 1 deletion src/common/helper/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ export const globalInstance: Global = {
hive_id: "",
ctheme: "",
baseApiUrl: "",
communityTitle: ""
communityTitle: "",
baAuthors: [],
communityType: ""
};

export const TrendingTagsInstance: TrendingTags = {
Expand Down
Loading