From 2051be080d29abc134fe1e749dc3cb81e2b37507 Mon Sep 17 00:00:00 2001 From: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:38:08 -0500 Subject: [PATCH] add recipient address to streams when nonexistent (#1890) --- .../anchorContractAddressResolver.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/resolvers/anchorContractAddressResolver.ts b/src/resolvers/anchorContractAddressResolver.ts index b45fd4c2b..70f09fe08 100644 --- a/src/resolvers/anchorContractAddressResolver.ts +++ b/src/resolvers/anchorContractAddressResolver.ts @@ -14,6 +14,9 @@ import { ApolloContext } from '../types/ApolloContext'; import { findUserById } from '../repositories/userRepository'; import { getProvider } from '../provider'; import { logger } from '../utils/logger'; +import { ChainType } from '../types/network'; +import { addBulkNewProjectAddress } from '../repositories/projectAddressRepository'; +import { validateProjectRelatedAddresses } from '../utils/validators/projectValidator'; @Resolver(_of => AnchorContractAddress) export class AnchorContractAddressResolver { @@ -24,6 +27,7 @@ export class AnchorContractAddressResolver { @Arg('networkId', () => Int) networkId: number, @Arg('address', () => String) address: string, @Arg('txHash', () => String) txHash: string, + @Arg('recipientAddress', { nullable: true }) recipientAddress?: string, ): Promise { const userId = ctx?.req?.user?.userId; const creatorUser = await findUserById(userId); @@ -53,11 +57,29 @@ export class AnchorContractAddressResolver { projectAddress.isRecipient === true, ) ) { - throw new Error( - i18n.__( - translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK, - ), - ); + if (recipientAddress) { + const recipientAddressInput = { + project, + user: creatorUser, + address: recipientAddress!, + chainType: ChainType.EVM, + networkId: networkId, + isRecipient: true, + }; + + await validateProjectRelatedAddresses( + [recipientAddressInput], + projectId, + ); + + await addBulkNewProjectAddress([recipientAddressInput]); + } else { + throw new Error( + i18n.__( + translationErrorMessagesKeys.PROJECT_DOESNT_HAVE_RECIPIENT_ADDRESS_ON_THIS_NETWORK, + ), + ); + } } const web3Provider = getProvider(networkId);