Skip to content
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

Ur codes #311

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"@cashu/cashu-ts": "^0.9.0",
"@gandlaf21/bc-ur": "^1.1.12",
"@react-native-community/netinfo": "9.3.10",
"@react-navigation/core": "^6.4.10",
"@react-navigation/native": "^6.1.9",
Expand Down
62 changes: 62 additions & 0 deletions src/components/AnimatedQR.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { UR, UREncoder } from '@gandlaf21/bc-ur'
import { mainColors } from '@src/styles'

Check warning on line 2 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'mainColors' is defined but never used

Check warning on line 2 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'mainColors' is defined but never used

Check warning on line 2 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'mainColors' is defined but never used
import { Buffer } from 'buffer'
import { useEffect, useRef, useState } from 'react'
import QRCode, { QRCodeProps } from 'react-native-qrcode-svg'

Check warning on line 5 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'QRCode' is defined but never used

Check warning on line 5 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'QRCode' is defined but never used

Check warning on line 5 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'QRCode' is defined but never used
import { s } from 'react-native-size-matters'

Check warning on line 6 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

's' is defined but never used

Check warning on line 6 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

's' is defined but never used

Check warning on line 6 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

's' is defined but never used
import Txt from './Txt'

export interface AnimatedQR extends QRCodeProps {
value: string;
interval: number;
chunkLength: number;
size?: number; // defaults to 128
onError: ()=>void

}

export function AnimatedQR({
value,
interval,
chunkLength,
size,
onError

Check warning on line 23 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'size' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 23 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'size' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 23 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'size' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 24 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'onError' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 24 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'onError' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 24 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'onError' is defined but never used. Allowed unused args must match /^_/u
}: AnimatedQR) {
const [part, setPart] = useState<string>('')

const firstSeqNum = 0
const ur = UR.fromBuffer(Buffer.from(value))
const encoder = useRef<UREncoder>(new UREncoder(ur, chunkLength, firstSeqNum))


useEffect(() => {
let timer: NodeJS.Timeout
if (value) {
timer = setInterval(() => {
setPart(encoder.current.nextPart())
console.log(part)
}, interval)

Check warning on line 39 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement

Check warning on line 39 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

Unexpected console statement

Check warning on line 39 in src/components/AnimatedQR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

Unexpected console statement
}
return () => {
if (timer) {
clearInterval(timer)
}
}
}, [value, chunkLength, interval, part])
return (
<>
<Txt txt={part}></Txt>
</>
// <QRCode
// value={part}
// size={size}
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
// logo={require('@assets/app-qr-icon.png')}
// logoBorderRadius={10}
// logoBackgroundColor={mainColors.WHITE}
// logoMargin={s(6)}
// onError={onError}
// />
)
}
8 changes: 6 additions & 2 deletions src/components/QR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,34 @@
import { mainColors } from '@src/styles'
import { useTranslation } from 'react-i18next'
import { TouchableOpacity, View } from 'react-native'
import QRCode from 'react-native-qrcode-svg'

Check warning on line 7 in src/components/QR.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'QRCode' is defined but never used

Check warning on line 7 in src/components/QR.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'QRCode' is defined but never used

Check warning on line 7 in src/components/QR.tsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'QRCode' is defined but never used
import { s, ScaledSheet } from 'react-native-size-matters'

import useCopy from './hooks/Copy'
import { CheckmarkIcon, CopyIcon } from './Icons'
import Txt from './Txt'
import { AnimatedQR } from './AnimatedQR'

interface QRProps {
size: number
value: string
isInvoice?: boolean
truncateNum?: number
interval?: number
onError: () => void
}

export default function QR({ size, value, isInvoice, truncateNum, onError }: QRProps) {
export default function QR({ size, value, isInvoice, truncateNum, onError,interval=100 }: QRProps) {
const { t } = useTranslation([NS.common])
const { color } = useThemeContext()
const { copied, copy } = useCopy()
const str = isInvoice ? value.toUpperCase() : value
return (
<TouchableOpacity onPress={() => void copy(str)}>
<View style={styles.qrWrap}>
<QRCode
<AnimatedQR
interval={interval}
chunkLength={100}
size={size}
value={str}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
1 change: 1 addition & 0 deletions src/screens/Payment/Send/EncodedToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export default function EncodedTokenPage({ navigation, route }: TEncodedTokenPag
<Txt txt={error.msg} styles={[globals(color).navTxt, styles.errorMsg]} />
:
<QR
interval={200}
size={s(280)}
value={value}
onError={() => setError({ msg: t('bigQrMsg'), open: true })}
Expand Down
Loading