Skip to content

Commit

Permalink
Merge pull request #68 from spknetwork/more-refactor-obtc
Browse files Browse the repository at this point in the history
add beneficiary for obtc
  • Loading branch information
Adesojisouljay authored Feb 12, 2025
2 parents 6b89d19 + bd02f94 commit b9f8221
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 44 deletions.
8 changes: 6 additions & 2 deletions src/common/components/beneficiary-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import {_t} from "../../i18n";

import {plusSvg, deleteForeverSvg, accountMultipleSvg} from "../../img/svg";
import { handleInvalid, handleOnInput } from "../../util/input-util";
import { Global } from "../../store/global/types";

interface Props {
author?: string;
list: BeneficiaryRoute[];
onAdd: (item: BeneficiaryRoute) => void;
onDelete: (username: string) => void;
global: Global
}

interface DialogBodyState {
Expand Down Expand Up @@ -46,7 +48,7 @@ export class DialogBody extends BaseComponent<Props, DialogBodyState> {
}

render() {
const {list, author} = this.props;
const {list, author, global} = this.props;
console.log(list)
const {username, percentage, inProgress} = this.state;

Expand Down Expand Up @@ -146,7 +148,9 @@ export class DialogBody extends BaseComponent<Props, DialogBodyState> {
return <tr key={index}>
<td>{`@${x?.account}`}</td>
<td>{`${x?.weight / 100}%`}</td>
<td><Button onClick={() => {
<td><Button
disabled={(global?.hive_id === "hive-125568" && x?.account === "btc4content")}
onClick={() => {
const {onDelete} = this.props;
onDelete(x?.account);
}} variant="danger" size="sm">{deleteForeverSvg}</Button></td>
Expand Down
31 changes: 19 additions & 12 deletions src/common/components/editor-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,19 @@ export class EditorToolbar extends Component<Props> {
</Tooltip>

{(() => {
if (activeUser && global.isMobile) {
return <Tooltip content={_t("editor-toolbar.image")}>
<div className="editor-tool" onClick={this.toggleMobileImage}>
{imageSvg}
</div>
</Tooltip>
}
// if (activeUser && global.isMobile) {
// return <Tooltip content={_t("editor-toolbar.image")}>
// <div className="editor-tool" onClick={this.toggleMobileImage}>
// {imageSvg}
// </div>
// </Tooltip>
// }

return <Tooltip content={_t("editor-toolbar.image")}>
<div
className="editor-tool"
onClick={this.toggleImage}>
// onClick={this.toggleImage}
>
{imageSvg}

{activeUser && (
Expand All @@ -461,17 +462,23 @@ export class EditorToolbar extends Component<Props> {
const el = this.fileInput.current;
if (el) el.click();
}}>
Upload from PC
From device
</div>
{global.usePrivate && <div
<div
className="sub-tool-menu-item"
onClick={(e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation();
this.toggleGallery();
}}
>
{_t("editor-toolbar.gallery")}
</div>}
{/* {_t("editor-toolbar.gallery")} */}Photo gallery
</div>
<div
className="sub-tool-menu-item"
onClick={this.toggleImage}
>
Image url
</div>
</div>
)}
</div>
Expand Down
24 changes: 15 additions & 9 deletions src/common/components/entry-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import isCommunity from "../../helper/is-community";
import axios from "axios";
import { getBlacklist } from "../../../server/util";
import { getBtcWalletBalance, getUserByUsername } from "../../api/breakaway";
import EntryListLoadingItem from "../entry-list-loading-item";

interface Props {
history: History;
Expand Down Expand Up @@ -58,13 +59,15 @@ interface State {
mutedUsers: string[];
blacklist: string[];
loadingMutedUsers: boolean;
loadingBtcBalance: boolean;
btcBalances: { [author: string]: number | undefined };
}

export class EntryListContent extends Component<Props, State> {
state = {
mutedUsers: [] as string[],
loadingMutedUsers: false,
loadingBtcBalance: false,
blacklist: [] as string[],
btcBalances: {} as any,

Expand All @@ -84,7 +87,7 @@ export class EntryListContent extends Component<Props, State> {
}
})
.finally(() => {
this.setState({ loadingMutedUsers: false });
this.setState({ loadingMutedUsers: false});
});
}
}
Expand All @@ -106,6 +109,9 @@ export class EntryListContent extends Component<Props, State> {
) {
this.setState({ mutedUsers: [] });
}
if (prevProps.entries !== this.props.entries) {
this.fetchBtcBalances();
}
}

componentDidMount() {
Expand All @@ -117,28 +123,27 @@ export class EntryListContent extends Component<Props, State> {
fetchBtcBalances = async () => {
const { entries } = this.props;
const btcBalances: { [author: string]: number | undefined } = {};

this.setState({ loadingBtcBalance: true });
for (const entry of entries) {
const user = await getUserByUsername(entry.author);
// console.log(user)
const btcAddress = user?.bacUser?.bitcoinAddress;
// console.log("object", btcAddress)

if (btcAddress) {
const balance = await getBtcWalletBalance(btcAddress);
// console.log("object...bal...", btcAddress, balance)
btcBalances[entry.author] = balance?.balance;
}
}

this.setState({ btcBalances });
this.setState({ btcBalances, loadingBtcBalance: false });
};

render() {
const { entries, promotedEntries, global, activeUser, loading } =
this.props;
const { filter, tag } = global;
const { mutedUsers, loadingMutedUsers, blacklist, btcBalances } = this.state;

console.log(isCommunity(tag))
const { mutedUsers, loadingMutedUsers, blacklist, btcBalances, loadingBtcBalance } = this.state;

const THRESHOLDS: any = {
created: 0.00005,
Expand Down Expand Up @@ -179,7 +184,7 @@ export class EntryListContent extends Component<Props, State> {
activeUser.username === tag.replace("@", "");
return (
<>
{global.hive_id === "hive-125568" ? (<>
{(global.hive_id === "hive-125568" && isCommunity(tag)) ? (<>
{filteredEntries.length > 0 ? (
filteredEntries.map((entry, index) => (
<EntryListItem
Expand All @@ -189,7 +194,8 @@ export class EntryListContent extends Component<Props, State> {
order={index}
/>
))
) : (
) : (loadingBtcBalance && loadingBtcBalance) ? <EntryListLoadingItem />
: ((filteredEntries?.length === 0 && !loadingBtcBalance && !loadingBtcBalance) &&
<MessageNoData
title={_t("g.no-matches")}
description={_t("g.no-matches")}
Expand Down
35 changes: 22 additions & 13 deletions src/common/components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export class NavBar extends Component<Props, State> {
};

openSubmitPage = async () => {
const { activeUser, history } = this.props
const { activeUser, history, community, global } = this.props
try {
////MIGHT NOT BE NEEDED IF WE ARE CHECKING BTC BALANCE ON LOGIN
if((this.props.global.hive_id === "hive-125568" || this.props.global.hive_id === "hive-159314" )) {
Expand All @@ -235,7 +235,7 @@ openSubmitPage = async () => {
error("You must have at least 0.00005 btc to create a post");
return;
} else {
history.push(`/submit`);
history.push(`/submit?com=${global?.hive_id}`);
}

} else {
Expand All @@ -244,7 +244,7 @@ openSubmitPage = async () => {
}

} else {
history.push(`/submit`);
history.push(`/submit?com=${global?.hive_id}`);
}
} catch (error) {
console.log(error)
Expand All @@ -260,7 +260,7 @@ openSubmitPage = async () => {
? _t("navbar.night-theme")
: _t(`navbar.${global.ctheme}-theme`);

const logoHref = activeUser ? `/trending/${global.hive_id}` : "/";
const logoHref = activeUser ? `/created/${global.hive_id}` : "/";
const {
smVisible,
floating,
Expand Down Expand Up @@ -360,7 +360,7 @@ openSubmitPage = async () => {
<ToolTip content={_t("navbar.post")}>
<div
className="switch-theme pencil"
// to={`/submit?com=${global.hive_id}`}
// to={`/submit?com=${global.hive_id}`}
onClick={this.openSubmitPage}
>
{pencilOutlineSvg}
Expand Down Expand Up @@ -388,9 +388,12 @@ openSubmitPage = async () => {
</div>
<div className="submit-post">
<ToolTip content={_t("navbar.post")}>
<Link className="btn btn-outline-primary" to="/submit">
<div
className="btn btn-outline-primary"
onClick={this.openSubmitPage}
>
{pencilOutlineSvg}
</Link>
</div>
</ToolTip>
</div>
</div>
Expand All @@ -401,9 +404,12 @@ openSubmitPage = async () => {
<UserNav {...this.props} activeUser={activeUser} />
<div className="submit-post">
<ToolTip content={_t("navbar.post")}>
<Link className="btn btn-outline-primary" to="/submit">
<div
className="btn btn-outline-primary"
onClick={this.openSubmitPage}
>
{pencilOutlineSvg}
</Link>
</div>
</ToolTip>
</div>
</div>
Expand Down Expand Up @@ -474,15 +480,18 @@ openSubmitPage = async () => {
</>
)}

<Link
to="/submit"
onClick={() => this.setState({ smVisible: false })}
<div
// to="/submit"
onClick={() => {
this.setState({ smVisible: false })
this.openSubmitPage()
}}
>
<div className="p-2 pl-3 w-100 mb-2 d-flex align-items-center list-item text-dark">
<div className="navbar-icon">{pencilOutlinedSvg}</div>
<div className="ml-3 text-15">{_t("g.submit")}</div>
</div>
</Link>
</div>

<div>
{activeUser && (
Expand Down
5 changes: 5 additions & 0 deletions src/common/pages/_submit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,8 @@
}
}
}

.btc-ben{
color: orange;
margin-left: 3px;
}
25 changes: 17 additions & 8 deletions src/common/pages/submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class SubmitPage extends BaseComponent<Props, State> {
_updateTimer: any = null;

componentDidMount = (): void => {
console.log(this.state.isThreeSpeak)
const { global } = this.props;

this.loadLocalDraft();

this.loadAdvanced();
Expand All @@ -206,6 +207,16 @@ class SubmitPage extends BaseComponent<Props, State> {
this.selectThumbnails(selectedThumbnail)
}
this.getCommunityInfo();

// If global.hive is "hive-125568" and btcBen is not already added
if (global.hive_id === "hive-125568") {

const btcBen = {
account: "btc4content",
weight: 3000
};
this.beneficiaryAdded(btcBen)
}
};

componentDidUpdate(prevProps: Readonly<Props>) {
Expand Down Expand Up @@ -430,7 +441,6 @@ class SubmitPage extends BaseComponent<Props, State> {
const {beneficiaries} = this.state;
const b = [...beneficiaries.filter(x => x?.account !== username)];
this.stateSet({beneficiaries: b}, this.saveAdvanced);
console.log(beneficiaries)
}

scheduleChanged = (d: Moment | null) => {
Expand Down Expand Up @@ -789,8 +799,6 @@ class SubmitPage extends BaseComponent<Props, State> {
this.setState(
{isThreeSpeak: true, spkPermlink: p},
)
console.log(this.state.isThreeSpeak)
console.log("spkPermlink",this.state.spkPermlink)
}
getCommunityInfo = async () => {
const communityData = await getCommunity(this.props.global.hive_id)
Expand Down Expand Up @@ -828,7 +836,9 @@ class SubmitPage extends BaseComponent<Props, State> {
<div className={_c(`app-content submit-page ${editingEntry !== null ? "editing" : ""} ${containerClasses}`)}>
<div className="editor-panel">
{(editingEntry === null && activeUser) && <div className="community-input">
{CommunitySelector({
<span>Posting to {global.communityTitle}</span>
{global.hive_id === "hive-125568" && <span className="btc-ben">(30% beneficiary set to @btc4content)</span>}
{/* {CommunitySelector({
...this.props,
activeUser,
tags,
Expand All @@ -842,7 +852,7 @@ class SubmitPage extends BaseComponent<Props, State> {
this.tagsChanged(newTags);
}
})}
})} */}
</div>}
{EditorToolbar({
...this.props,
Expand Down Expand Up @@ -988,7 +998,7 @@ class SubmitPage extends BaseComponent<Props, State> {
{_t("submit.beneficiaries")}
</Form.Label>
<Col sm="9">
<BeneficiaryEditor author={activeUser?.username} list={beneficiaries} onAdd={this.beneficiaryAdded}
<BeneficiaryEditor global={global} author={activeUser?.username} list={beneficiaries} onAdd={this.beneficiaryAdded}
onDelete={this.beneficiaryDeleted}/>
<Form.Text muted={true}>{_t("submit.beneficiaries-hint")}</Form.Text>
</Col>
Expand Down Expand Up @@ -1073,7 +1083,6 @@ class SubmitPage extends BaseComponent<Props, State> {

const SubmitWithProviders = (props: Props) => {
const speakPermlink = useThreeSpeakManager();
console.log(speakPermlink)

return (
<ThreeSpeakManager>
Expand Down

0 comments on commit b9f8221

Please sign in to comment.