Skip to content

Commit

Permalink
Merge pull request #424 from TosiDrop/feat/imfeelinglucky
Browse files Browse the repository at this point in the history
feat: im feeling lucky
  • Loading branch information
reqlez authored Apr 4, 2023
2 parents f0b8150 + 726d17b commit 029108a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
17 changes: 14 additions & 3 deletions client/src/components/Claim/RewardsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface Props {
isLoadingClaimReward: boolean;
selectAll: () => void;
poolInfo?: any;
maxTokenSelected: number;
selectRandomTokens: any;
}

export default function RewardsView({
Expand All @@ -22,6 +24,8 @@ export default function RewardsView({
isLoadingClaimReward,
selectAll,
poolInfo,
maxTokenSelected,
selectRandomTokens,
}: Props) {
if (claimableTokens.length > 0) {
return (
Expand Down Expand Up @@ -93,17 +97,24 @@ export default function RewardsView({
className={"background flex flex-row items-center p-5 rounded-2xl"}
>
<div>Selected {numberOfSelectedTokens} token</div>
<div className="ml-auto flex flex-row w-fit">
<div className="ml-auto flex flex-row w-fit gap-4">
<button
className="tosi-button py-2.5 px-5 rounded-lg"
onClick={selectRandomTokens}
>
I'm feeling lucky
</button>
<button
className="tosi-button py-2.5 px-5 rounded-lg"
onClick={selectAll}
>
{numberOfSelectedTokens === claimableTokens.length
{numberOfSelectedTokens ===
Math.min(claimableTokens.length, maxTokenSelected)
? "Unselect All"
: "Select All"}
</button>
<button
className="tosi-button ml-5 py-2.5 px-5 rounded-lg flex flex-row items-center"
className="tosi-button py-2.5 px-5 rounded-lg flex flex-row items-center"
disabled={numberOfSelectedTokens === 0}
onClick={claimRewards}
>
Expand Down
22 changes: 6 additions & 16 deletions client/src/hooks/cardano/claim/useClaimReward.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,12 @@ export default function useClaimReward() {
};

const selectAll = () => {
const positions = [...Array(claimableTokens.length).keys()].slice(
0,
maxTokenSelected
);

const updatedClaimableTokens = [...claimableTokens];
if (
numberOfSelectedTokens <
Math.min(maxTokenSelected, claimableTokens.length)
) {
positions.forEach(
(position) => (updatedClaimableTokens[position].selected = true)
);
} else {
positions.forEach(
(position) => (updatedClaimableTokens[position].selected = false)
);
updatedClaimableTokens.forEach((_) => (_.selected = false));
if (numberOfSelectedTokens !== maxTokenSelected) {
for (let i = 0; i < maxTokenSelected; i++) {
updatedClaimableTokens[i].selected = true;
}
}
setClaimableTokens(updatedClaimableTokens);
};
Expand Down Expand Up @@ -206,5 +195,6 @@ export default function useClaimReward() {
isCheckRewardLoading,
isClaimRewardLoading,
poolInfo,
maxTokenSelected,
};
}
4 changes: 4 additions & 0 deletions client/src/pages/Cardano/Claim/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function Claim() {
numberOfSelectedTokens,
claimRewards,
poolInfo,
maxTokenSelected,
selectRandomTokens,
} = useClaimReward();
const queue = useQueue();

Expand Down Expand Up @@ -45,6 +47,8 @@ function Claim() {
isLoadingClaimReward={isClaimRewardLoading}
selectAll={selectAll}
poolInfo={poolInfo}
maxTokenSelected={maxTokenSelected}
selectRandomTokens={selectRandomTokens}
/>
</div>
</>
Expand Down

0 comments on commit 029108a

Please sign in to comment.