Skip to content

Commit def434f

Browse files
authored
Merge pull request #1010 from PayButton/feat/multiple-chornik-servers
feat: multiple chronik servers
2 parents 6ed9c0f + a51ab12 commit def434f

17 files changed

Lines changed: 244 additions & 142 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
git_hook_setup = cp .githooks/pre-commit .git/hooks/pre-commit
22
git_diff_to_master = git diff --name-only --diff-filter=ACMRTUXB origin/master > DIFF
3-
create_test_paybutton_json = echo { \"priceAPIURL\": \"foo\", \"networkBlockchainClients\": { \"ecash\": \"chronik\", \"bitcoincash\": \"chronik\" }, \"networkBlockchainURLs\": { \"ecash\": \"https://xec.paybutton.io\", \"bitcoincash\": \"https://bch.paybutton.io\" }, \"wsBaseURL\": \"http://localhost:5000\", \"apiDomain\": \"http://localhost:3000\" } > paybutton-config.json
3+
create_test_paybutton_json = echo { \"priceAPIURL\": \"foo\", \"networkBlockchainClients\": { \"ecash\": \"chronik\", \"bitcoincash\": \"chronik\" }, \"networkBlockchainURLs\": { \"ecash\": [\"https://xec.paybutton.io\"], \"bitcoincash\": [\"https://bch.paybutton.io\"] }, \"wsBaseURL\": \"http://localhost:5000\", \"apiDomain\": \"http://localhost:3000\" } > paybutton-config.json
44
touch_local_env = touch .env.local
55

66
prod:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ default: false,
122122
#### networkBlockchainURLs
123123
```
124124
type: {
125-
"ecash": "https://chronik.fabien.cash",
126-
"bitcoincash": "https://chronik.pay2stay.com/bch"
125+
"ecash": ["https://xec.paybutton.org", "https://chronik.fabien.cash"],
126+
"bitcoincash": ["https://chronik.pay2stay.com/bch"]
127127
}
128128

129129
```

components/Admin/ChronikURLs.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { MainNetworkSlugsType } from 'constants/index'
2+
3+
interface IProps {
4+
chronikUrls: Record<MainNetworkSlugsType, string[]>
5+
}
6+
export default function ChronikURLs ({ chronikUrls }: IProps): JSX.Element {
7+
return <>
8+
<h3>Chronik URLs</h3>
9+
<div className="paybutton-table-ctn columns">
10+
<div>
11+
<h4>eCash</h4>
12+
<ol>
13+
{chronikUrls.ecash.map((url, idx) => <li key={idx}>{url}</li>)}
14+
</ol>
15+
</div>
16+
<div>
17+
<h4>Bitcoin Cash</h4>
18+
<ol>
19+
{chronikUrls.bitcoincash.map((url, idx) => <li key={idx}>{url}</li>)}
20+
</ol>
21+
</div>
22+
</div>
23+
</>
24+
}

components/Admin/RegisteredUsers.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ import { UserWithSupertokens } from 'services/userService'
22
import style from './admin.module.css'
33
import moment from 'moment'
44
import TableContainer from '../../components/TableContainer/TableContainer'
5+
import { Cell, CellProps } from 'react-table'
56

67
interface IProps {
78
users: UserWithSupertokens[]
89
}
910

10-
export default function RegisteredUsers({ users }: IProps): JSX.Element {
11+
export default function RegisteredUsers ({ users }: IProps): JSX.Element {
1112
if (users === undefined) return <></>
1213

1314
const columns = [
1415
{
1516
Header: 'Registered',
1617
accessor: 'registered',
17-
Cell: ({ cell }: any) => <span>{cell.value}</span>
18+
Cell: ({ cell }: CellProps<UserWithSupertokens>) => <span>{cell.value}</span>
1819
},
1920
{
2021
Header: 'Email',
2122
accessor: 'email',
22-
Cell: ({ cell }: any) => (
23+
Cell: ({ cell }: Cell<UserWithSupertokens>) => (
2324
<a
24-
href={`/api/auth/dashboard/?userid=${cell.row.original.id}&recipeId=emailpassword`}
25+
href={`/api/auth/dashboard/?userid=${cell.row.original.id as string}&recipeId=emailpassword`}
2526
target="_blank"
2627
rel="noopener noreferrer"
2728
>
@@ -32,18 +33,21 @@ export default function RegisteredUsers({ users }: IProps): JSX.Element {
3233
{
3334
Header: 'Admin',
3435
accessor: 'isAdmin',
35-
Cell: ({ cell }: any) => (
36+
Cell: ({ cell }: CellProps<UserWithSupertokens>) => (
3637
cell.value === true ? <span className={style.admin}>Yes</span> : 'No'
3738
)
3839
}
3940
]
40-
console.log({users})
41+
console.log({ users })
4142
const data = users.map(user => ({
4243
id: (user.stUser?.id === undefined || user.stUser?.id === '') ? user.userProfile?.id : user.stUser?.id,
43-
registered: user.stUser ? moment(user.stUser.timeJoined).fromNow() : 'NO ST USER FOUND',
44+
registered: (user.stUser != null) ? moment(user.stUser.timeJoined).fromNow() : 'NO ST USER FOUND',
4445
email: (user.stUser?.email === undefined || user.stUser?.email === '') ? user.userProfile?.id : user.stUser?.email,
4546
isAdmin: user.userProfile?.isAdmin
4647
}))
4748

48-
return <TableContainer columns={columns} data={data} ssr />
49+
return <>
50+
<h3>Registered Users</h3>
51+
<TableContainer columns={columns} data={data} ssr />
52+
</>
4953
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useEffect, useMemo, useState } from 'react'
2+
import Image from 'next/image'
3+
import EyeIcon from 'assets/eye-icon.png'
4+
import TableContainer from 'components/TableContainer/TableContainer'
5+
6+
export default function SubscribedAddresses (): JSX.Element {
7+
const [ecashSubscribedAddresses, setEcashSubscribedAddresses] = useState<string[]>([])
8+
const [bitcoincashSubscribedAddresses, setBitcoincashSubscribedAddresses] = useState<string[]>([])
9+
10+
useEffect(() => {
11+
void (async () => {
12+
const ok = await (await fetch('chronikStatus')).json()
13+
const subscribedEcashAddresses = ok.ecash?.map((value: string) => ({ address: value }))
14+
const subscribedBitcoincashAddresses = ok.bitcoincash?.map((value: string) => ({ address: value }))
15+
setEcashSubscribedAddresses(subscribedEcashAddresses)
16+
setBitcoincashSubscribedAddresses(subscribedBitcoincashAddresses)
17+
})()
18+
}, [])
19+
20+
const columns = useMemo(
21+
() => [
22+
{
23+
Header: 'Subscribed addresses',
24+
accessor: 'address',
25+
Cell: (cellProps: any) => {
26+
return <div className="table-date">{cellProps.cell.value}</div>
27+
}
28+
},
29+
{
30+
Header: 'View',
31+
accessor: 'view',
32+
Cell: (cellProps: any) => {
33+
return <a href={`https://explorer.e.cash/address/${cellProps.cell.row.values.address as string}`} target="_blank" rel="noopener noreferrer" className="table-eye-ctn">
34+
<div className="table-eye">
35+
<Image src={EyeIcon} alt='View on explorer' />
36+
</div>
37+
</a>
38+
}
39+
}
40+
],
41+
[]
42+
)
43+
44+
return <>
45+
<h3>Subscribed Addresses</h3>
46+
<h4> eCash</h4>
47+
<TableContainer columns={columns} data={ecashSubscribedAddresses ?? []} ssr/>
48+
<h4> Bitcoin Cash</h4>
49+
<TableContainer columns={columns} data={bitcoincashSubscribedAddresses ?? []} ssr/>
50+
</>
51+
}

components/ButtonGenerator/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import style from '../../styles/landing.module.css'
44
import { PayButton, Widget as PayButtonWidget } from '@paybutton/react'
55
import { ChromePicker } from 'react-color'
66
import CodeBlock from './CodeBlock'
7-
import { decode } from 'ecashaddrjs'
7+
import { decodeCashAddress } from 'ecashaddrjs'
88
import { generatorFormFields } from './data.js'
99
import {
1010
PRIMARY_XEC_COLOR,
@@ -83,7 +83,7 @@ export const initialButtonState: ButtonState = {
8383
onOpen: '',
8484
onClose: '',
8585
wsBaseURL: '',
86-
apiBaseURL: '',
86+
apiBaseURL: ''
8787
}
8888

8989
export default function ButtonGenerator (): JSX.Element {
@@ -93,7 +93,7 @@ export default function ButtonGenerator (): JSX.Element {
9393

9494
const isValidAddress = (address: string): string => {
9595
try {
96-
return decode(address).prefix
96+
return decodeCashAddress(address).prefix
9797
} catch (err) {
9898
return 'not valid'
9999
}

config/example-config.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
"bitcoincash": "chronik"
1313
},
1414
"networkBlockchainURLs": {
15-
"ecash": "https://xec.paybutton.io",
16-
"bitcoincash": "https://bch.paybutton.io"
17-
15+
"ecash": [
16+
"https://xec.paybutton.io",
17+
"https://chronik1.alitayin.com",
18+
"https://chronik2.alitayin.com",
19+
"https://chronik.e.cash",
20+
"https://chronik-native1.fabien.cash",
21+
"https://chronik-native2.fabien.cash",
22+
"https://chronik-native3.fabien.cash",
23+
"https://chronik.pay2stay.com/xec",
24+
"https://chronik.pay2stay.com/xec2"
25+
],
26+
"bitcoincash": ["https://bch.paybutton.io"]
1827
},
1928
"networksUnderMaintenance": {
2029
"bitcoincash": true

config/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface Config {
1515
priceAPIURL: string
1616
redisURL: string
1717
networkBlockchainClients: KeyValueT<BlockchainClientOptions>
18-
networkBlockchainURLs: KeyValueT<string>
18+
networkBlockchainURLs: KeyValueT<string[]>
1919
networksUnderMaintenance: KeyValueT<boolean>
2020
triggerPOSTTimeout: number
2121
sideshiftAffiliateId: string
@@ -35,15 +35,15 @@ const readConfig = (): Config => {
3535
if (
3636
(
3737
config.networkBlockchainURLs.ecash === undefined ||
38-
config.networkBlockchainURLs.ecash === ''
38+
config.networkBlockchainURLs.ecash.length === 0
3939
) &&
4040
!config.networksUnderMaintenance.ecash
4141
) {
4242
throw new Error(RESPONSE_MESSAGES.MISSING_BLOCKCHAIN_CLIENT_URL_400('ecash').message)
4343
} else if (
4444
(
4545
config.networkBlockchainURLs.bitcoincash === undefined ||
46-
config.networkBlockchainURLs.bitcoincash === ''
46+
config.networkBlockchainURLs.bitcoincash.length === 0
4747
) &&
4848
!config.networksUnderMaintenance.bitcoincash
4949
) {

constants/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ export const FETCH_N_TIMEOUT = 120000
146146
// When fetching some address transactions, delay (in ms) between each fetch.
147147
export const FETCH_DELAY = 100
148148

149+
// Delay to check if latency test has finished, when the app starts.
150+
export const LATENCY_TEST_CHECK_DELAY = 200
151+
149152
// Wait time (in ms) to see if there are new unsynced addresses
150153
export const SYNC_NEW_ADDRESSES_DELAY = 10000
151154

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"cors": "^2.8.5",
4242
"cross-env": "^7.0.2",
4343
"dotenv-cli": "^5.1.0",
44-
"ecashaddrjs": "^1.5.8",
44+
"ecashaddrjs": "^2.0.0",
4545
"express": "^4.17.1",
4646
"graphql": "^16.3.0",
4747
"helmet": "^4.4.1",
@@ -97,7 +97,7 @@
9797
"typescript": "^5.7.2"
9898
},
9999
"resolutions": {
100-
"chronik-client-cashtokens/ecashaddrjs": "^1.5.8"
100+
"chronik-client-cashtokens/ecashaddrjs": "^2.0.0"
101101
},
102102
"lint-staged": {
103103
"*.ts?(x)": [

0 commit comments

Comments
 (0)