From ff1ba08de083ffc96dd56ff3848d9ec41d3aed84 Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Tue, 22 Oct 2024 12:41:47 +0100 Subject: [PATCH 1/2] balance on posting --- src/common/api/breakaway.ts | 5 ++-- .../components/editor-toolbar/index.tsx | 4 +-- src/common/components/profile-card/index.tsx | 2 +- src/common/components/wallet-menu/index.tsx | 2 +- src/common/pages/common.ts | 2 +- src/common/pages/submit.tsx | 25 ++++++++++++++++++- 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/common/api/breakaway.ts b/src/common/api/breakaway.ts index 11df001cb4d..6addc898bea 100644 --- a/src/common/api/breakaway.ts +++ b/src/common/api/breakaway.ts @@ -1,9 +1,9 @@ import axios, { AxiosResponse } from "axios" import * as ls from "../util/local-storage"; -// const baUrl = "http://localhost:4000" +const baUrl = "http://localhost:4000" // const baUrl = "https://breakaway-points-system-api.onrender.com" -const baUrl = "https://api.breakaway.community" +// const baUrl = "https://api.breakaway.community" const accessToken = ls.get("ba_access_token") export const createBreakawayUser = async (username: string, community: string, referral: string, email: string)=> { @@ -119,7 +119,6 @@ export const getBtcWalletBalance = async (address: string) => { Authorization: `Bearer ${accessToken}`, }, }); - // console.log(response) return response.data; } catch (error) { diff --git a/src/common/components/editor-toolbar/index.tsx b/src/common/components/editor-toolbar/index.tsx index 509adf6e5e3..f2cb680756f 100644 --- a/src/common/components/editor-toolbar/index.tsx +++ b/src/common/components/editor-toolbar/index.tsx @@ -511,14 +511,14 @@ export class EditorToolbar extends Component { - + {/*
{emoticonHappyOutlineSvg} {showEmoji && { this.insertText(e, ''); }}/>}
-
+
*/}
diff --git a/src/common/components/profile-card/index.tsx b/src/common/components/profile-card/index.tsx index ede0762b3a9..826ca4d32ae 100644 --- a/src/common/components/profile-card/index.tsx +++ b/src/common/components/profile-card/index.tsx @@ -179,7 +179,7 @@ export const ProfileCard = (props: Props) => {
- { (global?.communityTitle === "Bitcoin Machines" && global?.hive_id === "hive-159314") && + { (global?.hive_id === "hive-125568" || global?.hive_id === "hive-159314") &&
BTC ordinal info
diff --git a/src/common/components/wallet-menu/index.tsx b/src/common/components/wallet-menu/index.tsx index 0db87935114..358df878862 100644 --- a/src/common/components/wallet-menu/index.tsx +++ b/src/common/components/wallet-menu/index.tsx @@ -40,7 +40,7 @@ export default class WalletMenu extends Component { Tokens {hiveEngineSvg} - {(global?.communityTitle === "Bitcoin Machines" && global?.hive_id === "hive-159314") && + {(global?.hive_id === "hive-125568" || global?.hive_id === "hive-159314") && Btc Ordinals diff --git a/src/common/pages/common.ts b/src/common/pages/common.ts index f16411eb888..26b13879971 100644 --- a/src/common/pages/common.ts +++ b/src/common/pages/common.ts @@ -89,7 +89,7 @@ export interface PageProps { addUser: (user: User) => void; deleteUser: (username: string) => void; - activeUser: ActiveUser | null; + activeUser: ActiveUser | any; setActiveUser: (username: string | null) => void; updateActiveUser: (data?: Account) => void; diff --git a/src/common/pages/submit.tsx b/src/common/pages/submit.tsx index cc4ccbb7e04..d5767032231 100644 --- a/src/common/pages/submit.tsx +++ b/src/common/pages/submit.tsx @@ -70,7 +70,7 @@ import ModalConfirm from "../components/modal-confirm"; import ResizableTextarea from "../components/resizable-text-area"; import TextareaAutocomplete from "../components/textarea-autocomplete"; import { ThreeSpeakManager } from "../util/ThreeSpeakProvider"; -import { updateUserPoints } from "../api/breakaway"; +import { updateUserPoints, getBtcWalletBalance } from "../api/breakaway"; import { useThreeSpeakManager } from "../util/ThreeSpeakProvider"; import { getCommunity } from "../api/bridge"; @@ -532,7 +532,16 @@ class SubmitPage extends BaseComponent { if (!activeUser || !activeUser.data.__loaded) { return; } + + const bitcoinBalance = await this.getBitcoinAddressbalance() + + if(bitcoinBalance < 1) { + console.log("Insufficient bitcoin balance") + error("Insufficient Btc Balance") + return; + } + // return; this.stateSet({posting: true}); let author = activeUser.username; @@ -797,6 +806,19 @@ class SubmitPage extends BaseComponent { this.setState({communityData}) } + getBitcoinAddressbalance = async () => { + const {activeUser} = this.props + try { + const metaData = JSON.parse(activeUser?.data?.posting_json_metadata); + + const bitcoinBalance = await getBtcWalletBalance(metaData?.bitcoin?.address) + console.log(bitcoinBalance) + return bitcoinBalance.balance + } catch (error) { + console.log(error) + } + } + render() { const {title, tags, body, reward, preview, posting, editingEntry, saving, editingDraft, advanced, beneficiaries, schedule, reblogSwitch, clearModal, selectedThumbnail, thumbnails, disabled} = this.state; @@ -807,6 +829,7 @@ class SubmitPage extends BaseComponent { }; const {global, activeUser} = this.props; + console.log(activeUser) const spinner = ; // const isMobile = typeof window !== 'undefined' && window.innerWidth < 570; From 05728058e163d1cc63d156e445adab4ad5dfc78e Mon Sep 17 00:00:00 2001 From: Adesojisouljay Date: Thu, 24 Oct 2024 11:00:34 +0100 Subject: [PATCH 2/2] metadata refactor fromactiveU to acc --- src/common/components/profile-card/index.tsx | 13 ++++++------ .../wallet-bitcoin-machines/index.tsx | 21 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/common/components/profile-card/index.tsx b/src/common/components/profile-card/index.tsx index 826ca4d32ae..f0a4e39edeb 100644 --- a/src/common/components/profile-card/index.tsx +++ b/src/common/components/profile-card/index.tsx @@ -44,7 +44,7 @@ interface Props { global: Global; history: History; activeUser: ActiveUser | any; - account: Account; + account: Account | any; section?: string; addAccount: (data: Account) => void; updateActiveUser: (data?: Account) => void; @@ -95,6 +95,7 @@ export const ProfileCard = (props: Props) => { },[]) useEffect(() => { + console.log(account) setFollowersList(false); setFollowingList(false); setFollowsActiveUserLoading(activeUser && activeUser.username ? true : false); @@ -105,7 +106,7 @@ export const ProfileCard = (props: Props) => { console.log(global) const getMetaData = () => { try { - const metaData = JSON.parse(activeUser?.data?.posting_json_metadata); + const metaData = JSON.parse(account?.posting_json_metadata); setJsonMetaData(metaData) } catch (error) { console.log(error) @@ -179,20 +180,20 @@ export const ProfileCard = (props: Props) => {
- { (global?.hive_id === "hive-125568" || global?.hive_id === "hive-159314") && + { (global?.hive_id === "hive-125568" || global?.hive_id === "hive-159314") && jsonMetaData?.bitcoin &&
BTC ordinal info
Address: - {formatString(jsonMetaData?.bitcoin.address)} + {formatString(jsonMetaData?.bitcoin?.address)}
Message: - {jsonMetaData?.bitcoin.message} + {jsonMetaData?.bitcoin?.message}
Signature: - {formatString(jsonMetaData?.bitcoin.signature)} + {formatString(jsonMetaData?.bitcoin?.signature)}
} diff --git a/src/common/components/wallet-bitcoin-machines/index.tsx b/src/common/components/wallet-bitcoin-machines/index.tsx index c07cdb6206c..7f0d712530c 100644 --- a/src/common/components/wallet-bitcoin-machines/index.tsx +++ b/src/common/components/wallet-bitcoin-machines/index.tsx @@ -102,7 +102,7 @@ interface Props { dynamicProps: DynamicProps; history: History; activeUser: ActiveUser | any; - account: Account; + account: Account | any; points: Points; signingKey: string; transactions: Transactions; @@ -142,7 +142,7 @@ export const WalletBtc = (props: Props) => { useEffect(() => { const getMetaData = () => { try { - const metaData = JSON.parse(activeUser?.data?.posting_json_metadata); + const metaData = JSON.parse(account?.posting_json_metadata); setJsonMetaData(metaData) } catch (error) { console.log(error) @@ -215,7 +215,8 @@ export const WalletBtc = (props: Props) => {
-
+ {!jsonMetaData?.bitcoin &&
{account.name} does not have a bitcoin profile
} + {jsonMetaData?.bitcoin &&
Btc Address
Your bitcoin wallet address
@@ -231,9 +232,9 @@ export const WalletBtc = (props: Props) => {
-
+
} -
+ {jsonMetaData?.bitcoin &&
{communityInfo?.title}
Your bitcoin wallet balance
@@ -243,9 +244,9 @@ export const WalletBtc = (props: Props) => { {bitcoinBalance.toFixed(5)} (BTC)
-
+
} -
+ {/*
Staked Token
Staked tokens are simila to hive power. The more tokens you stake, the more influnce you can have in rewarding other people's content
@@ -255,9 +256,9 @@ export const WalletBtc = (props: Props) => { 0.000 OrdsToken
-
+
*/} -
+ {jsonMetaData?.bitcoin &&

Bitcoin Wallet Transactions

@@ -277,7 +278,7 @@ export const WalletBtc = (props: Props) => {
); })()} -
+
}