-
Notifications
You must be signed in to change notification settings - Fork 50
Piyal dev #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Piyal dev #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ const ProtectedRoute = (props: RouteProps) => { | |
| return ( | ||
| <Redirect | ||
| to={{ | ||
| pathname: "/recover-account", | ||
| pathname: "/unlock-account", | ||
| search: location.search, | ||
| state: { from: location }, | ||
| }} | ||
|
|
@@ -68,7 +68,6 @@ const HomeRoute = () => { | |
| }; | ||
|
|
||
| const Routes = () => { | ||
| const applicationState = useSelector(applicationStateSelector); | ||
| const dispatch = useDispatch(); | ||
| useEffect(() => { | ||
| dispatch(loadAccount()); | ||
|
|
@@ -89,7 +88,7 @@ const Routes = () => { | |
| <ProtectedRoute path="/mnemonic-phrase"> | ||
| <MnemonicPhrase /> | ||
| </ProtectedRoute> | ||
| <Route path="/unlock"> | ||
| <Route path="/unlock-account"> | ||
| <UnlockAccount /> | ||
| </Route> | ||
| <Route path="/mnemonic-phrase-confirmed"> | ||
|
|
@@ -99,13 +98,9 @@ const Routes = () => { | |
| <CreatePassword /> | ||
| </Route> | ||
| <Route path="/recover-account"> | ||
| {applicationState !== APPLICATION_STATE.APPLICATION_STARTED ? ( | ||
| <UnlockAccount /> | ||
| ) : ( | ||
| <RecoverAccount /> | ||
| )} | ||
| <HomeRoute /> | ||
| <RecoverAccount /> | ||
| </Route> | ||
| <HomeRoute /> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixing some routing issues when jumping back into auth flow
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops! My b |
||
| </Switch> | ||
| </HashRouter> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,227 @@ | ||
| import connect from "./connect"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is just renaming the folder from 'services' to 'api'. since there was already an 'api' folder, it did a diff. ignore! |
||
| import submitTransaction from "./submitTransaction"; | ||
| import StellarSdk from "stellar-sdk"; | ||
|
|
||
| const injectApi = () => ({ | ||
| connect, | ||
| submitTransaction, | ||
| }); | ||
| import { | ||
| EXTENSION_ID, | ||
| SERVER_URL, | ||
| SERVICE_TYPES, | ||
| DEVELOPMENT, | ||
| APPLICATION_STATE, | ||
| } from "statics"; | ||
| import { Response } from "./types"; | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| lyra: any; | ||
| const server = new StellarSdk.Server(SERVER_URL); | ||
|
|
||
| export const createAccount = async ( | ||
| password: string, | ||
| ): Promise<{ publicKey: string }> => { | ||
| let publicKey = ""; | ||
|
|
||
| try { | ||
| ({ publicKey } = await sendMessageAndAwaitResponse({ | ||
| password, | ||
| type: SERVICE_TYPES.CREATE_ACCOUNT, | ||
| })); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
|
|
||
| return { publicKey }; | ||
| }; | ||
|
|
||
| export const loadAccount = async (): Promise<{ | ||
| publicKey: string; | ||
| applicationState: APPLICATION_STATE; | ||
| }> => { | ||
| let response = { | ||
| publicKey: "", | ||
| applicationState: APPLICATION_STATE.APPLICATION_STARTED, | ||
| }; | ||
|
|
||
| try { | ||
| response = await sendMessageAndAwaitResponse({ | ||
| type: SERVICE_TYPES.LOAD_ACCOUNT, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| return response; | ||
| }; | ||
|
|
||
| export const getMnemonicPhrase = async (): Promise<{ | ||
| mnemonicPhrase: string; | ||
| }> => { | ||
| let response = { mnemonicPhrase: "" }; | ||
|
|
||
| try { | ||
| response = await sendMessageAndAwaitResponse({ | ||
| type: SERVICE_TYPES.GET_MNEMONIC_PHRASE, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| return response; | ||
| }; | ||
|
|
||
| export const confirmMnemonicPhrase = async ( | ||
| mnemonicPhraseToConfirm: string, | ||
| ): Promise<{ | ||
| isCorrectPhrase: boolean; | ||
| applicationState: APPLICATION_STATE; | ||
| }> => { | ||
| let response = { | ||
| isCorrectPhrase: false, | ||
| applicationState: APPLICATION_STATE.PASSWORD_CREATED, | ||
| }; | ||
|
|
||
| try { | ||
| response = await sendMessageAndAwaitResponse({ | ||
| mnemonicPhraseToConfirm, | ||
| type: SERVICE_TYPES.CONFIRM_MNEMONIC_PHRASE, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| return response; | ||
| }; | ||
|
|
||
| export const recoverAccount = async ( | ||
| password: string, | ||
| recoverMnemonic: string, | ||
| ): Promise<{ publicKey: string }> => { | ||
| let publicKey = ""; | ||
|
|
||
| try { | ||
| ({ publicKey } = await sendMessageAndAwaitResponse({ | ||
| password, | ||
| recoverMnemonic, | ||
| type: SERVICE_TYPES.RECOVER_ACCOUNT, | ||
| })); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
|
|
||
| return { publicKey }; | ||
| }; | ||
|
|
||
| export const confirmPassword = async ( | ||
| password: string, | ||
| ): Promise<{ publicKey: string; applicationState: APPLICATION_STATE }> => { | ||
| let response = { | ||
| publicKey: "", | ||
| applicationState: APPLICATION_STATE.MNEMONIC_PHRASE_CONFIRMED, | ||
| }; | ||
| try { | ||
| response = await sendMessageAndAwaitResponse({ | ||
| password, | ||
| type: SERVICE_TYPES.CONFIRM_PASSWORD, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
|
|
||
| window.lyra = injectApi(); | ||
| return response; | ||
| }; | ||
|
|
||
| export const getAccountBalance = async ( | ||
| publicKey: string, | ||
| ): Promise<{ | ||
| balance: string; | ||
| }> => { | ||
| let response = { balances: [] }; | ||
|
|
||
| try { | ||
| response = await server.loadAccount(publicKey); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| return response.balances[0]; | ||
| }; | ||
|
|
||
| export const getPublicKey = async (): Promise<{ publicKey: string }> => { | ||
| let publicKey = ""; | ||
|
|
||
| try { | ||
| ({ publicKey } = await sendMessageAndAwaitResponsePublic({ | ||
| type: SERVICE_TYPES.LOAD_ACCOUNT, | ||
| })); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| return { publicKey }; | ||
| }; | ||
|
|
||
| export const rejectAccess = async (): Promise<void> => { | ||
| try { | ||
| await sendMessageAndAwaitResponse({ | ||
| type: SERVICE_TYPES.REJECT_ACCESS, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| }; | ||
|
|
||
| export const grantAccess = async (url: string): Promise<void> => { | ||
| try { | ||
| await sendMessageAndAwaitResponse({ | ||
| url, | ||
| type: SERVICE_TYPES.GRANT_ACCESS, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| }; | ||
|
|
||
| export const signTransaction = async ({ | ||
| password, | ||
| transaction, | ||
| }: { | ||
| password: string; | ||
| transaction: {}; | ||
| }): Promise<void> => { | ||
| try { | ||
| await sendMessageAndAwaitResponse({ | ||
| password, | ||
| transaction, | ||
| type: SERVICE_TYPES.SIGN_TRANSACTION, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| }; | ||
|
|
||
| export const signOut = async (): Promise<{ | ||
| publicKey: string; | ||
| applicationState: APPLICATION_STATE; | ||
| }> => { | ||
| let response = { | ||
| publicKey: "", | ||
| applicationState: APPLICATION_STATE.MNEMONIC_PHRASE_CONFIRMED, | ||
| }; | ||
| try { | ||
| response = await sendMessageAndAwaitResponse({ | ||
| type: SERVICE_TYPES.SIGN_OUT, | ||
| }); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
|
|
||
| return response; | ||
| }; | ||
|
|
||
| export const sendMessageAndAwaitResponse = (msg: {}): Promise<Response> => | ||
| new Promise((resolve) => { | ||
| if (DEVELOPMENT) { | ||
| chrome.runtime.sendMessage(EXTENSION_ID, msg, (res: Response) => | ||
| resolve(res), | ||
| ); | ||
| } else { | ||
| chrome.runtime.sendMessage(msg, (res: Response) => resolve(res)); | ||
| } | ||
| }); | ||
|
|
||
| export const sendMessageAndAwaitResponsePublic = (msg: {}): Promise<Response> => | ||
| new Promise((resolve) => { | ||
| chrome.runtime.sendMessage(EXTENSION_ID, msg, (res: Response) => | ||
| resolve(res), | ||
| ); | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from "react"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added a quick css tooltip component; not sure if we'll end up using it in the long run, but helpful for the moment |
||
| import styled from "styled-components"; | ||
|
|
||
| const TooltipEl = styled.span` | ||
| background: yellow; | ||
| color: black; | ||
| font-size: 0.7em; | ||
| margin-top: -4em; | ||
| position: absolute; | ||
| visibility: hidden; | ||
| text-shadow: none; | ||
| `; | ||
|
|
||
| interface TooltipProps { | ||
| className?: string; | ||
| text: string; | ||
| } | ||
|
|
||
| const Tooltip = ({ className, text }: TooltipProps) => ( | ||
| <TooltipEl className={className}>{text}</TooltipEl> | ||
| ); | ||
|
|
||
| export default Tooltip; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import React from "react"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will end up being where we stylize all error messages |
||
| import styled from "styled-components"; | ||
|
|
||
| const ErrorEl = styled.p` | ||
| color: red; | ||
| font-weight: bold; | ||
| `; | ||
|
|
||
| interface ErrorMessageProps { | ||
| authError: string; | ||
| } | ||
|
|
||
| export const ErrorMessage = ({ authError }: ErrorMessageProps) => ( | ||
| <>{authError ? <ErrorEl>{authError}</ErrorEl> : null}</> | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open these views in a new mini window instead of just a new tab