Skip to content

Commit 1200ea8

Browse files
Merge pull request #56 from spknetwork/signup-refactor
Signup refactor
2 parents e98b37c + ef92b8e commit 1200ea8

File tree

12 files changed

+705
-25
lines changed

12 files changed

+705
-25
lines changed

src/common/api/breakaway.ts

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

4-
// const baUrl = "http://localhost:4000"
4+
const baUrl = "http://localhost:4000"
55
// const baUrl = "https://breakaway-points-system-api.onrender.com"
6-
const baUrl = "https://api.breakaway.community"
6+
// const baUrl = "https://api.breakaway.community"
77
const accessToken = ls.get("ba_access_token")
88

99
export const createBreakawayUser = async (username: string, community: string, referral: string, email: string)=> {
@@ -144,5 +144,41 @@ export const getBtcTransactions = async (address: string) => {
144144
}
145145
};
146146

147+
export const getUserByUsername = async (username: string) => {
148+
try {
149+
const response = await axios.get(`${baUrl}/user/${username}`);
150+
151+
console.log(response)
152+
153+
return response.data;
154+
} catch (error) {
155+
console.error('Error fetching user by username:', error);
156+
throw error;
157+
}
158+
};
159+
160+
export const createFreeAccount = async (username: string, keys: any) => {
161+
try {
162+
const response = await axios.post(`${baUrl}/create-free-account`, {username, accountKeys: keys});
163+
164+
console.log(response)
165+
166+
return response.data;
167+
} catch (error) {
168+
console.error('Something went wrong:', error);
169+
throw error;
170+
}
171+
};
172+
173+
export const getAccountKeys = async (username: string) => {
174+
try {
175+
const response = await axios.post(`${baUrl}/get-account-keys`, {username});
147176

177+
console.log(response)
148178

179+
return response.data;
180+
} catch (error) {
181+
console.error('Something went wrong:', error);
182+
throw error;
183+
}
184+
};

src/common/components/editor-toolbar/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,16 @@ export class EditorToolbar extends Component<Props> {
511511
</div>
512512
</div>
513513
</Tooltip>
514-
<Tooltip content={_t("editor-toolbar.emoji")}>
514+
515+
{/* WILL RETURN WHEN FIXED ON ECENCY */}
516+
{/* <Tooltip content={_t("editor-toolbar.emoji")}>
515517
<div className="editor-tool" role="none">
516518
{emoticonHappyOutlineSvg}
517519
{showEmoji && <EmojiPicker fallback={(e) => {
518520
this.insertText(e, '');
519521
}}/>}
520522
</div>
521-
</Tooltip>
523+
</Tooltip> */}
522524
<Tooltip content="Markdown tutorial">
523525
<a href="https://commonmark.org/help/">
524526
<div className="editor-tool" role="none">
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
import React, { useState } from 'react'
2+
import { Button } from 'react-bootstrap';
3+
import { success } from '../feedback';
4+
import clipboard from '../../util/clipboard';
5+
import QRCode from 'react-qr-code';
6+
import { downloadSvg } from '../../img/svg';
7+
import { createFreeAccount, getAccountKeys } from '../../api/breakaway';
8+
import { _t } from '../../i18n';
9+
import { Link } from 'react-router-dom';
10+
11+
export const FreeAccount = (props: any) => {
12+
const {
13+
activeUser,
14+
username
15+
} = props;
16+
17+
const [keys, setKeys] = useState<any>(null)
18+
const [isDownloaded, setIsDownloaded] = useState<any>(false);
19+
const [message, setMessage] = useState("");
20+
const [step, setStep] = useState(1)
21+
22+
const createAccount = async () => {
23+
try {
24+
console.log(username)
25+
const response = await createFreeAccount(username, keys)
26+
console.log(response)
27+
if(response.success) {
28+
setStep(2)
29+
setMessage(response.message)
30+
}
31+
} catch (error) {
32+
console.log(error)
33+
}
34+
}
35+
const getKeys = async () => {
36+
try {
37+
console.log(username)
38+
const response = await getAccountKeys(username)
39+
console.log(response)
40+
if(response.success) {
41+
setKeys(response.accountDetails)
42+
}
43+
} catch (error) {
44+
console.log(error)
45+
}
46+
}
47+
48+
const downloadKeys = async () => {
49+
console.log("downloading.....")
50+
if (keys) {
51+
setIsDownloaded(false);
52+
const element = document.createElement("a");
53+
const keysToFile = `
54+
${_t("onboard.file-warning")}
55+
56+
${_t("onboard.recommend")}
57+
1. ${_t("onboard.recommend-print")}
58+
2. ${_t("onboard.recommend-use")}
59+
3. ${_t("onboard.recommend-save")}
60+
4. ${_t("onboard.recommend-third-party")}
61+
62+
${_t("onboard.account-info")}
63+
64+
Username: ${username}
65+
66+
Password: ${keys?.masterPassword}
67+
68+
${_t("onboard.owner-private")} ${keys.owner}
69+
70+
${_t("onboard.active-private")} ${keys.active}
71+
72+
${_t("onboard.posting-private")} ${keys.posting}
73+
74+
${_t("onboard.memo-private")} ${keys.memo}
75+
76+
77+
${_t("onboard.keys-use")}
78+
${_t("onboard.owner")} ${_t("onboard.owner-use")}
79+
${_t("onboard.active")} ${_t("onboard.active-use")}
80+
${_t("onboard.posting")} ${_t("onboard.posting-use")}
81+
${_t("onboard.memo")} ${_t("onboard.memo-use")}`;
82+
83+
const file = new Blob([keysToFile.replace(/\n/g, "\r\n")], {
84+
type: "text/plain",
85+
});
86+
element.href = URL.createObjectURL(file);
87+
element.download = `${username}_hive_keys.txt`;
88+
document.body.appendChild(element);
89+
element.click();
90+
setIsDownloaded(true);
91+
}
92+
};
93+
94+
return (
95+
<>
96+
<div className="success-wrapper">
97+
{step === 1 ? <>
98+
{!keys && <div className='d-flex flex-column'>
99+
<h2>Create a free Hive account</h2>
100+
<p>Click below to get your keys</p>
101+
<Button onClick={getKeys}>Get account keys</Button>
102+
</div >}
103+
{keys && (<div className="success-info">
104+
<h3>Creation steps</h3>
105+
{!activeUser && <>
106+
<strong style={{textAlign: "center"}}>
107+
Please make sure you have keychain installed as an
108+
extension on your browser (If you are a using the web
109+
browser, we recommend that you pin it to your browser.)
110+
</strong>
111+
<div className="keychain-ext">
112+
<p>Download the Hive Keychain extension for your preferred device:</p>
113+
<ul className="ul">
114+
<li className="kc-list">
115+
<img className="a-c" src="https://hive-keychain.com/img/browsers/android.svg" alt="" />
116+
<a
117+
href="https://play.google.com/store/apps/details?id=com.mobilekeychain"
118+
target="_blank"
119+
rel="noopener noreferrer"
120+
>
121+
Android
122+
</a>
123+
</li>
124+
<li className="kc-list">
125+
<img className="a-c" src="https://hive-keychain.com/img/browsers/ios.svg" alt="" />
126+
<a
127+
href="https://apps.apple.com/us/app/hive-keychain/id1552190010"
128+
target="_blank"
129+
rel="noopener noreferrer"
130+
>
131+
Apple
132+
</a>
133+
</li>
134+
<li className="kc-list">
135+
<img src="https://hive-keychain.com/img/browsers/chrome.svg" alt="" />
136+
<a
137+
href="https://chrome.google.com/webstore/detail/hive-keychain/jcacnejopjdphbnjgfaaobbfafkihpep?hl=en"
138+
target="_blank"
139+
rel="noopener noreferrer"
140+
>
141+
Chrome
142+
</a>
143+
</li>
144+
<li className="kc-list">
145+
<img src="https://hive-keychain.com/img/browsers/firefox.svg" alt="" />
146+
<a
147+
href="https://addons.mozilla.org/en-US/firefox/addon/hive-keychain/"
148+
target="_blank"
149+
rel="noopener noreferrer"
150+
>
151+
Mozilla
152+
</a>
153+
</li>
154+
<li className="kc-list">
155+
<img src="https://hive-keychain.com/img/browsers/brave.svg" alt="" />
156+
<a
157+
href="https://chrome.google.com/webstore/detail/hive-keychain/jcacnejopjdphbnjgfaaobbfafkihpep?hl=en"
158+
target="_blank"
159+
rel="noopener noreferrer"
160+
>
161+
Brave
162+
</a>
163+
</li>
164+
</ul>
165+
</div>
166+
</>}
167+
<div className="account-details">
168+
<span style={{ lineHeight: 2 }}>
169+
{_t("onboard.username")} <strong>{username}</strong>
170+
</span>
171+
</div>
172+
<div className="account-link">
173+
<h3>Step 1</h3>
174+
<p>Owner: {keys?.owner}</p>
175+
<p>Posting: {keys?.posting}</p>
176+
<p>Memo: {keys?.memo}</p>
177+
<p>Active: {keys?.active}</p>
178+
<span>Download your account keys</span>
179+
<Button className="mt-3" onClick={() => downloadKeys()}>
180+
{_t("onboard.download-keys")} {downloadSvg}
181+
</Button>
182+
</div>
183+
{isDownloaded && <div>
184+
<Button className="mt-3" onClick={createAccount}>
185+
Create account
186+
</Button>
187+
</div>}
188+
</div>)}
189+
</> : <div className='d-flex flex-column align-items-center'>
190+
<h1>{message}</h1>
191+
<Link to="/">
192+
<Button>Finish</Button>
193+
</Link>
194+
</div>}
195+
</div>
196+
</>
197+
)
198+
}

src/common/components/login/index.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import UserAvatar from "../user-avatar";
2323
import Tooltip from "../tooltip";
2424
import PopoverConfirm from "../popover-confirm";
2525
import OrDivider from "../or-divider";
26-
import {error} from "../feedback";
26+
import {error, success} from "../feedback";
2727

2828
import {getAuthUrl, makeHsCode} from "../../helper/hive-signer";
2929
import {hsLogin} from "../../../desktop/app/helper/hive-signer";
@@ -43,7 +43,7 @@ import _c from "../../util/fix-class-names";
4343

4444
import {deleteForeverSvg} from "../../img/svg";
4545
import { setupConfig } from "../../../setup";
46-
import { processLogin } from "../../api/breakaway";
46+
import { processLogin, getBtcWalletBalance, getUserByUsername } from "../../api/breakaway";
4747
import { getCommunity } from "../../api/bridge";
4848

4949
declare var window: AppWindow;
@@ -111,7 +111,39 @@ export class LoginKc extends BaseComponent<LoginKcProps, LoginKcState> {
111111

112112
this.stateSet({ inProgress: true });
113113

114+
let btcAddress;
115+
114116
try {
117+
const baUser = await getUserByUsername(username)
118+
119+
// if((this.props.global.hive_id === "hive-125568" || this.props.global.hive_id === "hive-159314" )) {
120+
// if(baUser?.bacUser?.bitcoinAddress) {
121+
// btcAddress = baUser?.bacUser?.bitcoinAddress
122+
// const addressBalance = await getBtcWalletBalance(baUser?.bacUser?.bitcoinAddress);
123+
// if(addressBalance.balance > 0.0005) {
124+
// error("You must have at least 0.0005 btc to login");
125+
// return;
126+
// } else {
127+
// success("Access granted...")
128+
// }
129+
130+
// if(this.props.global.hive_id === "hive-159314" && baUser?.bacUser?.ownsBTCMachine) {
131+
// error("Sorry, you have no bitcoin machine");
132+
// return;
133+
// } else {
134+
// success("Access granted...")
135+
// }
136+
// console.log(addressBalance)
137+
// } else {
138+
// error("Sorry, you have no bitcoin profile");
139+
// return
140+
// }
141+
142+
// } else {
143+
// success("Access granted...")
144+
// }
145+
146+
// return;
115147
account = await getAccount(username);
116148
} catch (err) {
117149
error(_t("login.error-user-fetch"));
@@ -126,11 +158,11 @@ export class LoginKc extends BaseComponent<LoginKcProps, LoginKcState> {
126158
}
127159

128160
const hasPostingPerm =
129-
account?.posting!.account_auths.filter((x) => x[0] === "ecency.app")
161+
account!.posting!.account_auths.filter((x) => x[0] === "ecency.app")
130162
.length > 0;
131163

132164
if (!hasPostingPerm) {
133-
const weight = account.posting!.weight_threshold;
165+
const weight = account!.posting!.weight_threshold;
134166

135167
this.stateSet({ inProgress: true });
136168
try {

0 commit comments

Comments
 (0)