Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: Sanction check #60

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/enterprise/src/components/Navigation/SideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ExternalLink } from 'lib/navigation/Link/ExternalLink';
import { ReactComponent as ChatIcon } from 'components/assets/Chat.svg';
import { ManageDaosButton } from 'dao/components/ManageDaosButton';
import { SettingsNavigationItem } from 'settings/components/SettingsNavigationItem';
import { useSanctionCheck } from 'queries';

const Container = styled(VStack)`
padding: 32px;
Expand All @@ -22,6 +23,7 @@ const Container = styled(VStack)`

export const SideNavigation = () => {
const connectedWallet = useConnectedWallet();
const isSanctioned = useSanctionCheck(connectedWallet?.walletAddress);

return (
<Container fullHeight justifyContent="space-between">
Expand Down Expand Up @@ -57,7 +59,7 @@ export const SideNavigation = () => {
{connectedWallet && (
<Tooltip title="Create a DAO" placement="right" arrow={true}>
<div>
<CreateDaoButton />
<CreateDaoButton disabled={isSanctioned}/>
</div>
</Tooltip>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useConnectedWallet } from '@terra-money/wallet-provider';
import { ManageWallet } from 'chain/components/ManageWallet';
import { CreateDaoButton } from 'dao/components/CreateDaoButton';
import { DashboardButton } from 'dao/components/DashboardButton';
import { ManageDaosButton } from 'dao/components/ManageDaosButton';
import { ComponentWithChildrenProps } from 'lib/shared/props';
import { HStack } from 'lib/ui/Stack';
import { useSanctionCheck } from 'queries';
import { SettingsNavigationItem } from 'settings/components/SettingsNavigationItem';
import styled from 'styled-components';

Expand Down Expand Up @@ -35,6 +37,8 @@ const Footer = styled(HStack)`
`;

export const SmallScreenNavigation = ({ children }: ComponentWithChildrenProps) => {
const connectedWallet = useConnectedWallet();
const isSanctioned = useSanctionCheck(connectedWallet?.walletAddress);
return (
<Container>
<Header alignItems="center" justifyContent="space-between">
Expand All @@ -48,7 +52,7 @@ export const SmallScreenNavigation = ({ children }: ComponentWithChildrenProps)
<ManageDaosButton />
<SettingsNavigationItem />
</HStack>
<CreateDaoButton />
<CreateDaoButton disabled={isSanctioned}/>
</Footer>
</Container>
);
Expand Down
32 changes: 30 additions & 2 deletions apps/enterprise/src/components/network-guard/NetworkGuard.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
import { UIElementProps } from '@terra-money/apps/components';
import { useTerraNetwork } from 'chain/hooks/useTerraNetwork';
import { useQueryClient } from 'react-query';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';
import { useConnectedWallet } from '@terra-money/wallet-provider';
import { SanctionModal } from 'lib/ui/SanctionModal';


export const NetworkGuard = (props: UIElementProps) => {
const { children } = props;
const connectedWallet = useConnectedWallet();
const [sactionCheck, setSanctioncCeck] = useState<boolean>();

const { moniker } = useTerraNetwork();
const queryClient = useQueryClient();


useEffect(() => {
queryClient.invalidateQueries();
}, [moniker, queryClient]);

useEffect(() => {
// const checkSanction = async () => {
// if (connectedWallet) {
// const walletAddress = connectedWallet.walletAddress;
// const response = await fetch(`https://something.com/check/${walletAddress}`);
// const isSanctioned = await response.json();

// if (isSanctioned) {
// setSanctioncCeck(true);
// } else {
// setSanctioncCeck(false);
// }
// }
// };
// checkSanction();
}, [connectedWallet]);

if(sactionCheck) {
return (
<SanctionModal></SanctionModal>
)
}



return <>{children}</>;
};
8 changes: 6 additions & 2 deletions apps/enterprise/src/dao/components/CreateDaoButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ const Button = styled(IconButton)`
font-size: 12px;
`;

export const CreateDaoButton = () => {
interface CreateDaoButtonProps {
disabled: any;
}

export const CreateDaoButton = ({disabled}: CreateDaoButtonProps) => {
return (
<InternalLink to={Path.CreateDao}>
<Button variant="primary">
<Button variant="primary" disabled={disabled}>
<PlusIcon />
</Button>
</InternalLink>
Expand Down
34 changes: 34 additions & 0 deletions apps/enterprise/src/lib/ui/SanctionModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UIElementProps } from '@terra-money/apps/components';
import { Modal } from 'lib/ui/Modal';
import { Text } from 'lib/ui/Text';
import { PrimaryButton } from 'lib/ui/buttons/rect/PrimaryButton';
import { HStack } from './Stack';
import { useLocation, useNavigate } from 'react-router';
import { useWallet } from '@terra-money/wallet-provider';


export const SanctionModal = (props: UIElementProps) => {
const { children } = props;
const navigate = useNavigate();
const location = useLocation();
const { disconnect } = useWallet();



return (
<>
{children}
{(
<Modal
title="Sanctioned address"
footer={<HStack fullWidth gap={16} justifyContent={'end'}><PrimaryButton onClick={() => navigate(location.pathname)}>Refresh</PrimaryButton><PrimaryButton onClick={() => disconnect()}>Disconnect</PrimaryButton></HStack>}
renderContent={() => (
<Text color="supporting">
Wallets that are or have interacted with sanctioned contracts are not permitted to use the Enterprise protocol webapp
</Text>
)}
/>
)}
</>
);
};
4 changes: 3 additions & 1 deletion apps/enterprise/src/pages/dao/TreasuryTokensOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AnimateNumber } from '@terra-money/apps/components';
import { formatAmount } from '@terra-money/apps/libs/formatting';
import { Address } from 'components/address';
import styled from 'styled-components';
import { VStack } from 'lib/ui/Stack';
import { HStack, VStack } from 'lib/ui/Stack';
import { Text } from 'lib/ui/Text';
import { ResponsiveView } from 'lib/ui/ResponsiveView';
import { DepositIntoTreasury } from './deposit';
Expand Down Expand Up @@ -129,7 +129,9 @@ export const TreasuryTokensOverview = () => {
<VStack fullHeight fullWidth justifyContent="space-between" gap={8}>
{renderBasicInfo()}
{renderAssets()}
<HStack justifyContent="flex-end">
<DepositIntoTreasury />
</HStack>
</VStack>
</NormalScreenWidthContainer>
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/enterprise/src/pages/dao/deposit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const DepositIntoTreasury = () => {
connected={() => (
<OverlayOpener
renderOpener={({ onOpen }) => (
<PrimaryButton onClick={onOpen} kind="secondary">
<PrimaryButton onClick={onOpen} kind="secondary" style={{ width: '186px' }}>
Deposit
</PrimaryButton>
)}
Expand Down
11 changes: 7 additions & 4 deletions apps/enterprise/src/pages/dao/staking/NFTStaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { formatAmount } from '@terra-money/apps/libs/formatting';
import { u } from '@terra-money/apps/types';
import Big from 'big.js';
import { NumericPanel } from 'components/numeric-panel';
import { useVotingPowerQuery, useNFTStakingQuery, useReleasableClaimsQuery } from 'queries';
import { useVotingPowerQuery, useNFTStakingQuery, useReleasableClaimsQuery, useSanctionCheck } from 'queries';
import { useClaimTx } from 'tx';
import { Text } from 'components/primitives';
import { DAOLogo } from 'components/dao-logo';
Expand All @@ -23,6 +23,7 @@ import { UnstakeNFTOverlay } from './UnstakeNFTOverlay';
import { useMyNftsQuery } from 'chain/queries/useMyNftsQuery';
import { PrimaryButton } from 'lib/ui/buttons/rect/PrimaryButton';
import { getDaoLogo } from 'dao/utils/getDaoLogo';
import { useConnectedWallet } from '@terra-money/wallet-provider';

const useWalletData = (daoAddress: string, walletAddress: string, totalStaked: u<Big>) => {
const { data: walletStaked = { amount: 0, tokens: [] } } = useNFTStakingQuery(daoAddress, walletAddress);
Expand Down Expand Up @@ -50,6 +51,8 @@ const useWalletData = (daoAddress: string, walletAddress: string, totalStaked: u
export const NftStakingConnectedView = () => {
const walletAddress = useAssertMyAddress();
const dao = useCurrentDao();
const connectedWallet = useConnectedWallet();
const isSanctioned = useSanctionCheck(connectedWallet?.walletAddress)
const { address, dao_membership_contract } = dao;
const { isLoading, totalStaked, symbol } = useNftDaoStakingInfo(address, dao_membership_contract);

Expand Down Expand Up @@ -92,7 +95,7 @@ export const NftStakingConnectedView = () => {
<PrimaryButton
isLoading={isLoading}
tooltipText={isStakingDisabled ? `You don't have NFTs to stake` : undefined}
isDisabled={isStakingDisabled}
isDisabled={isStakingDisabled && isSanctioned as any}
onClick={onOpen}
>
Stake
Expand All @@ -107,7 +110,7 @@ export const NftStakingConnectedView = () => {
renderOpener={({ onOpen }) => (
<PrimaryButton
kind="secondary"
isDisabled={isUnstakeDisabled}
isDisabled={isUnstakeDisabled && isSanctioned as any}
isLoading={isLoading}
onClick={onOpen}
tooltipText={isUnstakeDisabled ? `Your wallet doesn't have NFTs to stake` : undefined}
Expand Down Expand Up @@ -139,7 +142,7 @@ export const NftStakingConnectedView = () => {
<Container className={styles.actions} direction="row">
<PrimaryButton
kind="secondary"
isDisabled={isClaimDisabled}
isDisabled={isClaimDisabled && isSanctioned as any}
tooltipText={isClaimDisabled ? `You don't have NFTs to claim` : undefined}
isLoading={claimTxResult.loading}
onClick={() => {
Expand Down
11 changes: 7 additions & 4 deletions apps/enterprise/src/pages/dao/staking/TokenStaking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useCW20BalanceQuery,
useCW20TokenInfoQuery,
useReleasableClaimsQuery,
useSanctionCheck,
useTokenStakingAmountQuery,
useVotingPowerQuery,
} from 'queries';
Expand All @@ -27,6 +28,7 @@ import { OverlayOpener } from 'lib/ui/OverlayOpener';
import { StakeTokenOverlay } from './StakeTokenOverlay';
import { PrimaryButton } from 'lib/ui/buttons/rect/PrimaryButton';
import { getDaoLogo } from 'dao/utils/getDaoLogo';
import { useConnectedWallet } from '@terra-money/wallet-provider';

const useTokenData = (daoAddress: string, tokenAddress: string) => {
const { data: token } = useCW20TokenInfoQuery(tokenAddress);
Expand Down Expand Up @@ -80,7 +82,8 @@ export const TokenStakingConnectedView = () => {
const dao = useCurrentDao();
const { dao_membership_contract, address } = dao;
const tokenAddress = dao_membership_contract;

const connectedWallet = useConnectedWallet();
const isSanctioned = useSanctionCheck(connectedWallet?.walletAddress)
const { data: token } = useCW20TokenInfoQuery(tokenAddress);

const { isLoading, totalStaked, tokenSymbol, tokenDecimals } = useTokenData(address, tokenAddress);
Expand Down Expand Up @@ -126,7 +129,7 @@ export const TokenStakingConnectedView = () => {
<PrimaryButton
isLoading={isLoading}
tooltipText={isStakeDisabled ? 'No tokens to stake' : undefined}
isDisabled={isStakeDisabled}
isDisabled={isStakeDisabled && isSanctioned as any}
onClick={onOpen}
>
Stake
Expand All @@ -150,7 +153,7 @@ export const TokenStakingConnectedView = () => {
<PrimaryButton
kind="secondary"
isLoading={isLoading}
isDisabled={isUnstakeDisabled}
isDisabled={isUnstakeDisabled && isSanctioned as any}
tooltipText={isUnstakeDisabled && `You don't have staked tokens`}
onClick={onOpen}
>
Expand Down Expand Up @@ -191,7 +194,7 @@ export const TokenStakingConnectedView = () => {
<Container className={styles.actions} direction="row">
<PrimaryButton
kind="secondary"
isDisabled={isClaimDisabled}
isDisabled={isClaimDisabled && isSanctioned as any}
isLoading={claimTxResult.loading}
tooltipText={isClaimDisabled && 'No tokens to claim'}
onClick={() => {
Expand Down
3 changes: 2 additions & 1 deletion apps/enterprise/src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export * from './fetchCW3ListVoters';
export * from './useProposalVoteQuery';
export * from './useTreasuryTokensQuery';
export * from './useNFTInfoQuery';
export * from './useNFTsOwnersQuery';
export * from './useNFTsOwnersQuery';
export * from './useSanctionCheck';
16 changes: 16 additions & 0 deletions apps/enterprise/src/queries/useSanctionCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { useQuery, UseQueryResult } from "react-query"


const isWalletSanctioned = async (walletAddress: string | undefined) => {
// const response = await fetch(`https://something.com/check/${walletAddress}`);
// const isSanctioned = await response.json();
// return isSanctioned;
return true
}

export const useSanctionCheck = (walletAddress: string | undefined): UseQueryResult<boolean> => {
return useQuery([walletAddress] , async () => {
const isSanctioned: boolean = await isWalletSanctioned(walletAddress);
return isSanctioned;
})
}