diff --git a/cashtab/package-lock.json b/cashtab/package-lock.json --- a/cashtab/package-lock.json +++ b/cashtab/package-lock.json @@ -1,12 +1,12 @@ { "name": "cashtab", - "version": "2.23.0", + "version": "2.23.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cashtab", - "version": "2.23.0", + "version": "2.23.1", "dependencies": { "@ant-design/icons": "^5.3.0", "@bitgo/utxo-lib": "^9.33.0", diff --git a/cashtab/package.json b/cashtab/package.json --- a/cashtab/package.json +++ b/cashtab/package.json @@ -1,6 +1,6 @@ { "name": "cashtab", - "version": "2.23.0", + "version": "2.23.1", "private": true, "scripts": { "start": "node scripts/start.js", diff --git a/cashtab/src/validation/__tests__/index.test.js b/cashtab/src/validation/__tests__/index.test.js --- a/cashtab/src/validation/__tests__/index.test.js +++ b/cashtab/src/validation/__tests__/index.test.js @@ -20,7 +20,6 @@ meetsAliasSpec, isValidAliasSendInput, isProbablyNotAScam, - getContactAddressOrAliasError, isValidSideshiftObj, isValidMultiSendUserInput, shouldSendXecBeDisabled, @@ -39,9 +38,7 @@ invalidXecAirdropExclusionListPrefixless, } from 'validation/fixtures/mocks'; import vectors from 'validation/fixtures/vectors'; -import { when } from 'jest-when'; import appConfig from 'config/app'; -import aliasSettings from 'config/alias'; describe('Cashtab validation functions', () => { it(`isValidSideshiftObj() returns true for a valid sideshift library object`, () => { @@ -73,117 +70,6 @@ }; expect(isValidSideshiftObj(mockSideshift)).toBe(false); }); - it(`getContactAddressOrAliasError() returns false for a valid and registered alias input that is not already in contacts`, async () => { - const mockRegisteredAliasResponse = { - alias: 'cbdc', - address: 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx', - txid: 'f7d71433af9a4e0081ea60349becf2a60efed8890df7c3e8e079b3427f51d5ea', - blockheight: 802515, - }; - const fetchUrl = `${aliasSettings.aliasServerBaseUrl}/alias/${mockRegisteredAliasResponse.alias}`; - - // mock the fetch call to alias-server's '/alias' endpoint - global.fetch = jest.fn(); - when(fetch) - .calledWith(fetchUrl) - .mockResolvedValue({ - json: () => Promise.resolve(mockRegisteredAliasResponse), - }); - expect(await getContactAddressOrAliasError('cbdc.xec', [])).toBe(false); - }); - it(`getContactAddressOrAliasError() returns expected error for a valid and registered alias input that is already in contacts`, async () => { - const mockRegisteredAliasResponse = { - alias: 'cbdc', - address: 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx', - txid: 'f7d71433af9a4e0081ea60349becf2a60efed8890df7c3e8e079b3427f51d5ea', - blockheight: 802515, - }; - const fetchUrl = `${aliasSettings.aliasServerBaseUrl}/alias/${mockRegisteredAliasResponse.alias}`; - - // mock the fetch call to alias-server's '/alias' endpoint - global.fetch = jest.fn(); - when(fetch) - .calledWith(fetchUrl) - .mockResolvedValue({ - json: () => Promise.resolve(mockRegisteredAliasResponse), - }); - expect( - await getContactAddressOrAliasError('cbdc.xec', [ - { address: 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx' }, - ]), - ).toBe( - `ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx is already in Contacts`, - ); - }); - it(`getContactAddressOrAliasError() returns expected error for a valid alias input that the server is unable to resolve`, async () => { - const mockRegisteredAliasResponse = new Error('some server error'); - const fetchUrl = `${aliasSettings.aliasServerBaseUrl}/alias/cbdc`; - - // mock the fetch call to alias-server's '/alias' endpoint - global.fetch = jest.fn(); - when(fetch) - .calledWith(fetchUrl) - .mockResolvedValue(mockRegisteredAliasResponse); - expect(await getContactAddressOrAliasError('cbdc.xec', [])).toBe( - `Error resolving "cbdc.xec"`, - ); - }); - it(`getContactAddressOrAliasError() returns expected error for a valid but unregistered alias input`, async () => { - const mockUnregisteredAliasResponse = { - alias: 'koush', - isRegistered: false, - registrationFeeSats: 554, - processedBlockheight: 803421, - }; - const fetchUrl = `${aliasSettings.aliasServerBaseUrl}/alias/${mockUnregisteredAliasResponse.alias}`; - - // mock the fetch call to alias-server's '/alias' endpoint - global.fetch = jest.fn(); - when(fetch) - .calledWith(fetchUrl) - .mockResolvedValue({ - json: () => Promise.resolve(mockUnregisteredAliasResponse), - }); - expect(await getContactAddressOrAliasError('koush.xec', [])).toBe( - 'Alias "koush.xec" is unregistered', - ); - }); - it(`getContactAddressOrAliasError() returns expected error for an invalid eCash address / alias input`, async () => { - expect(await getContactAddressOrAliasError('notvalid', [])).toBe( - `"notvalid" is not a valid eCash address or alias`, - ); - }); - it(`getContactAddressOrAliasError() returns false for a valid eCash address that is not in Contacts`, async () => { - expect( - await getContactAddressOrAliasError( - 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx', - [], - ), - ).toBe(false); - }); - it(`getContactAddressOrAliasError() returns expected error for a valid eCash address that is in Contacts`, async () => { - expect( - await getContactAddressOrAliasError( - 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx', - [ - { - address: - 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx', - }, - ], - ), - ).toBe( - 'ecash:qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx is already in Contacts', - ); - }); - it(`getContactAddressOrAliasError() returns false for a valid prefix-less eCash address`, async () => { - expect( - await getContactAddressOrAliasError( - 'qq9h6d0a5q65fgywv4ry64x04ep906mdku8f0gxfgx', - [], - ), - ).toBe(false); - }); it(`validateMnemonic() returns true for a valid mnemonic`, () => { const mnemonic = 'labor tail bulb distance estate collect lecture into smile differ yard legal'; diff --git a/cashtab/src/validation/index.js b/cashtab/src/validation/index.js --- a/cashtab/src/validation/index.js +++ b/cashtab/src/validation/index.js @@ -11,7 +11,6 @@ cashtabSettingsValidation, } from 'config/cashtabSettings'; import tokenBlacklist from 'config/tokenBlacklist'; -import { queryAliasServer } from 'alias'; import appConfig from 'config/app'; import { opReturn } from 'config/opreturn'; import { getStackArray } from 'ecash-script'; @@ -39,65 +38,6 @@ ); }; -/** - * Get error from user-input contact address - * A valid contact address can be a valid alias that resolves to an address - * NOTE - * If we support alias entry to contact list -- which is quite complicated and has potentially zero impact - * we still need to save the actual address in the list - * otherwise we will need to lookup many aliases in contacts for all cashtab features that depend on "is - * this address in contact lits" - * @param {*} value - * @param {*} contacts - * @returns {false | string} - */ -export const getContactAddressOrAliasError = async ( - addressOrAlias, - contacts, -) => { - const isValidCashAddress = cashaddr.isValidCashAddress( - addressOrAlias, - 'ecash', - ); - const isValidAlias = isValidAliasSendInput(addressOrAlias) === true; - if (!isValidCashAddress && !isValidAlias) { - return `"${addressOrAlias}" is not a valid eCash address or alias`; - } - // Check if alias address resolves - let resolvedAddress; - - if (isValidAlias) { - try { - const aliasDetails = await queryAliasServer( - 'alias', - addressOrAlias.split('.xec')[0], - ); - if ('address' in aliasDetails) { - resolvedAddress = aliasDetails.address; - } else { - return `Alias "${addressOrAlias}" is unregistered`; - } - } catch (err) { - console.error( - `getContactAddressOrAliasError(): Error retrieving alias details`, - err, - ); - // For purposes of UI, present this validation msg - // Also possible the server is down - // Either way, we do not want to accept such an input - return `Error resolving "${addressOrAlias}"`; - } - } - let address = isValidAlias ? resolvedAddress : addressOrAlias; - for (const contact of contacts) { - if (contact.address === address) { - return `${address} is already in Contacts`; - } - } - - return false; -}; - export const getContactAddressError = (address, contacts) => { const isValidCashAddress = cashaddr.isValidCashAddress(address, 'ecash'); // We do not accept prefixless input