Skip to content

Commit

Permalink
✨ If no referrer, use frak labs governance
Browse files Browse the repository at this point in the history
  • Loading branch information
srod committed May 16, 2024
1 parent 02664c6 commit a3ba5e1
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions packages/wallet/src/module/referral/hook/useTriggerReferral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { useCallback } from "react";
import type { Hex } from "viem";

/**
* Small hook used to perform redirection in the paywall context
* Wallet governance address
*/
const FRAK_WALLET_GOVERNANCE: Hex =
"0xB5cbdba1Db3618a68921e7c00e38617c9AfDf220";

/**
* Hook to trigger the referral
*/
export function useTriggerReferral() {
/**
Expand All @@ -16,12 +22,22 @@ export function useTriggerReferral() {
const [referralHistory, setReferralHistory] = useAtom(referralHistoryAtom);

/**
* Trigger the referral
* Referral from Frak when the user is not referred
*/
const triggerReferral = useCallback(
async (wallet: WebAuthNWallet) => {
if (!referralHistory) return;
const referralFromFrak = useCallback(
async (wallet: WebAuthNWallet) =>
await setUserReferred({
user: wallet.address,
referrer: FRAK_WALLET_GOVERNANCE,
}),
[]
);

/**
* Referral from the last referred user
*/
const referralFromUser = useCallback(
async (wallet: WebAuthNWallet) => {
// Set the user referred
await setUserReferred({
user: wallet.address,
Expand All @@ -38,14 +54,27 @@ export function useTriggerReferral() {
contentId: contentId as Hex,
});
}
},
[referralHistory]
);

// Reset referral history
setReferralHistory({
contents: {},
lastReferrer: "0x00",
});
/**
* Trigger the referral
*/
const triggerReferral = useCallback(
async (wallet: WebAuthNWallet) => {
const referralMethod = Object.keys(referralHistory.contents).length
? referralFromUser
: referralFromFrak;
await referralMethod(wallet);
setReferralHistory({ contents: {}, lastReferrer: "0x00" });
},
[referralHistory, setReferralHistory]
[
referralHistory,
referralFromFrak,
referralFromUser,
setReferralHistory,
]
);

return { triggerReferral };
Expand Down

0 comments on commit a3ba5e1

Please sign in to comment.