|
| 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 | +} |
0 commit comments