Skip to content

Commit 532ff02

Browse files
Merge pull request #60 from spknetwork/add-btc-to-profile
add btc to profile
2 parents bf8dd8c + 8131fc5 commit 532ff02

File tree

18 files changed

+565
-91
lines changed

18 files changed

+565
-91
lines changed

src/common/api/breakaway.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import axios, { AxiosResponse } from "axios"
22
import * as ls from "../util/local-storage";
33

44
// const baUrl = "http://localhost:4000"
5-
// const baUrl = "https://breakaway-points-system-api.onrender.com"
65
const baUrl = "https://api.breakaway.community"
76
const accessToken = ls.get("ba_access_token")
87

@@ -48,7 +47,6 @@ export const processLogin = async (username: string, ts: string, sig: string, co
4847

4948
const { token, ...user } = response.data.response;
5049

51-
console.log('Login Successful...');
5250
return response;
5351

5452
} catch (error) {
@@ -148,8 +146,6 @@ export const getUserByUsername = async (username: string) => {
148146
try {
149147
const response = await axios.get(`${baUrl}/user/${username}`);
150148

151-
console.log(response)
152-
153149
return response.data;
154150
} catch (error) {
155151
console.error('Error fetching user by username:', error);
@@ -161,8 +157,6 @@ export const createFreeAccount = async (username: string, keys: any) => {
161157
try {
162158
const response = await axios.post(`${baUrl}/create-free-account`, {username, accountKeys: keys});
163159

164-
console.log(response)
165-
166160
return response.data;
167161
} catch (error) {
168162
console.error('Something went wrong:', error);
@@ -174,11 +168,39 @@ export const getAccountKeys = async (username: string) => {
174168
try {
175169
const response = await axios.post(`${baUrl}/get-account-keys`, {username});
176170

177-
console.log(response)
171+
return response.data;
172+
} catch (error) {
173+
console.error('Something went wrong:', error);
174+
throw error;
175+
}
176+
};
177+
178+
export const checkBtcMachine = async (address: string) => {
179+
try {
180+
const response = await axios.get(`${baUrl}/get-account-keys/${address}`);
178181

179182
return response.data;
180183
} catch (error) {
181184
console.error('Something went wrong:', error);
182185
throw error;
183186
}
184187
};
188+
189+
190+
191+
///////Btc ordinals
192+
export const fetchOrdinals = async (address: any) => {
193+
const API_URL = `https://api.hiro.so/ordinals/v1/inscriptions?address=${address}`;
194+
195+
try {
196+
const response = await fetch(API_URL);
197+
if (!response.ok) {
198+
throw new Error(`Error: ${response.statusText}`);
199+
}
200+
const data = await response.json();
201+
return data.results;
202+
} catch (error: any) {
203+
console.error("Failed to fetch ordinals:", error.message);
204+
return [];
205+
}
206+
};

src/common/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ const App = ({ setLang }: any) => {
9292
path={routes.ENTRY}
9393
component={EntryContainer}
9494
/>
95-
<Route
95+
{/* <Route
9696
exact={true}
9797
strict={true}
9898
path={routes.COMMUNITIES}
9999
component={CommunitiesContainer}
100-
/>
100+
/> */}
101101
<Route
102102
exact={true}
103103
strict={true}

src/common/components/community-menu/index.tsx

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,45 @@ export class CommunityMenu extends Component<Props> {
3939
}
4040

4141
render() {
42-
const { community, match } = this.props;
42+
const { community, match, global } = this.props;
4343
const { filter, name } = match.params;
44-
44+
4545
const menuConfig: {
4646
history: History;
4747
label: string;
4848
items: MenuItem[];
4949
} = {
5050
history: this.props.history,
5151
label:
52-
filter === EntryFilter.trending
53-
? _t("community.posts")
54-
: _t(`entry-filter.filter-${filter}`),
52+
(filter === EntryFilter.trending)
53+
? "Community Posts"
54+
: _t(`entry-filter.filter-${filter}`), // Keep for other translations
5555
items: [
56-
...[
57-
EntryFilter.trending,
58-
EntryFilter.hot,
59-
EntryFilter.created,
60-
EntryFilter.payout,
61-
EntryFilter.muted,
62-
].map((x) => {
63-
return {
64-
label: _t(`entry-filter.filter-${x}`),
65-
href: `/${x}/${community.name}`,
66-
active: filter === x,
67-
};
68-
}),
69-
],
56+
...(global.hive_id === "hive-125568"
57+
? [
58+
...([{ label: "5,000stats", value: EntryFilter.created }]),
59+
...([{ label: "50,000stats", value: EntryFilter.sats50000 }]),
60+
...([{ label: "500,000sat", value: EntryFilter.sats500000 }]),
61+
// ...([{ label: "0.5BTC", value: EntryFilter.trending }]),
62+
...([{ label: "0.5BTC", value: EntryFilter.trending }]),
63+
...( [{ label: "1BTC", value: EntryFilter.hot }]),
64+
]
65+
: [
66+
{ label: "Trending", value: EntryFilter.trending },
67+
{ label: "Hot", value: EntryFilter.hot },
68+
{ label: "Created", value: EntryFilter.created },
69+
{ label: "Payout", value: EntryFilter.payout },
70+
{ label: "Muted", value: EntryFilter.muted },
71+
])
72+
].map((item) => {
73+
return {
74+
label: item.label, // Custom label starting with numbers
75+
href: `/${item.value}/${community.name}`,
76+
active: filter === item.value,
77+
};
78+
}),
7079
};
71-
80+
7281
return (
7382
<div className="community-menu">
7483
<div className="menu-items">

src/common/components/entry-list/index.tsx

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { getFollowing } from "../../api/hive";
2121
import isCommunity from "../../helper/is-community";
2222
import axios from "axios";
2323
import { getBlacklist } from "../../../server/util";
24+
import { getBtcWalletBalance, getUserByUsername } from "../../api/breakaway";
2425

2526
interface Props {
2627
history: History;
@@ -57,13 +58,16 @@ interface State {
5758
mutedUsers: string[];
5859
blacklist: string[];
5960
loadingMutedUsers: boolean;
61+
btcBalances: { [author: string]: number | undefined };
6062
}
6163

6264
export class EntryListContent extends Component<Props, State> {
6365
state = {
6466
mutedUsers: [] as string[],
6567
loadingMutedUsers: false,
6668
blacklist: [] as string[],
69+
btcBalances: {} as any,
70+
6771
};
6872

6973
fetchMutedUsers = () => {
@@ -107,20 +111,58 @@ export class EntryListContent extends Component<Props, State> {
107111
componentDidMount() {
108112
this.fetchMutedUsers();
109113
this.fetchBlacklist();
114+
this.fetchBtcBalances();
110115
}
111116

117+
fetchBtcBalances = async () => {
118+
const { entries } = this.props;
119+
const btcBalances: { [author: string]: number | undefined } = {};
120+
121+
for (const entry of entries) {
122+
const user = await getUserByUsername(entry.author);
123+
// console.log(user)
124+
const btcAddress = user?.bacUser?.bitcoinAddress;
125+
// console.log("object", btcAddress)
126+
127+
if (btcAddress) {
128+
const balance = await getBtcWalletBalance(btcAddress);
129+
// console.log("object...bal...", btcAddress, balance)
130+
btcBalances[entry.author] = balance?.balance;
131+
}
132+
}
133+
134+
this.setState({ btcBalances });
135+
};
136+
112137
render() {
113138
const { entries, promotedEntries, global, activeUser, loading } =
114139
this.props;
115140
const { filter, tag } = global;
116-
const { mutedUsers, loadingMutedUsers, blacklist } = this.state;
141+
const { mutedUsers, loadingMutedUsers, blacklist, btcBalances } = this.state;
142+
143+
const THRESHOLDS: any = {
144+
created: 0.00005,
145+
sats50000: 0.0005,
146+
sats500000: 0.005,
147+
trending: 0.4,
148+
hot: 1,
149+
};
150+
151+
const filteredEntries = entries.filter((entry) => {
152+
const btcBalance: any = btcBalances[entry.author];
153+
const threshold = THRESHOLDS[global.filter];
154+
return btcBalance !== undefined && btcBalance >= threshold && !blacklist.includes(entry.author);
155+
});
156+
117157
const dataToRender = entries.filter((entry) =>
118158
!entry.community
119159
? true
120160
: !blacklist.includes(entry.author) &&
121-
(entry.community === global.hive_id ||
122-
entry.json_metadata.tags?.some((tag) => global.tags.includes(tag)))
123-
);
161+
(entry.community === global.hive_id ||
162+
(entry?.json_metadata?.tags &&
163+
Array.isArray(entry.json_metadata.tags) &&
164+
entry.json_metadata.tags.some((tag) => global.tags.includes(tag))))
165+
);
124166

125167
let mutedList: string[] = [];
126168
if (
@@ -137,7 +179,26 @@ export class EntryListContent extends Component<Props, State> {
137179
activeUser.username === tag.replace("@", "");
138180
return (
139181
<>
140-
{loadingMutedUsers ? (
182+
{global.hive_id === "hive-125568" ? (<>
183+
{filteredEntries.length > 0 ? (
184+
filteredEntries.map((entry, index) => (
185+
<EntryListItem
186+
key={`${entry.author}-${entry.permlink}`}
187+
{...this.props}
188+
entry={entry}
189+
order={index}
190+
/>
191+
))
192+
) : (
193+
<MessageNoData
194+
title={_t("g.no-matches")}
195+
description={_t("g.no-data")}
196+
global={global}
197+
buttonTo={""}
198+
buttonText={""}
199+
/>
200+
)}
201+
</>) : (loadingMutedUsers ? (
141202
<LinearProgress />
142203
) : dataToRender.length > 0 ? (
143204
<>
@@ -233,7 +294,7 @@ export class EntryListContent extends Component<Props, State> {
233294
buttonTo="/submit"
234295
global={global}
235296
/>
236-
)}
297+
))}
237298
</>
238299
);
239300
}

0 commit comments

Comments
 (0)