Skip to content

Commit

Permalink
Merge pull request #925 from Keith-CY/improve-qr-scanner
Browse files Browse the repository at this point in the history
Improve qr scanner
  • Loading branch information
Keith-CY authored Sep 11, 2019
2 parents d6919c4 + 8a7b246 commit ae680bf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/neuron-ui/src/components/Receive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Receive = ({
onQRCodeClick={() => setShowLargeQRCode(true)}
size={256}
exportable
includeMargin
dispatch={dispatch}
/>
</Stack>
Expand Down
14 changes: 10 additions & 4 deletions packages/neuron-ui/src/widgets/QRCode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ const QRCode = ({
qrcode.make()

const cells = qrcode.modules || []
const margin = includeMargin ? 4 : 0
const margin = includeMargin ? 1 : 0
const fgPath = generatePath(cells, margin)
const numCells = cells.length + margin * 2

const svgStr = `<svg shapeRendering="crispEdges" height="${scale * size}" width="${scale *
size}" viewBox="0 0 ${numCells} ${numCells}" ><path fill="${bgColor}" d="M0, 0 h${numCells} v${numCells} H0z" /><path fill="${fgColor}" d="${fgPath}" /></svg>`
const svgStr = `<svg shapeRendering="crispEdges"
width="${scale * size}"
height="${scale * size}"
viewBox="0 0 ${numCells} ${numCells}"
>
<path fill="${bgColor}" d="M0, 0 h${numCells} v${numCells} H0z" />
<path fill="${fgColor}" d="${fgPath}" />
</svg>`

const onDownload = useCallback(() => {
if (canvasRef.current === null) {
Expand Down Expand Up @@ -147,7 +153,7 @@ const QRCode = ({
}, [svgStr, size])

return (
<Stack tokens={{ childrenGap: 15 }}>
<Stack tokens={{ childrenGap: 15 }} horizontalAlign="center" verticalAlign="center">
<Stack.Item>
<canvas ref={canvasRef} width={size} height={size} onClick={onQRCodeClick} />
</Stack.Item>
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/widgets/QRScanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const QRScanner = ({ title, label, onConfirm, styles }: QRScannerProps) => {
color,
})
if (verifyAddress(code.data)) {
onConfirm(code.data)
onDismiss()
onConfirm(code.data)
} else {
setData(code.data)
}
Expand Down

0 comments on commit ae680bf

Please sign in to comment.