Skip to content

Commit

Permalink
Updates counter to use assignedWallets if whitelistedWallets is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbartnik committed Jan 17, 2024
1 parent 01769ec commit d58dfbf
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions apps/sentry-client-desktop/src/features/home/SentryWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const recommendedFundingBalance = ethers.parseEther("0.005");
export function SentryWallet() {
const [drawerState, setDrawerState] = useAtom(drawerStateAtom);
const setModalState = useSetAtom(modalStateAtom);
const {ownersLoading, owners, licensesLoading} = useAtomValue(chainStateAtom);
const {ownersLoading, owners, licensesLoading, licensesList} = useAtomValue(chainStateAtom);
const queryClient = useQueryClient();
const {hasAssignedKeys} = useAtomValue(accruingStateAtom);

Expand All @@ -53,7 +53,6 @@ export function SentryWallet() {
const {startRuntime, stopRuntime, sentryRunning, nodeLicenseStatusMap} = useOperatorRuntime();
const {data} = useStorage();


const [isOpen, setIsOpen] = useState<boolean>(false);
const {refresh} = useChainDataRefresh();

Expand Down Expand Up @@ -110,18 +109,34 @@ export function SentryWallet() {
}

function getDropdownItems() {
return owners.map((wallet, i) => (
<p
onClick={() => {
setSelectedWallet(wallet);
setIsOpen(false);
}}
className="p-2 cursor-pointer hover:bg-gray-100"
key={`sentry-item-${i}`}
>
{wallet}
</p>
));
// If the user has whitelisted wallets, update the dropdown to populate with their whitelistedWallets.
if (data?.whitelistedWallets) {
return data?.whitelistedWallets.map((wallet, i) => (
<p
onClick={() => {
setSelectedWallet(wallet);
setIsOpen(false);
}}
className="p-2 cursor-pointer hover:bg-gray-100"
key={`sentry-item-${i}`}
>
{wallet}
</p>
));
} else {
return owners.map((wallet, i) => (
<p
onClick={() => {
setSelectedWallet(wallet);
setIsOpen(false);
}}
className="p-2 cursor-pointer hover:bg-gray-100"
key={`sentry-item-${i}`}
>
{wallet}
</p>
));
}
}

function getKeys() {
Expand Down Expand Up @@ -159,12 +174,18 @@ export function SentryWallet() {
}

function getWalletCounter() {
/**
* By default, use the assignedWallets values.
* If the user has whitelisted wallets, update the counter to populate with their whitelistedWallets values.
*/
const keysCounter = data?.whitelistedWallets
? `${nodeLicenseStatusMap.size} key${nodeLicenseStatusMap.size === 1 ? '' : 's'} in ${data?.whitelistedWallets?.length} wallet${data?.whitelistedWallets?.length === 1 ? '' : 's'}`
: `${licensesList.length} key${licensesList.length === 1 ? '' : 's'} in ${owners.length} wallet${owners.length === 1 ? '' : 's'}`

return (
<>
{nodeLicenseStatusMap.size > 0
? (loading
? ("Loading...")
: (`${nodeLicenseStatusMap.size} key${nodeLicenseStatusMap.size === 1 ? '' : 's'} in ${data?.whitelistedWallets?.length} wallet${data?.whitelistedWallets?.length === 1 ? '' : 's'}`))
? (loading ? ("Loading...") : (`${keysCounter}`))
: ("No keys")}
</>
);
Expand Down Expand Up @@ -360,7 +381,7 @@ export function SentryWallet() {
onClick={() => setIsOpen(!isOpen)}
className={`flex items-center justify-between w-[538px] border-[#A3A3A3] border-r border-l border-t ${!isOpen ? "border-b" : null} border-[#A3A3A3] p-2`}
>
<p>{selectedWallet || `All assigned wallets (${owners.length})`}</p>
<p>{selectedWallet || `All assigned wallets (${data?.whitelistedWallets ? data.whitelistedWallets.length : owners.length})`}</p>
<IoIosArrowDown
className={`h-[15px] transform ${isOpen ? "rotate-180 transition-transform ease-in-out duration-300" : "transition-transform ease-in-out duration-300"}`}
/>
Expand Down

0 comments on commit d58dfbf

Please sign in to comment.