From 4e3b0e8170463bc7241046d8e374ec8f4bc16820 Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 9 Dec 2024 10:11:11 -0500 Subject: [PATCH] add recipient address to streams when nonexistent --- .../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);