diff --git a/src/sagas/helpers.js b/src/sagas/helpers.js index 7487c12ce..042e1b9d1 100644 --- a/src/sagas/helpers.js +++ b/src/sagas/helpers.js @@ -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; @@ -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} + */ +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) => { diff --git a/src/sagas/pushNotification.js b/src/sagas/pushNotification.js index 2750c2f59..1bc297df4 100644 --- a/src/sagas/pushNotification.js +++ b/src/sagas/pushNotification.js @@ -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'; @@ -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), }))), }); diff --git a/src/screens/SendScanQRCode.js b/src/screens/SendScanQRCode.js index c1894ea63..8ad79b144 100644 --- a/src/screens/SendScanQRCode.js +++ b/src/screens/SendScanQRCode.js @@ -19,6 +19,7 @@ import { COLORS } from '../styles/themes'; const mapStateToProps = (state) => ({ wallet: state.wallet, + tokens: state.tokens, }); class SendScanQRCode extends React.Component { @@ -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,