Skip to content

Commit

Permalink
Merge pull request #95 from breez/ci-react-native
Browse files Browse the repository at this point in the history
Ci react native
  • Loading branch information
ok300 authored Nov 13, 2023
2 parents 7f246c7 + 542fd9d commit 5fa2297
Show file tree
Hide file tree
Showing 21 changed files with 1,933 additions and 251 deletions.
35 changes: 34 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
repository: breez/breez-sdk
ref: ${{ needs.setup.outputs.sdk-ref }}
package-version: ${{ needs.setup.outputs.package-version }}
packages-to-publish: '["csharp", "flutter", "golang"]'
packages-to-publish: '["csharp", "flutter", "golang", "react-native"]'
use-dummy-binaries: true

check-rust:
Expand Down Expand Up @@ -156,6 +156,39 @@ jobs:
- name: Build the csharp project
working-directory: snippets/csharp
run: dotnet build

check-react-native:
needs:
- setup
- build-packages
name: Check react native snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x

- name: Download archived package
uses: actions/download-artifact@v3
with:
name: react-native-${{ needs.setup.outputs.package-version }}
path: snippets/react-native/packages

- name: Install dependencies
working-directory: snippets/react-native
run: yarn

- name: Check syntax
working-directory: snippets/react-native
run: tsc

- name: Check formatting
working-directory: snippets/react-native
run: yarn run lint

check-golang:
needs:
Expand Down
43 changes: 43 additions & 0 deletions snippets/react-native/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
env: {
browser: true,
es2021: true
},
extends: [
'standard-with-typescript',
'plugin:react/recommended'
],
overrides: [
{
env: {
node: true
},
files: [
'.eslintrc.{js,cjs}'
],
parserOptions: {
sourceType: 'script'
}
}
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: [
'./tsconfig.json'
]
},
plugins: [
'react'
],
rules: {
'@typescript-eslint/explicit-function-return': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-unused-vars': 'off'
},
settings: {
react: {
version: 'detect'
}
}
}
8 changes: 0 additions & 8 deletions snippets/react-native/.prettierrc

This file was deleted.

7 changes: 7 additions & 0 deletions snippets/react-native/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Steps to compile the snippets locally
1. Build a react native package
- By running the publish-all-platforms CI in the breez-sdk repository (use dummy binaries)
2. Download the react-native-{VERSION} artifact
3. Unzip the artifact and put the `sdk-react-native.tgz` file in the `snippets/react-native/packages` folder
4. Run `yarn` to install the package.
5. happy coding
16 changes: 8 additions & 8 deletions snippets/react-native/buy_btc.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
buyBitcoin,
BuyBitcoinProvider
} from "@breeztech/react-native-breez-sdk"
buyBitcoin,
BuyBitcoinProvider
} from '@breeztech/react-native-breez-sdk'

const exampleBuyBtc = async () => {
// ANCHOR: buy-btc
const buyBitcoinResponse = await buyBitcoin({
provider: BuyBitcoinProvider.MOONPAY
})
// ANCHOR_END: buy-btc
// ANCHOR: buy-btc
const buyBitcoinResponse = await buyBitcoin({
provider: BuyBitcoinProvider.MOONPAY
})
// ANCHOR_END: buy-btc
}
18 changes: 9 additions & 9 deletions snippets/react-native/connecting_lsp.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { connectLsp, lspId, lspInfo } from "@breeztech/react-native-breez-sdk"
import { connectLsp, lspId, lspInfo } from '@breeztech/react-native-breez-sdk'

const exampleAutoConnect = async () => {
// ANCHOR: get-lsp-info
const id = await lspId()
const info = await lspInfo()
// ANCHOR_END: get-lsp-info
// ANCHOR: get-lsp-info
const id = await lspId()
const info = await lspInfo()
// ANCHOR_END: get-lsp-info
}

const exampleManualConnect = async () => {
// ANCHOR: connect-lsp
const id = "your selected lsp id"
await connectLsp(id)
// ANCHOR_END: connect-lsp
// ANCHOR: connect-lsp
const id = 'your selected lsp id'
await connectLsp(id)
// ANCHOR_END: connect-lsp
}
24 changes: 12 additions & 12 deletions snippets/react-native/fiat_currencies.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {
listFiatCurrencies,
fetchFiatRates
} from "@breeztech/react-native-breez-sdk"
listFiatCurrencies,
fetchFiatRates
} from '@breeztech/react-native-breez-sdk'

const exampleListCurrencies = async () => {
// ANCHOR: list-fiat-currencies
const fiatCurrencies = await listFiatCurrencies()
// ANCHOR_END: list-fiat-currencies
// ANCHOR: list-fiat-currencies
const fiatCurrencies = await listFiatCurrencies()
// ANCHOR_END: list-fiat-currencies
}

const exampleFetchRates = async () => {
// ANCHOR: fetch-fiat-rates
const fiatRates = await fetchFiatRates()
// ANCHOR_END: fetch-fiat-rates
// ANCHOR: fetch-fiat-rates
const fiatRates = await fetchFiatRates()
// ANCHOR_END: fetch-fiat-rates
}

const exampleListCurrenciesAndRates = async () => {
// ANCHOR: get-fiat-currencies-and-rates
// TODO
// ANCHOR_END: get-fiat-currencies-and-rates
// ANCHOR: get-fiat-currencies-and-rates
// TODO
// ANCHOR_END: get-fiat-currencies-and-rates
}
72 changes: 36 additions & 36 deletions snippets/react-native/getting_started.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import {
BreezEvent,
connect,
defaultConfig,
EnvironmentType,
mnemonicToSeed,
NodeConfig,
NodeConfigVariant,
nodeInfo
} from "@breeztech/react-native-breez-sdk"
type BreezEvent,
connect,
defaultConfig,
EnvironmentType,
mnemonicToSeed,
type NodeConfig,
NodeConfigVariant,
nodeInfo
} from '@breeztech/react-native-breez-sdk'

const exampleGettingStarted = async () => {
// ANCHOR: init-sdk
// SDK events listener
const onBreezEvent = (e: BreezEvent) => {
console.log(`Received event ${e.type}`)
}
// ANCHOR: init-sdk
// SDK events listener
const onBreezEvent = (e: BreezEvent) => {
console.log(`Received event ${e.type}`)
}

// Create the default config
const seed = await mnemonicToSeed("<mnemonics words>")
const inviteCode = "<invite code>"
const apiKey = "<api key>"
const nodeConfig: NodeConfig = {
type: NodeConfigVariant.GREENLIGHT,
config: {
inviteCode
}
// Create the default config
const seed = await mnemonicToSeed('<mnemonics words>')
const inviteCode = '<invite code>'
const apiKey = '<api key>'
const nodeConfig: NodeConfig = {
type: NodeConfigVariant.GREENLIGHT,
config: {
inviteCode
}
}

const config = await defaultConfig(
EnvironmentType.PRODUCTION,
apiKey,
nodeConfig
)
const config = await defaultConfig(
EnvironmentType.PRODUCTION,
apiKey,
nodeConfig
)

// Connect to the Breez SDK make it ready for use
await connect(config, seed, onBreezEvent)
// ANCHOR_END: init-sdk
// Connect to the Breez SDK make it ready for use
await connect(config, seed, onBreezEvent)
// ANCHOR_END: init-sdk
}

const exampleFetchNodeInfo = async () => {
// ANCHOR: fetch-balance
const nodeState = await nodeInfo()
const balanceLn = nodeState.channelsBalanceMsat
const balanceOnchain = nodeState.onchainBalanceMsat
// ANCHOR_END: fetch-balance
// ANCHOR: fetch-balance
const nodeState = await nodeInfo()
const balanceLn = nodeState.channelsBalanceMsat
const balanceOnchain = nodeState.onchainBalanceMsat
// ANCHOR_END: fetch-balance
}
26 changes: 13 additions & 13 deletions snippets/react-native/list_payments.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import {
listPayments,
PaymentTypeFilter
} from "@breeztech/react-native-breez-sdk"
listPayments,
PaymentTypeFilter
} from '@breeztech/react-native-breez-sdk'

const exampleListPayments = async () => {
// ANCHOR: list-payments
const payments = listPayments({ filter: PaymentTypeFilter.ALL })
// ANCHOR_END: list-payments
// ANCHOR: list-payments
const payments = listPayments({ filter: PaymentTypeFilter.ALL })
// ANCHOR_END: list-payments
}

const exampleListPaymentsFiltered = async () => {
// ANCHOR: list-payments-filtered
const payments = listPayments({
filter: PaymentTypeFilter.SENT,
fromTimestamp: 1696880000,
includeFailures: true
})
// ANCHOR_END: list-payments-filtered
// ANCHOR: list-payments-filtered
const payments = listPayments({
filter: PaymentTypeFilter.SENT,
fromTimestamp: 1696880000,
includeFailures: true
})
// ANCHOR_END: list-payments-filtered
}
38 changes: 19 additions & 19 deletions snippets/react-native/lnurl_auth.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import {
InputTypeVariant,
lnurlAuth,
LnUrlCallbackStatusVariant,
parseInput
} from "@breeztech/react-native-breez-sdk"
InputTypeVariant,
lnurlAuth,
LnUrlCallbackStatusVariant,
parseInput
} from '@breeztech/react-native-breez-sdk'

const exampleLnurlAuth = async () => {
// ANCHOR: lnurl-auth
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
const lnurlAuthUrl =
"lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
// ANCHOR: lnurl-auth
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
const lnurlAuthUrl =
'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu'

const input = await parseInput(lnurlAuthUrl)
if (input.type === InputTypeVariant.LN_URL_AUTH) {
const result = await lnurlAuth(input.data)
if (result.type === LnUrlCallbackStatusVariant.OK) {
console.log("Successfully authenticated")
} else {
console.log("Failed to authenticate")
}
const input = await parseInput(lnurlAuthUrl)
if (input.type === InputTypeVariant.LN_URL_AUTH) {
const result = await lnurlAuth(input.data)
if (result.type === LnUrlCallbackStatusVariant.OK) {
console.log('Successfully authenticated')
} else {
console.log('Failed to authenticate')
}
// ANCHOR_END: lnurl-auth
}
// ANCHOR_END: lnurl-auth
}
38 changes: 19 additions & 19 deletions snippets/react-native/lnurl_pay.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import {
InputTypeVariant,
parseInput,
payLnurl
} from "@breeztech/react-native-breez-sdk"
InputTypeVariant,
parseInput,
payLnurl
} from '@breeztech/react-native-breez-sdk'

const exampleLnurlPay = async () => {
// ANCHOR: lnurl-pay
// Endpoint can also be of the
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
const lnurlPayUrl = "[email protected]"
// ANCHOR: lnurl-pay
// Endpoint can also be of the
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
const lnurlPayUrl = '[email protected]'

const input = await parseInput(lnurlPayUrl)
if (input.type === InputTypeVariant.LN_URL_PAY) {
const amountMsat = input.data.minSendable
const lnUrlPayResult = await payLnurl({
data: input.data,
amountMsat,
comment: "comment"
})
}
// ANCHOR_END: lnurl-pay
const input = await parseInput(lnurlPayUrl)
if (input.type === InputTypeVariant.LN_URL_PAY) {
const amountMsat = input.data.minSendable
const lnUrlPayResult = await payLnurl({
data: input.data,
amountMsat,
comment: 'comment'
})
}
// ANCHOR_END: lnurl-pay
}
Loading

0 comments on commit 5fa2297

Please sign in to comment.