diff --git a/packages/shared/lib/address.ts b/packages/shared/lib/address.ts index 662beb9f244..c1eecb5be0b 100644 --- a/packages/shared/lib/address.ts +++ b/packages/shared/lib/address.ts @@ -1,4 +1,2 @@ export const isValidAddressAndPrefix = (address: string, expectedAddressPrefix: string): boolean => new RegExp(`^${expectedAddressPrefix}1[02-9ac-hj-np-z]{59}$`).test(address) - -export const isValidEVMAddress = (address: string): boolean => new RegExp('0x[a-fA-F0-9]{40}$').test(address) diff --git a/packages/shared/lib/common/deep-links/enums/wallet-context.enum.ts b/packages/shared/lib/common/deep-links/enums/wallet-context.enum.ts index 143c36d8f94..42e4320c3c2 100644 --- a/packages/shared/lib/common/deep-links/enums/wallet-context.enum.ts +++ b/packages/shared/lib/common/deep-links/enums/wallet-context.enum.ts @@ -12,12 +12,6 @@ export enum WalletOperation { export enum SendOperationParameter { Amount = 'amount', Unit = 'unit', -} - -/** - * The query parameters available exclusively for a bridge operation - */ -export enum SwapOperationParameter { - ChainId = 'chainId', - ReceiverAddress = 'receiverAddress', + Tag = 'tag', + Metadata = 'metadata', } diff --git a/packages/shared/lib/common/deep-links/types/deep-link-request.type.ts b/packages/shared/lib/common/deep-links/types/deep-link-request.type.ts index 693daea9cc4..f4a7df2622f 100644 --- a/packages/shared/lib/common/deep-links/types/deep-link-request.type.ts +++ b/packages/shared/lib/common/deep-links/types/deep-link-request.type.ts @@ -1,11 +1,6 @@ import type { NotificationData } from '../../../typings/notification' -import type { - DeepLinkContext, - SendOperationParameters, - SendWithMetaDataOperationParameters, - WalletOperation, -} from '@common/deep-links' +import type { DeepLinkContext, SendOperationParameters, WalletOperation } from '@common/deep-links' /** * A union type of all deep link contexts' operations. @@ -15,7 +10,7 @@ export type DeepLinkOperation = WalletOperation /** * A union type of all deep link operations' parameters. */ -export type DeepLinkParameters = void | SendOperationParameters | SendWithMetaDataOperationParameters +export type DeepLinkParameters = void | SendOperationParameters /** * The content of a deep link request. diff --git a/packages/shared/lib/common/deep-links/types/wallet-context.type.ts b/packages/shared/lib/common/deep-links/types/wallet-context.type.ts index f9f63295c59..4ae02988461 100644 --- a/packages/shared/lib/common/deep-links/types/wallet-context.type.ts +++ b/packages/shared/lib/common/deep-links/types/wallet-context.type.ts @@ -8,12 +8,6 @@ export type SendOperationParameters = { amount: string unit: Unit message: string -} - -/** - * The parameters of a bridge operation. - */ -export type SendWithMetaDataOperationParameters = SendOperationParameters & { - tag: string - metadata: string + tag?: string + metadata?: string } diff --git a/packages/shared/lib/common/deep-links/wallet-context-handler.ts b/packages/shared/lib/common/deep-links/wallet-context-handler.ts index 312886cadc7..f172b17a5d1 100644 --- a/packages/shared/lib/common/deep-links/wallet-context-handler.ts +++ b/packages/shared/lib/common/deep-links/wallet-context-handler.ts @@ -2,23 +2,13 @@ import { Unit } from '@iota/unit-converter' import { localize } from '@core/i18n' -import { isValidAddressAndPrefix, isValidEVMAddress } from '../../address' +import { isValidAddressAndPrefix } from '../../address' import { addError } from '../../errors' -import { - DeepLinkContext, - SendOperationParameter, - SwapOperationParameter, - WalletOperation, -} from '@common/deep-links/enums' -import { - DeepLinkParameters, - DeepLinkRequest, - SendOperationParameters, - SendWithMetaDataOperationParameters, -} from '@common/deep-links/types' +import { DeepLinkContext, SendOperationParameter, WalletOperation } from '@common/deep-links/enums' +import { DeepLinkParameters, DeepLinkRequest, SendOperationParameters } from '@common/deep-links/types' import { formatNumber } from '@lib/currency' -import { getNumberOfDecimalPlaces } from '@lib/utils' +import { getByteLengthOfString, getNumberOfDecimalPlaces } from '@lib/utils' /** * Parses a deep link within the wallet context. @@ -53,9 +43,6 @@ export const parseWalletDeepLinkRequest = (url: URL, expectedAddressPrefix: stri case WalletOperation.Send: parameters = parseSendOperation(address, url.searchParams) break - case WalletOperation.SwapOut: - parameters = parseSwapOutOperation(address, url.searchParams) - break default: return addError({ time: Date.now(), @@ -82,7 +69,6 @@ export const parseWalletDeepLinkRequest = (url: URL, expectedAddressPrefix: stri * * @param {string} address The recipient's Bech32 address. * @param {URLSearchParams} searchParams The query parameters of the deep link URL. - * @param {string} expectedAddressPrefix The expected human-readable part of a Bech32 address. * * @return {void | SendOperationParameters} The formatted parameters for the send operation. */ @@ -126,50 +112,27 @@ const parseSendOperation = (address: string, searchParams: URLSearchParams): voi }) } - return { - address, - amount: formatNumber(Math.abs(parsedAmount), numDecimalPlaces, numDecimalPlaces), - unit: parsedUnit, - message: '', - } -} - -const parseSwapOutOperation = ( - waspAddress: string, - searchParams: URLSearchParams -): void | SendWithMetaDataOperationParameters => { - const sendParams = parseSendOperation(waspAddress, searchParams) - if (!sendParams) { - // Error handling is done in parseSendOperation already - return - } - - const chainId = searchParams.get(SwapOperationParameter.ChainId) - if (!chainId) { - return addError({ - time: Date.now(), - type: 'deepLink', - message: 'The chain ID is missing', - }) - } else if (!Number.isInteger(Number(chainId))) { - return addError({ time: Date.now(), type: 'deepLink', message: `Chain ID is not an integer '${chainId}'` }) + const tag = searchParams.get(SendOperationParameter.Tag) + if (tag) { + if (getByteLengthOfString(tag) > 64) { + return addError({ time: Date.now(), type: 'deepLink', message: localize('error.send.tagLength') }) + } } - const receiverAddress = searchParams.get(SwapOperationParameter.ReceiverAddress) - if (!receiverAddress) { - return addError({ time: Date.now(), type: 'deepLink', message: 'The receiver address is missing' }) - } else if (!isValidEVMAddress(receiverAddress)) { - return addError({ - time: Date.now(), - type: 'deepLink', - message: `The receiver address is not an EVM address: '${receiverAddress}'`, - }) + const metadata = searchParams.get(SendOperationParameter.Metadata) + if (metadata) { + if (getByteLengthOfString(metadata) > 8192) { + return addError({ time: Date.now(), type: 'deepLink', message: localize('error.send.metadataLength') }) + } } return { - ...sendParams, - tag: WalletOperation.SwapOut, - metadata: `${receiverAddress}:${chainId}`, + address, + amount: formatNumber(Math.abs(parsedAmount), numDecimalPlaces, numDecimalPlaces), + unit: parsedUnit, + message: '', + tag, + metadata, } } diff --git a/packages/shared/lib/tests/address.test.ts b/packages/shared/lib/tests/address.test.ts deleted file mode 100644 index 79f052015b0..00000000000 --- a/packages/shared/lib/tests/address.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { isValidEVMAddress } from '../address' - -describe('File: address.ts', () => { - describe('Function: isValidEVMAddress', () => { - it('Valid EVM Address', () => { - const address = '0xF65e3cCbe04D4784EDa9CC4a33F84A6162aC9EB6' - expect(isValidEVMAddress(address)).toEqual(true) - }) - - it('Invalid EVM Address (1 character too few)', () => { - const address = '0xF65e3cCbe04D4784EDa9CC4a33F84A6162aC9EB' - expect(isValidEVMAddress(address)).toEqual(false) - }) - - it('Invalid EVM Address (1 character too much)', () => { - const address = '0xF65e3cCbe04D4784EDa9CC4a33F84A6162aC9EB62' - expect(isValidEVMAddress(address)).toEqual(false) - }) - - it('Invalid EVM Address (iota address)', () => { - const address = 'atoi1qz0mvjzjfwt5wcy8j8daw6avh67z77kquwkwzr5fvuu6pfzpjqgz7cptqex' - expect(isValidEVMAddress(address)).toEqual(false) - }) - }) -}) diff --git a/packages/shared/lib/typings/sendParams.ts b/packages/shared/lib/typings/sendParams.ts index 235346549b0..ba979508cef 100644 --- a/packages/shared/lib/typings/sendParams.ts +++ b/packages/shared/lib/typings/sendParams.ts @@ -1,4 +1,3 @@ -import { SendWithMetaDataOperationParameters } from '@common/deep-links' import { Unit } from '@iota/unit-converter' import { LabeledWalletAccount } from './wallet' diff --git a/packages/shared/locales/en.json b/packages/shared/locales/en.json index a14efca237b..ec55cfcdaea 100644 --- a/packages/shared/locales/en.json +++ b/packages/shared/locales/en.json @@ -1208,8 +1208,8 @@ "total": "Total: {balance}", "openExplorer": "View in Explorer", "activityDetails": "Transaction details", - "tag": "Tag", - "metadata": "Metadata" + "tag": "Tag (optional)", + "metadata": "Metadata (optional)" }, "dates": { "today": "Today", diff --git a/packages/shared/routes/dashboard/wallet/Wallet.svelte b/packages/shared/routes/dashboard/wallet/Wallet.svelte index c317b9a93a0..c929f32c07f 100644 --- a/packages/shared/routes/dashboard/wallet/Wallet.svelte +++ b/packages/shared/routes/dashboard/wallet/Wallet.svelte @@ -225,7 +225,7 @@ remainder_value_strategy: { strategy: 'ChangeAddress', }, - indexation: { index: tag ?? 'firefly', data: convertStringToUtf8Array(data) }, + indexation: { index: tag ? tag : 'firefly', data: convertStringToUtf8Array(data) }, }, { onSuccess(response) {