Skip to content

Commit

Permalink
Merge pull request #2878 from buildcore-io/soon_claim
Browse files Browse the repository at this point in the history
Soon claim
  • Loading branch information
adamunchained authored May 8, 2024
2 parents a8b8599 + db6262d commit 2136a71
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,32 @@ import { verifyEthForB5TangleSchema } from './VerifyEthForB5TangleRequest';
export class VerifyEthForBuilTokenTangleService extends BaseTangleService<TangleResponse> {
public handleRequest = async ({ request, match }: HandlerParams): Promise<TangleResponse> => {
const params = await assertValidationAsync(verifyEthForB5TangleSchema, request);
let ethAddress = params.ethAddress.toLowerCase();
const ethAddresses = params.ethAddress.toLowerCase().split(',');

let soonSnapDocRef = database().doc(COL.SOON_SNAP, match.from);
let soonSnap = await this.transaction.get(soonSnapDocRef);
if (!soonSnap) {
soonSnapDocRef = database().doc(COL.SOON_SNAP, ethAddress);
soonSnap = await this.transaction.get(soonSnapDocRef);
}

ethAddress = soonSnap?.ethAddress || ethAddress;

const fid = await getFidForEth(ethAddress);
const fid = await getFidForEth(ethAddresses[0]);
if (!(await isUserFollowingChannel(fid))) {
return { status: 'error', message: 'Must follow JustBuild' };
}

if (!soonSnap) {
return { status: 'error', message: 'No snapshot for this SMR address' };
await this.confirmEthAddress(match.from, ethAddresses[0]);

for (const ethAddress of ethAddresses) {
await this.confirmEthAddress(ethAddress, ethAddress);
}

if (!soonSnap.ethAddressVerified) {
return { status: 'success' };
};

private confirmEthAddress = async (soonSnapUid: string, ethAddress: string) => {
const soonSnapDocRef = database().doc(COL.SOON_SNAP, soonSnapUid);
const soonSnap = await this.transaction.get(soonSnapDocRef);
if (soonSnap && !soonSnap.ethAddressVerified) {
this.transactionService.push({
ref: soonSnapDocRef,
data: { ethAddress, ethAddressVerified: true },
action: Action.U,
});
}

return { status: 'success' };
};
}

Expand Down

0 comments on commit 2136a71

Please sign in to comment.