Skip to content

Commit

Permalink
add recipient address to streams when nonexistent (#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 authored Dec 9, 2024
1 parent 795e035 commit 2051be0
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/resolvers/anchorContractAddressResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<AnchorContractAddress> {
const userId = ctx?.req?.user?.userId;
const creatorUser = await findUserById(userId);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 2051be0

Please sign in to comment.