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

Fix: QR Code registered token check #386

Merged
merged 3 commits into from
Nov 16, 2023
Merged
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
13 changes: 12 additions & 1 deletion src/sagas/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function isUnlockScreen(action) {
* Get registered tokens from the wallet instance.
* @param {HathorWallet} wallet
* @param {boolean} excludeHTR If we should exclude the HTR token.
* @returns {string[]}
* @returns {Promise<{ uid: string, symbol: string, name: string }[]>}
*/
export async function getRegisteredTokens(wallet, excludeHTR = false) {
const htrUid = hathorLib.constants.HATHOR_TOKEN_CONFIG.uid;
Expand Down Expand Up @@ -185,6 +185,17 @@ export async function getRegisteredTokens(wallet, excludeHTR = false) {
return tokens;
}

/**
* Check if a token is registered in the context of the saga functions.
* @param {HathorWallet} wallet
* @param {string} tokenUid
* @returns {Promise<boolean>}
*/
export async function isTokenRegistered(wallet, tokenUid) {
const tokens = await getRegisteredTokens(wallet);
return tokens.some((token) => token.uid === tokenUid);
}

export async function getFullnodeNetwork() {
try {
const response = await new Promise((resolve, reject) => {
Expand Down
4 changes: 2 additions & 2 deletions src/sagas/pushNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import {
} from '../constants';
import { getPushNotificationSettings } from '../utils';
import { STORE } from '../store';
import { getNetworkSettings, isUnlockScreen, showPinScreenForResult } from './helpers';
import { getNetworkSettings, isUnlockScreen, showPinScreenForResult, isTokenRegistered } from './helpers';
import { messageHandler } from '../workers/pushNotificationHandler';
import { WALLET_STATUS } from './wallet';

Expand Down Expand Up @@ -544,7 +544,7 @@ export const getTxDetails = async (wallet, txId) => {
name: each.tokenName,
symbol: each.tokenSymbol,
balance: each.balance,
isRegistered: await wallet.storage.isTokenRegistered(each.tokenId),
isRegistered: await isTokenRegistered(each.tokenId),
}))),
});

Expand Down
6 changes: 5 additions & 1 deletion src/screens/SendScanQRCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { COLORS } from '../styles/themes';

const mapStateToProps = (state) => ({
wallet: state.wallet,
tokens: state.tokens,
});

class SendScanQRCode extends React.Component {
Expand All @@ -42,7 +43,10 @@ class SendScanQRCode extends React.Component {
if (!qrcode.isValid) {
this.showAlertError(qrcode.error);
} else if (qrcode.token && qrcode.amount) {
if (await this.props.wallet.storage.isTokenRegistered(qrcode.token.uid)) {
const isTokenRegistered = this.props.tokens.some(
(stateToken) => stateToken.uid === qrcode.token.uid
);
if (isTokenRegistered) {
const params = {
address: qrcode.address,
token: qrcode.token,
Expand Down
Loading