Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
feat: implement send over lightning and intraledger (#20)
Browse files Browse the repository at this point in the history
* feat: add the generic parse payment destination logic under a galoy-client folder (which will be a package later)

* feat: implement the send screen, ln-invoice works

* feat: make a sendFixedAmount component and add reset button

* feat: add action to handle no-amount invoices

* feat: implement sending over intraledger

Co-authored-by: Samer Buna <[email protected]>
  • Loading branch information
samerbuna and samerbuna authored Jan 12, 2022
1 parent ff63f26 commit 4f76ab4
Show file tree
Hide file tree
Showing 42 changed files with 1,188 additions and 85 deletions.
11 changes: 3 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ module.exports = {
"array-callback-return": "error",
"block-scoped-var": "error",
"camelcase": "error",
"capitalized-comments": "warn",
"complexity": "error",
"consistent-return": "error",
"consistent-this": "error",
"curly": "error",
"default-case-last": "error",
Expand All @@ -73,12 +70,12 @@ module.exports = {
"jsx-quotes": "error",
"linebreak-style": ["error", "unix"],
"max-depth": ["error", { max: 3 }],
"max-lines-per-function": ["error", { max: 200 }],
"max-lines-per-function": ["error", { max: 250 }],
"max-lines": ["error", { max: 300 }],
"max-nested-callbacks": ["error", { max: 2 }],
"max-params": ["error", { max: 2 }],
"max-statements-per-line": ["error", { max: 1 }],
"max-statements": ["error", { max: 30 }],
"max-statements": ["error", { max: 100 }],
"new-parens": "error",
"newline-per-chained-call": "error",
"no-alert": "error",
Expand Down Expand Up @@ -145,10 +142,8 @@ module.exports = {
"no-useless-return": "error",
"no-var": "error",
"no-void": "error",
"no-warning-comments": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-exponentiation-operator": "error",
"prefer-const": ["error", { destructuring: "all" }],
"prefer-numeric-literals": "error",
"prefer-object-spread": "error",
"prefer-promise-reject-errors": "error",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: yarn install
- run: (cd src/galoy-client && yarn install)
- name: Run check code
run: yarn code:check
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: yarn install
- run: (cd src/galoy-client && yarn install)
- name: Run all tests
run: yarn test
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@
"regenerator-runtime": "^0.13.9",
"serialize-javascript": "^6.0.0",
"source-map-loader": "^3.0.0",
"stream-browserify": "^3.0.0",
"style-loader": "^3.3.1",
"subscriptions-transport-ws": "^0.11.0",
"ts-loader": "^9.2.6",
"typescript": "^4.5.4",
"url": "^0.11.0",
"use-debounce": "^7.0.1",
"webpack": "^5.64.4",
"webpack-cli": "^4.9.1"
Expand Down
49 changes: 49 additions & 0 deletions src/components/debounced-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ChangeEvent, useState, memo, useEffect } from "react"
import { useDebouncedCallback } from "use-debounce"

export type OnInputValueChange = (value: string) => void

type Props = {
onChange?: OnInputValueChange
onDebouncedChange?: OnInputValueChange
[prop: string]: unknown
}

type InputObject = {
value: string
debouncedValue?: string
typing: boolean
}

const DebouncedInput = ({ onChange, onDebouncedChange, ...inputProps }: Props) => {
const [input, setInput] = useState<InputObject>({ value: "", typing: false })

const setDebouncedInputValue = useDebouncedCallback((debouncedValue) => {
setInput((currInput) => ({ ...currInput, debouncedValue, typing: false }))
}, 1000)

useEffect(() => {
if (input.typing) {
setDebouncedInputValue(input.value)
}
return () => setDebouncedInputValue.cancel()
}, [setDebouncedInputValue, input.typing, input.value])

useEffect(() => {
if (onDebouncedChange && input.debouncedValue !== undefined) {
onDebouncedChange(input.debouncedValue)
}
}, [onDebouncedChange, input.debouncedValue])

const handleOnChange = (event: ChangeEvent<HTMLInputElement>) => {
const newValue = event.target.value
if (onChange) {
onChange(newValue)
}
setInput({ value: newValue, typing: true })
}

return <input value={input.value} onChange={handleOnChange} {...inputProps} />
}

export default memo(DebouncedInput)
2 changes: 1 addition & 1 deletion src/components/debounced-textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeEvent, useState, memo, useEffect } from "react"
import { useDebouncedCallback } from "use-debounce"

export type OnTextValueChange = (numberValue: string) => void
export type OnTextValueChange = (value: string) => void

type Props = {
onChange?: OnTextValueChange
Expand Down
2 changes: 1 addition & 1 deletion src/components/error-fallback.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from "server/config"
import config from "store/config"

type Props = { error: string | Error }

Expand Down
4 changes: 2 additions & 2 deletions src/components/formatted-number-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useDebouncedCallback } from "use-debounce"

const formatter = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 })

export type ParsieInputValueFunction = (inputValue: string) => {
export type ParseInputValueFunction = (inputValue: string) => {
numberValue: number | ""
formattedValue: string
}

const parseInputValue: ParsieInputValueFunction = (inputValue) => {
const parseInputValue: ParseInputValueFunction = (inputValue) => {
if (inputValue === "") {
return { numberValue: "", formattedValue: "" }
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import copy from "copy-to-clipboard"
import { useMyUpdates } from "store/use-my-updates"
import { translate } from "translate"
import SuccessCheckmark from "./sucess-checkmark"
import { useAppDispatcher } from "store"

type Props = {
invoice: GraphQL.LnInvoice | GraphQL.LnNoAmountInvoice
onPaymentSuccess?: () => void
}

const Invoice = ({ invoice, onPaymentSuccess }: Props) => {
const dispatch = useAppDispatcher()
const { lnUpdate } = useMyUpdates()
const [showCopied, setShowCopied] = useState(false)

Expand All @@ -21,6 +23,10 @@ const Invoice = ({ invoice, onPaymentSuccess }: Props) => {
setTimeout(() => setShowCopied(false), 3000)
}

const resetReceiveScreen = () => {
dispatch({ type: "reset-current-screen" })
}

const invoicePaid =
lnUpdate?.paymentHash === invoice?.paymentHash && lnUpdate?.status === "PAID"

Expand All @@ -32,6 +38,7 @@ const Invoice = ({ invoice, onPaymentSuccess }: Props) => {
return (
<div className="invoice-paid">
<SuccessCheckmark />
<button onClick={resetReceiveScreen}>Receive another payment</button>
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/login.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useRef, useState } from "react"
import intlTelInput from "intl-tel-input"

import config from "server/config"
import config from "store/config"
import { translate } from "translate"
import { history, useRequest } from "store"

Expand Down
6 changes: 3 additions & 3 deletions src/components/receive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const Receive = () => {
<div className="receive">
<Header />
<div className="page-title">{translate("Receive Bitcoin")}</div>{" "}
<div className="amount-input">
<div className="amount-input center-display">
<div className="currency-label">
{input.currency === "SATS" ? <SatSymbol /> : "$"}
</div>
Expand All @@ -175,7 +175,7 @@ const Receive = () => {
&#8645;
</div>
</div>
<div className="note-input">
<div className="note-input center-display">
<DebouncedTextarea
onDebouncedChange={handleDebouncedMemoUpdate}
name="memo"
Expand All @@ -188,7 +188,7 @@ const Receive = () => {
<div className="amount-converted">{conversionDisplay}</div>
</div>
)}
<div className="invoice-container">
<div className="action-container center-display">
{showInvoiceSpinner && <Spinner size="big" />}
{showInvoice && (
<InvoiceGenerator
Expand Down
14 changes: 7 additions & 7 deletions src/components/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import { setLocale } from "translate"
import RootComponent from "../components/root-component"
import { useErrorHandler } from "react-error-boundary"

type RootProps = { initialState: InitialState }
type RootProps = { GwwState: GwwState }

const Root = ({ initialState }: RootProps) => {
const Root = ({ GwwState }: RootProps) => {
const handleError = useErrorHandler()
const [state, dispatch] = useReducer(mainReducer, initialState, (initState) => {
const [state, dispatch] = useReducer(mainReducer, GwwState, (initState) => {
setLocale(initState.defaultLanguage)
return initState
})
Expand Down Expand Up @@ -58,19 +58,19 @@ const Root = ({ initialState }: RootProps) => {
return (
<ApolloProvider client={apolloClient}>
<GwwContext.Provider value={{ state, dispatch }}>
<RootComponent path={state.path} />
<RootComponent path={state.path} key={state.key} />
</GwwContext.Provider>
</ApolloProvider>
)
}

type SSRootProps = {
client: ApolloClient<unknown>
initialState: InitialState
GwwState: GwwState
}

export const SSRRoot = ({ client, initialState }: SSRootProps) => {
const [state, dispatch] = useReducer(mainReducer, initialState, (initState) => {
export const SSRRoot = ({ client, GwwState }: SSRootProps) => {
const [state, dispatch] = useReducer(mainReducer, GwwState, (initState) => {
setLocale(initState.defaultLanguage)
return initState
})
Expand Down
Loading

0 comments on commit 4f76ab4

Please sign in to comment.