Implement a mapping to track all likes for each user, then pool all these payments upon a mutual match:
```solidity
// In the contract, add this mapping:
mapping(address => uint256[]) public userLikes;
function likeUser(address liked) external payable {
require(msg.value == 1 ether, "Must send exactly 1 ETH");
require(!likes[msg.sender][liked], "Already liked");
require(msg.sender != liked, "Cannot like yourself");
require(profileNFT.profileToToken(msg.sender) != 0, "Must have a profile NFT");
require(profileNFT.profileToToken(liked) != 0, "Liked user must have a profile NFT");
likes[msg.sender][liked] = true;
userLikes[msg.sender].push(msg.value); // Track all likes payments
emit Liked(msg.sender, liked);
if (likes[liked][msg.sender]) {
matches[msg.sender].push(liked);
matches[liked].push(msg.sender);
emit Matched(msg.sender, liked);
matchRewards(msg.sender, liked);
}
}
function matchRewards(address from, address to) internal {
uint256 totalRewardsFrom = 0;
uint256 totalRewardsTo = 0;
// Sum up all previous likes for both users
for (uint256 i = 0; i < userLikes[from].length; i++) {
totalRewardsFrom += userLikes[from][i];
}
for (uint256 i = 0; i < userLikes[to].length; i++) {
totalRewardsTo += userLikes[to][i];
}
uint256 totalRewards = totalRewardsFrom + totalRewardsTo;
uint256 matchingFees = (totalRewards * FIXEDFEE) / 100;
uint256 rewards = totalRewards - matchingFees;
// Deploy and fund the MultiSigWallet with all rewards
MultiSigWallet multiSigWallet = new MultiSigWallet(from, to);
(bool success, ) = payable(address(multiSigWallet)).call{value: rewards}("");
require(success, "Transfer to MultiSig failed");
// Clear userLikes after transfer
delete userLikes[from];
delete userLikes[to];
}
```
Explanation:
With this approach, each user's like payments are stored in an array within userLikes. When a mutual match is detected, matchRewards calculates the sum of all previous likes from both users, applies the fee, and then transfers the remaining amount to the MultiSig wallet.