Skip to content

Commit

Permalink
use URL_SCHEME from package.json; simplify PopOpCode.tsx
Browse files Browse the repository at this point in the history
Instead of hardcoding `emission://`, we can grab it from the package json. This way, the 'emission' string will only need to be changed in one place for other versions of the app.
And since QrCode.tsx is able to handle either URLs or plain tokens, we can also simplify PopOpCode to just accept the plain token and pass this through to QrCode.tsx
  • Loading branch information
JGreenlee committed Oct 16, 2024
1 parent 16a9a87 commit 8fbe0e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
5 changes: 4 additions & 1 deletion www/js/components/QrCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ we can remove this wrapper and just use the QRCode component directly */
import React from 'react';
import QRCode from 'react-qr-code';
import { logDebug, logWarn } from '../plugin/logger';
import packageJsonBuild from '../../../package.cordovabuild.json';

const URL_SCHEME = packageJsonBuild.cordova.plugins['cordova-plugin-customurlscheme'].URL_SCHEME;

export function shareQR(message) {
/*code adapted from demo of react-qr-code*/
Expand Down Expand Up @@ -45,7 +48,7 @@ export function shareQR(message) {
const QrCode = ({ value, ...rest }) => {
let hasLink = value.toString().includes('//');
if (!hasLink) {
value = 'emission://login_token?token=' + value;
value = `${URL_SCHEME}://login_token?token=${value}`;
}

return (
Expand Down
17 changes: 4 additions & 13 deletions www/js/control/PopOpCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import QrCode from '../components/QrCode';
import { AlertManager } from '../components/AlertBar';
import { settingStyles } from './ProfileSettings';

const PopOpCode = ({ visibilityValue, tokenURL, action, setVis }) => {
const PopOpCode = ({ visibilityValue, token, action, setVis }) => {
const { t } = useTranslation();
const { colors } = useTheme();

const opcodeList = tokenURL.split('=');
const opcode = opcodeList[opcodeList.length - 1];

function copyText(textToCopy) {
navigator.clipboard.writeText(textToCopy).then(() => {
AlertManager.addMessage({ msgKey: 'Copied to clipboard!' });
Expand All @@ -22,13 +19,7 @@ const PopOpCode = ({ visibilityValue, tokenURL, action, setVis }) => {
let copyButton;
if (window['cordova'].platformId == 'ios') {
copyButton = (
<IconButton
icon="content-copy"
onPress={() => {
copyText(opcode);
}}
style={styles.button}
/>
<IconButton icon="content-copy" onPress={() => copyText(token)} style={styles.button} />
);
}

Expand All @@ -41,8 +32,8 @@ const PopOpCode = ({ visibilityValue, tokenURL, action, setVis }) => {
<Dialog.Title>{t('general-settings.qrcode')}</Dialog.Title>
<Dialog.Content style={styles.content}>
<Text style={styles.text}>{t('general-settings.qrcode-share-title')}</Text>
<QrCode value={tokenURL} style={{ marginHorizontal: 8 }}></QrCode>
<Text style={styles.opcode}>{opcode}</Text>
<QrCode value={token} style={{ marginHorizontal: 8 }}></QrCode>
<Text style={styles.opcode}>{token}</Text>
</Dialog.Content>
<Dialog.Actions>
<IconButton icon="share" onPress={() => action()} style={styles.button} />
Expand Down
2 changes: 1 addition & 1 deletion www/js/control/ProfileSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ const ProfileSettings = () => {
<PopOpCode
visibilityValue={opCodeVis}
setVis={setOpCodeVis}
tokenURL={'emission://login_token?token=' + authSettings.opcode}
token={authSettings.opcode}
action={() => shareQR(authSettings.opcode)}></PopOpCode>

{/* {view privacy} */}
Expand Down

0 comments on commit 8fbe0e4

Please sign in to comment.