From f669c493ece9e2c0722f5f73ffb3df8af109918f Mon Sep 17 00:00:00 2001 From: s100tist Date: Fri, 19 Jul 2024 15:31:02 -0600 Subject: [PATCH 01/14] wallet address url stored in database converted to lower case (packages/backend/src/graphql/resolvers/wallet_address.ts). middleware.ts in packages/backend/src/open_payments/wallet_address/middleware.ts modified to look up for the walletaddress url in a case insensitive way. --- .../src/graphql/resolvers/wallet_address.ts | 2 +- .../src/open_payments/wallet_address/middleware.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/wallet_address.ts b/packages/backend/src/graphql/resolvers/wallet_address.ts index 1731699fc9..c9398691ef 100644 --- a/packages/backend/src/graphql/resolvers/wallet_address.ts +++ b/packages/backend/src/graphql/resolvers/wallet_address.ts @@ -90,7 +90,7 @@ export const createWalletAddress: MutationResolvers['createWallet assetId: args.input.assetId, additionalProperties: addProps, publicName: args.input.publicName, - url: args.input.url + url: args.input.url.toLowerCase() } const walletAddressOrError = await walletAddressService.create(options) diff --git a/packages/backend/src/open_payments/wallet_address/middleware.ts b/packages/backend/src/open_payments/wallet_address/middleware.ts index 6a6601d9f9..51df2db7e8 100644 --- a/packages/backend/src/open_payments/wallet_address/middleware.ts +++ b/packages/backend/src/open_payments/wallet_address/middleware.ts @@ -15,7 +15,7 @@ export async function getWalletAddressUrlFromRequestBody( ctx: SignedCollectionContext, next: () => Promise ) { - ctx.walletAddressUrl = ctx.request.body.walletAddress + ctx.walletAddressUrl = ctx.request.body.walletAddress.toLowerCase() await next() } @@ -23,7 +23,7 @@ export async function getWalletAddressUrlFromQueryParams( ctx: SignedCollectionContext, next: () => Promise ) { - ctx.walletAddressUrl = ctx.request.query['wallet-address'] + ctx.walletAddressUrl = ctx.request.query['wallet-address'].toLowerCase() await next() } @@ -31,7 +31,7 @@ export async function getWalletAddressUrlFromPath( ctx: WalletAddressUrlContext, next: () => Promise ) { - ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.walletAddressPath}` + ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.walletAddressPath}`.toLowerCase() await next() } @@ -53,7 +53,7 @@ export async function getWalletAddressUrlFromIncomingPayment( }) } - ctx.walletAddressUrl = incomingPayment.walletAddress.url + ctx.walletAddressUrl = incomingPayment.walletAddress.url.toLowerCase() await next() } @@ -75,7 +75,7 @@ export async function getWalletAddressUrlFromOutgoingPayment( }) } - ctx.walletAddressUrl = outgoingPayment.walletAddress.url + ctx.walletAddressUrl = outgoingPayment.walletAddress.url.toLowerCase() await next() } @@ -95,7 +95,7 @@ export async function getWalletAddressUrlFromQuote( }) } - ctx.walletAddressUrl = quote.walletAddress.url + ctx.walletAddressUrl = quote.walletAddress.url.toLowerCase() await next() } @@ -106,7 +106,7 @@ export async function getWalletAddressForSubresource( const walletAddressService = await ctx.container.use('walletAddressService') const walletAddress = await walletAddressService.getOrPollByUrl( - ctx.walletAddressUrl + ctx.walletAddressUrl.toLowerCase() ) if (!walletAddress?.isActive) { From 534a3f0dda0a48ae610e5dab83b0c9cbd84c32c3 Mon Sep 17 00:00:00 2001 From: s100tist Date: Mon, 19 Aug 2024 08:36:16 -0600 Subject: [PATCH 02/14] correcting formating --- .../backend/src/open_payments/wallet_address/middleware.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/open_payments/wallet_address/middleware.ts b/packages/backend/src/open_payments/wallet_address/middleware.ts index 51df2db7e8..39b1d219ce 100644 --- a/packages/backend/src/open_payments/wallet_address/middleware.ts +++ b/packages/backend/src/open_payments/wallet_address/middleware.ts @@ -31,7 +31,8 @@ export async function getWalletAddressUrlFromPath( ctx: WalletAddressUrlContext, next: () => Promise ) { - ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.walletAddressPath}`.toLowerCase() + ctx.walletAddressUrl = + `https://${ctx.request.host}/${ctx.params.walletAddressPath}`.toLowerCase() await next() } From ad8cfac6d59bccf7ea5313eb305f61040b3bfe31 Mon Sep 17 00:00:00 2001 From: s100tist Date: Mon, 19 Aug 2024 11:25:24 -0600 Subject: [PATCH 03/14] rollback of to lower case in openpayments/walletaddress/middleware and graphqlresolvers --- .../src/graphql/resolvers/wallet_address.ts | 2 +- .../src/open_payments/wallet_address/middleware.ts | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/graphql/resolvers/wallet_address.ts b/packages/backend/src/graphql/resolvers/wallet_address.ts index c9398691ef..1731699fc9 100644 --- a/packages/backend/src/graphql/resolvers/wallet_address.ts +++ b/packages/backend/src/graphql/resolvers/wallet_address.ts @@ -90,7 +90,7 @@ export const createWalletAddress: MutationResolvers['createWallet assetId: args.input.assetId, additionalProperties: addProps, publicName: args.input.publicName, - url: args.input.url.toLowerCase() + url: args.input.url } const walletAddressOrError = await walletAddressService.create(options) diff --git a/packages/backend/src/open_payments/wallet_address/middleware.ts b/packages/backend/src/open_payments/wallet_address/middleware.ts index 39b1d219ce..f6faee8d35 100644 --- a/packages/backend/src/open_payments/wallet_address/middleware.ts +++ b/packages/backend/src/open_payments/wallet_address/middleware.ts @@ -15,7 +15,7 @@ export async function getWalletAddressUrlFromRequestBody( ctx: SignedCollectionContext, next: () => Promise ) { - ctx.walletAddressUrl = ctx.request.body.walletAddress.toLowerCase() + ctx.walletAddressUrl = ctx.request.body.walletAddress await next() } @@ -23,7 +23,7 @@ export async function getWalletAddressUrlFromQueryParams( ctx: SignedCollectionContext, next: () => Promise ) { - ctx.walletAddressUrl = ctx.request.query['wallet-address'].toLowerCase() + ctx.walletAddressUrl = ctx.request.query['wallet-address'] await next() } @@ -32,7 +32,7 @@ export async function getWalletAddressUrlFromPath( next: () => Promise ) { ctx.walletAddressUrl = - `https://${ctx.request.host}/${ctx.params.walletAddressPath}`.toLowerCase() + `https://${ctx.request.host}/${ctx.params.walletAddressPath}` await next() } @@ -54,7 +54,7 @@ export async function getWalletAddressUrlFromIncomingPayment( }) } - ctx.walletAddressUrl = incomingPayment.walletAddress.url.toLowerCase() + ctx.walletAddressUrl = incomingPayment.walletAddress.url await next() } @@ -76,7 +76,7 @@ export async function getWalletAddressUrlFromOutgoingPayment( }) } - ctx.walletAddressUrl = outgoingPayment.walletAddress.url.toLowerCase() + ctx.walletAddressUrl = outgoingPayment.walletAddress.url await next() } @@ -96,7 +96,7 @@ export async function getWalletAddressUrlFromQuote( }) } - ctx.walletAddressUrl = quote.walletAddress.url.toLowerCase() + ctx.walletAddressUrl = quote.walletAddress.url await next() } @@ -107,7 +107,7 @@ export async function getWalletAddressForSubresource( const walletAddressService = await ctx.container.use('walletAddressService') const walletAddress = await walletAddressService.getOrPollByUrl( - ctx.walletAddressUrl.toLowerCase() + ctx.walletAddressUrl ) if (!walletAddress?.isActive) { From 3c15536f28b4222284cd2e26c6ffa0af0c7a731c Mon Sep 17 00:00:00 2001 From: s100tist Date: Mon, 19 Aug 2024 17:29:57 -0600 Subject: [PATCH 04/14] Max suggestion --- .../src/open_payments/wallet_address/service.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index 3a62c5e865..ffd93b6f3a 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -166,7 +166,7 @@ async function createWalletAddress( return await WalletAddress.query(deps.knex) .insertGraphAndFetch({ - url: options.url, + url: options.url.toLowerCase(), publicName: options.publicName, assetId: options.assetId, additionalProperties: additionalProperties @@ -295,10 +295,14 @@ async function getWalletAddressByUrl( deps: ServiceDependencies, url: string ): Promise { + url = url.toLowerCase() + console.log('This is what we are looking for: ', url) const walletAddress = await WalletAddress.query(deps.knex) - .findOne({ url }) + .where('url', 'ilike', `%${url}%`) // Usamos 'where' con 'ilike' para hacer la consulta + .limit(1) .withGraphFetched('asset') - return walletAddress || undefined + console.log("Wawawaw ", walletAddress) + return walletAddress[0] || undefined } async function getWalletAddressPage( From 18fcf957a49089210735c69e07dcc71ae330420f Mon Sep 17 00:00:00 2001 From: Roberto <67120473+s100tist@users.noreply.github.com> Date: Wed, 21 Aug 2024 08:54:44 -0600 Subject: [PATCH 05/14] Removing logs:( --- packages/backend/src/open_payments/wallet_address/service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index ffd93b6f3a..ae7e31f2af 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -296,12 +296,10 @@ async function getWalletAddressByUrl( url: string ): Promise { url = url.toLowerCase() - console.log('This is what we are looking for: ', url) const walletAddress = await WalletAddress.query(deps.knex) .where('url', 'ilike', `%${url}%`) // Usamos 'where' con 'ilike' para hacer la consulta .limit(1) .withGraphFetched('asset') - console.log("Wawawaw ", walletAddress) return walletAddress[0] || undefined } From c239662fb95017cafeb1eb5f31a37ab98135e54c Mon Sep 17 00:00:00 2001 From: Roberto <67120473+s100tist@users.noreply.github.com> Date: Wed, 21 Aug 2024 08:57:19 -0600 Subject: [PATCH 06/14] Update service.ts --- packages/backend/src/open_payments/wallet_address/service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index ae7e31f2af..42fbb0125b 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -297,7 +297,7 @@ async function getWalletAddressByUrl( ): Promise { url = url.toLowerCase() const walletAddress = await WalletAddress.query(deps.knex) - .where('url', 'ilike', `%${url}%`) // Usamos 'where' con 'ilike' para hacer la consulta + .where('url', 'ilike', `%${url}%`) .limit(1) .withGraphFetched('asset') return walletAddress[0] || undefined From a28c2ded00e25ead8f82a66d1e418aee2950c309 Mon Sep 17 00:00:00 2001 From: s100tist Date: Wed, 21 Aug 2024 09:24:21 -0600 Subject: [PATCH 07/14] query corrected --- packages/backend/src/open_payments/wallet_address/service.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index 42fbb0125b..8ff24a8e68 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -295,10 +295,8 @@ async function getWalletAddressByUrl( deps: ServiceDependencies, url: string ): Promise { - url = url.toLowerCase() const walletAddress = await WalletAddress.query(deps.knex) - .where('url', 'ilike', `%${url}%`) - .limit(1) + .whereRaw('url = LOWER(?)', [url]) .withGraphFetched('asset') return walletAddress[0] || undefined } From 91398860f1c9af964816d85f66576a5e8fc37e65 Mon Sep 17 00:00:00 2001 From: s100tist Date: Mon, 26 Aug 2024 08:26:31 -0600 Subject: [PATCH 08/14] return deleted --- .../backend/src/open_payments/wallet_address/middleware.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/middleware.ts b/packages/backend/src/open_payments/wallet_address/middleware.ts index f6faee8d35..6a6601d9f9 100644 --- a/packages/backend/src/open_payments/wallet_address/middleware.ts +++ b/packages/backend/src/open_payments/wallet_address/middleware.ts @@ -31,8 +31,7 @@ export async function getWalletAddressUrlFromPath( ctx: WalletAddressUrlContext, next: () => Promise ) { - ctx.walletAddressUrl = - `https://${ctx.request.host}/${ctx.params.walletAddressPath}` + ctx.walletAddressUrl = `https://${ctx.request.host}/${ctx.params.walletAddressPath}` await next() } From c500f2b03b2e378efd3097af7b0fe18b71866eb4 Mon Sep 17 00:00:00 2001 From: s100tist Date: Thu, 29 Aug 2024 04:58:52 -0600 Subject: [PATCH 09/14] using toLowerCase in the request --- packages/backend/src/open_payments/wallet_address/service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index 8ff24a8e68..ef9bc6bce4 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -296,9 +296,9 @@ async function getWalletAddressByUrl( url: string ): Promise { const walletAddress = await WalletAddress.query(deps.knex) - .whereRaw('url = LOWER(?)', [url]) + .findOne({url: url.toLowerCase()}) .withGraphFetched('asset') - return walletAddress[0] || undefined + return walletAddress || undefined } async function getWalletAddressPage( From aec3467b05717cc6e55621133de5912b76f30441 Mon Sep 17 00:00:00 2001 From: s100tist Date: Thu, 29 Aug 2024 05:19:51 -0600 Subject: [PATCH 10/14] format changes --- packages/backend/src/open_payments/wallet_address/service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index ef9bc6bce4..08072d9883 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -296,7 +296,7 @@ async function getWalletAddressByUrl( url: string ): Promise { const walletAddress = await WalletAddress.query(deps.knex) - .findOne({url: url.toLowerCase()}) + .findOne({ url: url.toLowerCase() }) .withGraphFetched('asset') return walletAddress || undefined } From ab6c339879211ccd91abb629b13d2865e03b310c Mon Sep 17 00:00:00 2001 From: s100tist Date: Wed, 4 Sep 2024 08:04:19 -0600 Subject: [PATCH 11/14] tests for wallet address draft --- .../wallet_address/service.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/packages/backend/src/open_payments/wallet_address/service.test.ts b/packages/backend/src/open_payments/wallet_address/service.test.ts index 40ce06f726..3d7d4a2fa0 100644 --- a/packages/backend/src/open_payments/wallet_address/service.test.ts +++ b/packages/backend/src/open_payments/wallet_address/service.test.ts @@ -135,6 +135,44 @@ describe('Open Payments Wallet Address Service', (): void => { accountingService.getBalance(walletAddress.id) ).resolves.toBeUndefined() }) + + + test.each` + url | description + ${'https://AlIce.me/PEy'} | ${'with a mixed case url'} + `( + 'Creating wallet address with case insensitiveness', + async ({ url }): Promise => { + await expect( + walletAddressService.create({ + ...options, + url + }) + ).resolves.toMatchObject( + {url:url.toLowerCase()} + ) + } + ) + + test.each` + url | description + ${'https://aliCe.me/pay'} | ${'with a mixed case url'} + ${'https://Alice.me/pay'} | ${'Duplied with a mixed case url'} + + `( + 'Wallet address cannot be created if the url is duplicated', + async ({ url }): Promise => { + await expect( + walletAddressService.create({ + ...options, + url + }) + ).resolves.toMatchObject( + {url:url.toLowerCase()} + ) + } + ) + }) describe('Update Wallet Address', (): void => { @@ -421,6 +459,8 @@ describe('Open Payments Wallet Address Service', (): void => { } ) ) + + }) describe('Get Or Poll Wallet Addres By Url', (): void => { From 7e9b8a6287e0e8112644263a7db2f450781470ed Mon Sep 17 00:00:00 2001 From: s100tist Date: Thu, 12 Sep 2024 16:56:16 -0600 Subject: [PATCH 12/14] tests added --- .../wallet_address/service.test.ts | 61 ++++++++----------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/service.test.ts b/packages/backend/src/open_payments/wallet_address/service.test.ts index 3d7d4a2fa0..24d1379f75 100644 --- a/packages/backend/src/open_payments/wallet_address/service.test.ts +++ b/packages/backend/src/open_payments/wallet_address/service.test.ts @@ -135,43 +135,38 @@ describe('Open Payments Wallet Address Service', (): void => { accountingService.getBalance(walletAddress.id) ).resolves.toBeUndefined() }) - - test.each` - url | description - ${'https://AlIce.me/PEy'} | ${'with a mixed case url'} - `( - 'Creating wallet address with case insensitiveness', - async ({ url }): Promise => { - await expect( - walletAddressService.create({ - ...options, - url - }) - ).resolves.toMatchObject( - {url:url.toLowerCase()} - ) - } - ) - test.each` - url | description - ${'https://aliCe.me/pay'} | ${'with a mixed case url'} - ${'https://Alice.me/pay'} | ${'Duplied with a mixed case url'} - - `( - 'Wallet address cannot be created if the url is duplicated', - async ({ url }): Promise => { + test('Creating wallet address with case insensitiveness', async (): Promise => { + const url = 'https://Alice.me/pay' await expect( walletAddressService.create({ - ...options, - url - }) + ...options, + url + }) ).resolves.toMatchObject( - {url:url.toLowerCase()} + { url: url.toLowerCase() } ) } - ) + ) + + test( + 'Wallet address cannot be created if the url is duplicated', + async (): Promise => { + const url = 'https://Alice.me/pay' + const wallet = walletAddressService.create({ + ...options, + url + }) + assert.ok(!isWalletAddressError(wallet)) + await expect( + walletAddressService.create({ + ...options, + url + }) + ).resolves.toEqual(WalletAddressError.InvalidUrl) + } + ) }) @@ -262,8 +257,8 @@ describe('Open Payments Wallet Address Service', (): void => { expect(incomingPaymentUpdated.expiresAt.getTime()).toEqual( expiresAt.getTime() + - config.walletAddressDeactivationPaymentGracePeriodMs - - duration + config.walletAddressDeactivationPaymentGracePeriodMs - + duration ) } ) @@ -459,8 +454,6 @@ describe('Open Payments Wallet Address Service', (): void => { } ) ) - - }) describe('Get Or Poll Wallet Addres By Url', (): void => { From 53d7871893c11578e4ed22ed0ec1fc5ecf10de92 Mon Sep 17 00:00:00 2001 From: s100tist Date: Tue, 17 Sep 2024 10:39:21 -0600 Subject: [PATCH 13/14] duplied wallet addresses handling --- .../open_payments/wallet_address/errors.ts | 10 +++-- .../wallet_address/service.test.ts | 38 ++++++++----------- .../open_payments/wallet_address/service.ts | 8 +++- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/backend/src/open_payments/wallet_address/errors.ts b/packages/backend/src/open_payments/wallet_address/errors.ts index f6775dcb21..77d0bb8c52 100644 --- a/packages/backend/src/open_payments/wallet_address/errors.ts +++ b/packages/backend/src/open_payments/wallet_address/errors.ts @@ -3,7 +3,8 @@ import { GraphQLErrorCode } from '../../graphql/errors' export enum WalletAddressError { InvalidUrl = 'InvalidUrl', UnknownAsset = 'UnknownAsset', - UnknownWalletAddress = 'UnknownWalletAddress' + UnknownWalletAddress = 'UnknownWalletAddress', + DuplicateWalletAddress = 'DuplicateWalletAddress' } // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types @@ -15,7 +16,8 @@ export const errorToCode: { } = { [WalletAddressError.InvalidUrl]: GraphQLErrorCode.BadUserInput, [WalletAddressError.UnknownAsset]: GraphQLErrorCode.BadUserInput, - [WalletAddressError.UnknownWalletAddress]: GraphQLErrorCode.NotFound + [WalletAddressError.UnknownWalletAddress]: GraphQLErrorCode.NotFound, + [WalletAddressError.DuplicateWalletAddress]: GraphQLErrorCode.Duplicate } export const errorToMessage: { @@ -23,5 +25,7 @@ export const errorToMessage: { } = { [WalletAddressError.InvalidUrl]: 'invalid url', [WalletAddressError.UnknownAsset]: 'unknown asset', - [WalletAddressError.UnknownWalletAddress]: 'unknown wallet address' + [WalletAddressError.UnknownWalletAddress]: 'unknown wallet address', + [WalletAddressError.DuplicateWalletAddress]: + 'wallet address is already registered' } diff --git a/packages/backend/src/open_payments/wallet_address/service.test.ts b/packages/backend/src/open_payments/wallet_address/service.test.ts index 24d1379f75..30db937dd3 100644 --- a/packages/backend/src/open_payments/wallet_address/service.test.ts +++ b/packages/backend/src/open_payments/wallet_address/service.test.ts @@ -136,7 +136,6 @@ describe('Open Payments Wallet Address Service', (): void => { ).resolves.toBeUndefined() }) - test('Creating wallet address with case insensitiveness', async (): Promise => { const url = 'https://Alice.me/pay' await expect( @@ -144,30 +143,23 @@ describe('Open Payments Wallet Address Service', (): void => { ...options, url }) - ).resolves.toMatchObject( - { url: url.toLowerCase() } - ) - } - ) + ).resolves.toMatchObject({ url: url.toLowerCase() }) + }) - test( - 'Wallet address cannot be created if the url is duplicated', - async (): Promise => { - const url = 'https://Alice.me/pay' - const wallet = walletAddressService.create({ + test('Wallet address cannot be created if the url is duplicated', async (): Promise => { + const url = 'https://Alice.me/pay' + const wallet = walletAddressService.create({ + ...options, + url + }) + assert.ok(!isWalletAddressError(wallet)) + await expect( + walletAddressService.create({ ...options, url }) - assert.ok(!isWalletAddressError(wallet)) - await expect( - walletAddressService.create({ - ...options, - url - }) - ).resolves.toEqual(WalletAddressError.InvalidUrl) - } - ) - + ).resolves.toEqual(WalletAddressError.DuplicateWalletAddress) + }) }) describe('Update Wallet Address', (): void => { @@ -257,8 +249,8 @@ describe('Open Payments Wallet Address Service', (): void => { expect(incomingPaymentUpdated.expiresAt.getTime()).toEqual( expiresAt.getTime() + - config.walletAddressDeactivationPaymentGracePeriodMs - - duration + config.walletAddressDeactivationPaymentGracePeriodMs - + duration ) } ) diff --git a/packages/backend/src/open_payments/wallet_address/service.ts b/packages/backend/src/open_payments/wallet_address/service.ts index 08072d9883..ad14d8f882 100644 --- a/packages/backend/src/open_payments/wallet_address/service.ts +++ b/packages/backend/src/open_payments/wallet_address/service.ts @@ -1,7 +1,8 @@ import { ForeignKeyViolationError, TransactionOrKnex, - NotFoundError + NotFoundError, + UniqueViolationError } from 'objection' import { URL } from 'url' @@ -178,6 +179,11 @@ async function createWalletAddress( return WalletAddressError.UnknownAsset } } + if (err instanceof UniqueViolationError) { + if (err.constraint === 'walletaddresses_url_unique') { + return WalletAddressError.DuplicateWalletAddress + } + } throw err } } From 53b0c8c3ab5ed814e536145966ccb5a8a5ac2dfe Mon Sep 17 00:00:00 2001 From: Roberto <67120473+s100tist@users.noreply.github.com> Date: Wed, 18 Sep 2024 08:38:02 -0600 Subject: [PATCH 14/14] Update packages/backend/src/open_payments/wallet_address/errors.ts Co-authored-by: Max Kurapov --- packages/backend/src/open_payments/wallet_address/errors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/open_payments/wallet_address/errors.ts b/packages/backend/src/open_payments/wallet_address/errors.ts index 77d0bb8c52..03d672762c 100644 --- a/packages/backend/src/open_payments/wallet_address/errors.ts +++ b/packages/backend/src/open_payments/wallet_address/errors.ts @@ -27,5 +27,5 @@ export const errorToMessage: { [WalletAddressError.UnknownAsset]: 'unknown asset', [WalletAddressError.UnknownWalletAddress]: 'unknown wallet address', [WalletAddressError.DuplicateWalletAddress]: - 'wallet address is already registered' + 'Duplicate wallet address found with the same url' }