Skip to content

Commit

Permalink
add a list view for front
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-merkl committed Mar 3, 2025
1 parent 70dca8b commit f0602d8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contracts/ReferralRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ contract ReferralRegistry is UUPSHelper {
/// @notice Mapping to store user to referrer relationships
mapping(string => mapping(address => address)) public keyToUserToReferrer;

/// @notice Mapping to list referred
mapping(string => mapping(address => address[])) public keyToReferred;

/// @notice Adds a new referral key to the list
/// @param key The referral key to add
/// @param _cost The cost of the referral program
Expand Down Expand Up @@ -161,10 +164,22 @@ contract ReferralRegistry is UUPSHelper {
/// @param key The referral key for which the user is acknowledging the referrer
/// @param referrer The address of the referrer
function acknowledgeReferrer(string calldata key, address referrer) public {
if (keyToUserToReferrer[key][msg.sender] != address(0)) {
address previousReferrer = keyToUserToReferrer[key][msg.sender];
address[] storage previousListOfReferred = keyToReferred[key][previousReferrer];
for (uint256 i = 0; i < previousListOfReferred.length; i++) {
if (previousListOfReferred[i] == msg.sender) {
previousListOfReferred[i] = previousListOfReferred[previousListOfReferred.length - 1];
previousListOfReferred.pop();
break;
}
}
}
if (referralPrograms[key].requiresRefererToBeSet) {
require(refererStatus[key][referrer] == ReferralStatus.Set, "Referrer has not created a referral link");
}
keyToUserToReferrer[key][msg.sender] = referrer;
keyToReferred[key][referrer].push(msg.sender);
emit ReferrerAcknowledged(key, msg.sender, referrer);
}

Expand Down Expand Up @@ -281,6 +296,13 @@ contract ReferralRegistry is UUPSHelper {
return keyToUserToReferrer[key][user];
}

/// @notice Gets the list of referred users
/// @param key The referral key to check
/// @param user The referrer
function getReferred(string calldata key, address user) external view returns (address[] memory) {
return keyToReferred[key][user];
}

/// @notice Gets the cost of a referral for a specific key
/// @param key The referral key to check
/// @return The cost of the referral for the given key
Expand Down

0 comments on commit f0602d8

Please sign in to comment.