Skip to content

Commit

Permalink
make supported files human readable; fix onScan silent failures due t…
Browse files Browse the repository at this point in the history
…o missing object argument
  • Loading branch information
polymorpher authored and taoalpha committed Mar 29, 2022
1 parent e2e39e8 commit 7577179
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion code/client/src/components/QrCodeScanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import UploadOutlined from '@ant-design/icons/UploadOutlined'
import jsQR from 'jsqr'
import { getDataURLFromFile, getTextFromFile } from './Common'

const SupportedNonImgFileLabels = {
'application/json': 'JSON files (.json)',
'text/plain': 'Plain Text files',
}
const QrCodeScanner = ({ onScan, shouldInit, style, supportedNonImgFiles = ['application/json'], btnText = 'Use Image or JSON Instead' }) => {
const ref = useRef()
const { isMobile } = useWindowDimensions()
Expand Down Expand Up @@ -119,7 +123,7 @@ const QrCodeScanner = ({ onScan, shouldInit, style, supportedNonImgFiles = ['app
const beforeUpload = (file) => {
const isSupported = ['image/jpeg', 'image/png', ...supportedNonImgFiles].includes(file.type)
if (!isSupported) {
message.error(`You can only upload JPG/PNG ${supportedNonImgFiles.length ? `or ${supportedNonImgFiles.join(',')} ` : ''}file`)
message.error(`You can only upload JPG/PNG ${supportedNonImgFiles.length ? `or one of the followings: ${supportedNonImgFiles.map(e => SupportedNonImgFileLabels[e]).join(',')} ` : ''}`)
}
return true
}
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/pages/Restore/RestoreByScan.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const RestoreByScan = ({ isActive, onComplete, onCancel }) => {
f()
}, [addressInput])

const onScan = async (e, { isJson }) => {
const onScan = async (e, { isJson = false } = {}) => {
if (e && !secret) {
const now = performance.now()
if (!(now - control.lastScan > config.scanDelay)) {
Expand Down
2 changes: 1 addition & 1 deletion code/client/src/pages/Show/Extend.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const Extend = ({
}
}, [method])

const onScan = (e, { isJson }) => {
const onScan = (e, { isJson = false } = {}) => {
if (e && !seed) {
try {
let parsed
Expand Down

0 comments on commit 7577179

Please sign in to comment.