Skip to content

Commit

Permalink
Merge pull request #56 from spknetwork/signup-refactor
Browse files Browse the repository at this point in the history
Signup refactor
  • Loading branch information
Adesojisouljay authored Nov 12, 2024
2 parents e98b37c + ef92b8e commit 1200ea8
Show file tree
Hide file tree
Showing 12 changed files with 705 additions and 25 deletions.
40 changes: 38 additions & 2 deletions src/common/api/breakaway.ts
Original file line number Diff line number Diff line change
@@ -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)=> {
Expand Down Expand Up @@ -144,5 +144,41 @@ export const getBtcTransactions = async (address: string) => {
}
};

export const getUserByUsername = async (username: string) => {
try {
const response = await axios.get(`${baUrl}/user/${username}`);

console.log(response)

return response.data;
} catch (error) {
console.error('Error fetching user by username:', error);
throw error;
}
};

export const createFreeAccount = async (username: string, keys: any) => {
try {
const response = await axios.post(`${baUrl}/create-free-account`, {username, accountKeys: keys});

console.log(response)

return response.data;
} catch (error) {
console.error('Something went wrong:', error);
throw error;
}
};

export const getAccountKeys = async (username: string) => {
try {
const response = await axios.post(`${baUrl}/get-account-keys`, {username});

console.log(response)

return response.data;
} catch (error) {
console.error('Something went wrong:', error);
throw error;
}
};
6 changes: 4 additions & 2 deletions src/common/components/editor-toolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,16 @@ export class EditorToolbar extends Component<Props> {
</div>
</div>
</Tooltip>
<Tooltip content={_t("editor-toolbar.emoji")}>

{/* WILL RETURN WHEN FIXED ON ECENCY */}
{/* <Tooltip content={_t("editor-toolbar.emoji")}>
<div className="editor-tool" role="none">
{emoticonHappyOutlineSvg}
{showEmoji && <EmojiPicker fallback={(e) => {
this.insertText(e, '');
}}/>}
</div>
</Tooltip>
</Tooltip> */}
<Tooltip content="Markdown tutorial">
<a href="https://commonmark.org/help/">
<div className="editor-tool" role="none">
Expand Down
198 changes: 198 additions & 0 deletions src/common/components/free-account/FreeAccount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import React, { useState } from 'react'
import { Button } from 'react-bootstrap';
import { success } from '../feedback';
import clipboard from '../../util/clipboard';
import QRCode from 'react-qr-code';
import { downloadSvg } from '../../img/svg';
import { createFreeAccount, getAccountKeys } from '../../api/breakaway';
import { _t } from '../../i18n';
import { Link } from 'react-router-dom';

export const FreeAccount = (props: any) => {
const {
activeUser,
username
} = props;

const [keys, setKeys] = useState<any>(null)
const [isDownloaded, setIsDownloaded] = useState<any>(false);
const [message, setMessage] = useState("");
const [step, setStep] = useState(1)

const createAccount = async () => {
try {
console.log(username)
const response = await createFreeAccount(username, keys)
console.log(response)
if(response.success) {
setStep(2)
setMessage(response.message)
}
} catch (error) {
console.log(error)
}
}
const getKeys = async () => {
try {
console.log(username)
const response = await getAccountKeys(username)
console.log(response)
if(response.success) {
setKeys(response.accountDetails)
}
} catch (error) {
console.log(error)
}
}

const downloadKeys = async () => {
console.log("downloading.....")
if (keys) {
setIsDownloaded(false);
const element = document.createElement("a");
const keysToFile = `
${_t("onboard.file-warning")}
${_t("onboard.recommend")}
1. ${_t("onboard.recommend-print")}
2. ${_t("onboard.recommend-use")}
3. ${_t("onboard.recommend-save")}
4. ${_t("onboard.recommend-third-party")}
${_t("onboard.account-info")}
Username: ${username}
Password: ${keys?.masterPassword}
${_t("onboard.owner-private")} ${keys.owner}
${_t("onboard.active-private")} ${keys.active}
${_t("onboard.posting-private")} ${keys.posting}
${_t("onboard.memo-private")} ${keys.memo}
${_t("onboard.keys-use")}
${_t("onboard.owner")} ${_t("onboard.owner-use")}
${_t("onboard.active")} ${_t("onboard.active-use")}
${_t("onboard.posting")} ${_t("onboard.posting-use")}
${_t("onboard.memo")} ${_t("onboard.memo-use")}`;

const file = new Blob([keysToFile.replace(/\n/g, "\r\n")], {
type: "text/plain",
});
element.href = URL.createObjectURL(file);
element.download = `${username}_hive_keys.txt`;
document.body.appendChild(element);
element.click();
setIsDownloaded(true);
}
};

return (
<>
<div className="success-wrapper">
{step === 1 ? <>
{!keys && <div className='d-flex flex-column'>
<h2>Create a free Hive account</h2>
<p>Click below to get your keys</p>
<Button onClick={getKeys}>Get account keys</Button>
</div >}
{keys && (<div className="success-info">
<h3>Creation steps</h3>
{!activeUser && <>
<strong style={{textAlign: "center"}}>
Please make sure you have keychain installed as an
extension on your browser (If you are a using the web
browser, we recommend that you pin it to your browser.)
</strong>
<div className="keychain-ext">
<p>Download the Hive Keychain extension for your preferred device:</p>
<ul className="ul">
<li className="kc-list">
<img className="a-c" src="https://hive-keychain.com/img/browsers/android.svg" alt="" />
<a
href="https://play.google.com/store/apps/details?id=com.mobilekeychain"
target="_blank"
rel="noopener noreferrer"
>
Android
</a>
</li>
<li className="kc-list">
<img className="a-c" src="https://hive-keychain.com/img/browsers/ios.svg" alt="" />
<a
href="https://apps.apple.com/us/app/hive-keychain/id1552190010"
target="_blank"
rel="noopener noreferrer"
>
Apple
</a>
</li>
<li className="kc-list">
<img src="https://hive-keychain.com/img/browsers/chrome.svg" alt="" />
<a
href="https://chrome.google.com/webstore/detail/hive-keychain/jcacnejopjdphbnjgfaaobbfafkihpep?hl=en"
target="_blank"
rel="noopener noreferrer"
>
Chrome
</a>
</li>
<li className="kc-list">
<img src="https://hive-keychain.com/img/browsers/firefox.svg" alt="" />
<a
href="https://addons.mozilla.org/en-US/firefox/addon/hive-keychain/"
target="_blank"
rel="noopener noreferrer"
>
Mozilla
</a>
</li>
<li className="kc-list">
<img src="https://hive-keychain.com/img/browsers/brave.svg" alt="" />
<a
href="https://chrome.google.com/webstore/detail/hive-keychain/jcacnejopjdphbnjgfaaobbfafkihpep?hl=en"
target="_blank"
rel="noopener noreferrer"
>
Brave
</a>
</li>
</ul>
</div>
</>}
<div className="account-details">
<span style={{ lineHeight: 2 }}>
{_t("onboard.username")} <strong>{username}</strong>
</span>
</div>
<div className="account-link">
<h3>Step 1</h3>
<p>Owner: {keys?.owner}</p>
<p>Posting: {keys?.posting}</p>
<p>Memo: {keys?.memo}</p>
<p>Active: {keys?.active}</p>
<span>Download your account keys</span>
<Button className="mt-3" onClick={() => downloadKeys()}>
{_t("onboard.download-keys")} {downloadSvg}
</Button>
</div>
{isDownloaded && <div>
<Button className="mt-3" onClick={createAccount}>
Create account
</Button>
</div>}
</div>)}
</> : <div className='d-flex flex-column align-items-center'>
<h1>{message}</h1>
<Link to="/">
<Button>Finish</Button>
</Link>
</div>}
</div>
</>
)
}
40 changes: 36 additions & 4 deletions src/common/components/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import UserAvatar from "../user-avatar";
import Tooltip from "../tooltip";
import PopoverConfirm from "../popover-confirm";
import OrDivider from "../or-divider";
import {error} from "../feedback";
import {error, success} from "../feedback";

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

import {deleteForeverSvg} from "../../img/svg";
import { setupConfig } from "../../../setup";
import { processLogin } from "../../api/breakaway";
import { processLogin, getBtcWalletBalance, getUserByUsername } from "../../api/breakaway";
import { getCommunity } from "../../api/bridge";

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

this.stateSet({ inProgress: true });

let btcAddress;

try {
const baUser = await getUserByUsername(username)

// if((this.props.global.hive_id === "hive-125568" || this.props.global.hive_id === "hive-159314" )) {
// if(baUser?.bacUser?.bitcoinAddress) {
// btcAddress = baUser?.bacUser?.bitcoinAddress
// const addressBalance = await getBtcWalletBalance(baUser?.bacUser?.bitcoinAddress);
// if(addressBalance.balance > 0.0005) {
// error("You must have at least 0.0005 btc to login");
// return;
// } else {
// success("Access granted...")
// }

// if(this.props.global.hive_id === "hive-159314" && baUser?.bacUser?.ownsBTCMachine) {
// error("Sorry, you have no bitcoin machine");
// return;
// } else {
// success("Access granted...")
// }
// console.log(addressBalance)
// } else {
// error("Sorry, you have no bitcoin profile");
// return
// }

// } else {
// success("Access granted...")
// }

// return;
account = await getAccount(username);
} catch (err) {
error(_t("login.error-user-fetch"));
Expand All @@ -126,11 +158,11 @@ export class LoginKc extends BaseComponent<LoginKcProps, LoginKcState> {
}

const hasPostingPerm =
account?.posting!.account_auths.filter((x) => x[0] === "ecency.app")
account!.posting!.account_auths.filter((x) => x[0] === "ecency.app")
.length > 0;

if (!hasPostingPerm) {
const weight = account.posting!.weight_threshold;
const weight = account!.posting!.weight_threshold;

this.stateSet({ inProgress: true });
try {
Expand Down
Loading

0 comments on commit 1200ea8

Please sign in to comment.