Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
cjinghong committed May 3, 2024
1 parent 7483ddc commit abf5afc
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 92 deletions.
13 changes: 8 additions & 5 deletions governance/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
SolflareWalletAdapter,
} from "@solana/wallet-adapter-wallets";

import { WalletProvider as SolanaWalletProvider, ConnectionProvider } from "@solana/wallet-adapter-react";
import {
WalletProvider as SolanaWalletProvider,
ConnectionProvider,
} from "@solana/wallet-adapter-react";
import { SubgraphDataContextProvider } from "shared/lib/hooks/subgraphDataContext";
import RootApp from "./components/RootApp";
import { Web3ContextProvider } from "shared/lib/hooks/web3Context";
Expand Down Expand Up @@ -43,10 +46,10 @@ function App() {
<ChainContextProvider>
<ConnectionProvider endpoint={getSolanaClusterURI()}>
{/* This is just to prevent useWeb3Wallet from breaking */}
<SolanaWalletProvider wallets={[
new PhantomWalletAdapter(),
new SolflareWalletAdapter(),
]} autoConnect={false}>
<SolanaWalletProvider
wallets={[new PhantomWalletAdapter(), new SolflareWalletAdapter()]}
autoConnect={false}
>
<Web3ContextProvider>
<Web3ReactProvider connectors={allConnectors}>
<PendingTransactionsContextProvider>
Expand Down
9 changes: 6 additions & 3 deletions governance/src/components/Wallet/AccountStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const AccountStatus: React.FC<AccountStatusProps> = ({ variant }) => {
const [copyState, setCopyState] = useState<"visible" | "hiding" | "hidden">(
"hidden"
);
const [showAirdropModal, setShowAirdropModal] = useState(false)
const [showAirdropModal, setShowAirdropModal] = useState(false);

const { data: ensData } = useENSSearch(account || "");

Expand Down Expand Up @@ -342,7 +342,10 @@ const AccountStatus: React.FC<AccountStatusProps> = ({ variant }) => {

return (
<>
<AirdropModal show={showAirdropModal} onClose={() => setShowAirdropModal(false)}/>
<AirdropModal
show={showAirdropModal}
onClose={() => setShowAirdropModal(false)}
/>

{/* Main Button and Desktop Menu */}
<WalletContainer variant={variant} ref={desktopMenuRef}>
Expand Down Expand Up @@ -396,7 +399,7 @@ const AccountStatus: React.FC<AccountStatusProps> = ({ variant }) => {
<MenuItem title="DISCONNECT" onClick={handleDisconnect} />
)}

<AirdropButton onClick={() => setShowAirdropModal(true)}/>
<AirdropButton onClick={() => setShowAirdropModal(true)} />
</DesktopFloatingMenu>
</WalletContainer>

Expand Down
71 changes: 27 additions & 44 deletions governance/src/components/Wallet/Airdrop/AirdropBreakdown.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { useCallback } from "react";
import {
BaseIndicator,
Subtitle
} from "shared/lib/designSystem";
import { BaseIndicator, Subtitle } from "shared/lib/designSystem";
import { CloseIcon } from "shared/lib/assets/icons/icons";
import colors from "shared/lib/designSystem/colors";
import theme from "shared/lib/designSystem/theme";
import { AirdropBreakdownKeys } from "shared/lib/store/types";
import styled from "styled-components";

export const getQualifiedColor = (qualified: boolean) => {
return qualified ? colors.green : colors.red
}
return qualified ? colors.green : colors.red;
};

const getAirdropTitle = (variant: AirdropBreakdownKeys) => {
switch (variant) {
Expand Down Expand Up @@ -48,7 +45,7 @@ const BreakdownPill = styled.div<{
border-radius: 100px;
`;

const BreakdownPillToken = styled(Subtitle) <{
const BreakdownPillToken = styled(Subtitle)<{
qualified: boolean;
}>`
color: ${(props) => getQualifiedColor(props.qualified)};
Expand All @@ -57,8 +54,8 @@ const BreakdownPillToken = styled(Subtitle) <{

interface AirdropBreakdownProps {
breakdown?: {
[key in AirdropBreakdownKeys]: boolean
}
[key in AirdropBreakdownKeys]: boolean;
};
}

const AirdropBreakdown = ({ breakdown }: AirdropBreakdownProps) => {
Expand All @@ -69,17 +66,15 @@ const AirdropBreakdown = ({ breakdown }: AirdropBreakdownProps) => {
<BreakdownPillToken qualified={qualified}>
{getAirdropTitle(key)}
</BreakdownPillToken>
{
qualified
? (
<BaseIndicator
size={8}
color={getQualifiedColor(qualified)}
/>
) : (
<CloseIcon width={8} height={8} stroke={getQualifiedColor(qualified)} />
)
}
{qualified ? (
<BaseIndicator size={8} color={getQualifiedColor(qualified)} />
) : (
<CloseIcon
width={8}
height={8}
stroke={getQualifiedColor(qualified)}
/>
)}
</BreakdownPill>
</BreakdownBackground>
),
Expand All @@ -88,31 +83,19 @@ const AirdropBreakdown = ({ breakdown }: AirdropBreakdownProps) => {

return (
<BreakdownContainer>
{
breakdown
? Object.keys(breakdown).map((key) =>
renderBreakdownPill(
key as AirdropBreakdownKeys,
breakdown[key as AirdropBreakdownKeys]
)
)
: (
<>
{
renderBreakdownPill(
AirdropBreakdownKeys.maxStaked,
false
)
}
{
renderBreakdownPill(
AirdropBreakdownKeys.heldRbnAfterTGE,
false
)
}
</>
{breakdown ? (
Object.keys(breakdown).map((key) =>
renderBreakdownPill(
key as AirdropBreakdownKeys,
breakdown[key as AirdropBreakdownKeys]
)
}
)
) : (
<>
{renderBreakdownPill(AirdropBreakdownKeys.maxStaked, false)}
{renderBreakdownPill(AirdropBreakdownKeys.heldRbnAfterTGE, false)}
</>
)}
</BreakdownContainer>
);
};
Expand Down
3 changes: 1 addition & 2 deletions governance/src/components/Wallet/Airdrop/AirdropButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ButtonContainer = styled.div`
&:hover {
${ClaimText} {
color: #fff;
color: #fff;
}
}
`;
Expand All @@ -37,7 +37,6 @@ const LogoContainer = styled.div`
margin-right: 8px;
`;


const RedLogo = styled(Logo)`
circle {
fill: ${colors.products.yield}3D;
Expand Down
14 changes: 9 additions & 5 deletions governance/src/components/Wallet/Airdrop/AirdropInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const Description = styled(SecondaryText)`
text-align: center;
`;


const ViewBreakdownPill = styled.div`
display: flex;
background: ${colors.green}14;
Expand Down Expand Up @@ -158,12 +157,16 @@ interface AirdropInfoProps {
onClaim: () => void;
}

const AirdropInfo: React.FC<AirdropInfoProps> = ({ loading, airdropInfo, onClaim }) => {
const AirdropInfo: React.FC<AirdropInfoProps> = ({
loading,
airdropInfo,
onClaim,
}) => {
const { account } = useWeb3Wallet();
const [, setShowConnectModal] = useConnectWalletModal();
const [showBreakdown, setShowBreakdown] = useState(false);

const loadingText = useLoadingText("")
const loadingText = useLoadingText("");

const airdropAmountStr = useMemo(() => {
if (!airdropInfo) {
Expand Down Expand Up @@ -248,7 +251,8 @@ const AirdropInfo: React.FC<AirdropInfoProps> = ({ loading, airdropInfo, onClaim
</BaseModalContentColumn>
<BaseModalContentColumn marginTop={16}>
<AirdropExplanationText>
A total of 1,933,802 RBN was distributed to accounts that locked their $RBN for two years.
A total of 1,933,802 RBN was distributed to accounts that locked
their $RBN for two years.
</AirdropExplanationText>
</BaseModalContentColumn>
<BaseModalContentColumn marginTop={16}>
Expand Down Expand Up @@ -355,4 +359,4 @@ const AirdropInfo: React.FC<AirdropInfoProps> = ({ loading, airdropInfo, onClaim

export default AirdropInfo;

// export const x = ""
// export const x = ""
26 changes: 15 additions & 11 deletions governance/src/components/Wallet/Airdrop/AirdropModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const AirdropModal: React.FC<AirdropModalProps> = ({ show, onClose }) => {
await provider.waitForTransaction(txhash, 2);
setStep("claimed");
} catch (err) {
console.error(err)
console.error(err);
setStep("info");
}
}, [
Expand Down Expand Up @@ -86,28 +86,32 @@ const AirdropModal: React.FC<AirdropModalProps> = ({ show, onClose }) => {
initial:
step === "info" || step === "claim"
? {
x: 50,
opacity: 0,
}
x: 50,
opacity: 0,
}
: {},
animate:
step === "info" || step === "claim"
? {
x: 0,
opacity: 1,
}
x: 0,
opacity: 1,
}
: {},
exit:
step === "info"
? {
x: -50,
opacity: 0,
}
x: -50,
opacity: 0,
}
: {},
}}
>
{step === "info" ? (
<AirdropInfo loading={loading} airdropInfo={airdropInfo} onClaim={claimAirdrop} />
<AirdropInfo
loading={loading}
airdropInfo={airdropInfo}
onClaim={claimAirdrop}
/>
) : (
<RBNClaimModalContent step={step} type="rbn" />
)}
Expand Down
40 changes: 22 additions & 18 deletions governance/src/hooks/airdrop/useAirdrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { usePendingTransactions } from "shared/lib/hooks/pendingTransactionsCont
import { impersonateAddress } from "shared/lib/utils/development";
import useMerkleDistributor from "../useMerkleDistributor";

import { AirdropBreakdownKeys, GovernanceAirdropInfoData } from "shared/lib/store/types";
import {
AirdropBreakdownKeys,
GovernanceAirdropInfoData,
} from "shared/lib/store/types";
import { isProduction } from "shared/lib/utils/env";
import ProofData from "./proof-mainnet.json";
import ProofTestnetData from "./proof-testnet.json";
Expand All @@ -20,7 +23,7 @@ export type AirdropClaim = {
index: number;
amount: string;
proof: string[];
}
};

export type AirdropProof = {
merkleRoot: string;
Expand All @@ -34,17 +37,17 @@ export type AirdropBreakdownData = {
[address: string]: {
rbnAmount: number;
heldRbnAfterTGE: boolean;
}
};
};

const proof = isProduction()
? ProofData as AirdropProof
: ProofTestnetData as AirdropProof;
const airdropBreakdown = isProduction()
? BreakdownData as AirdropBreakdownData
: BreakdownTestnetData as AirdropBreakdownData;
const proof = isProduction()
? (ProofData as AirdropProof)
: (ProofTestnetData as AirdropProof);
const airdropBreakdown = isProduction()
? (BreakdownData as AirdropBreakdownData)
: (BreakdownTestnetData as AirdropBreakdownData);

const rbnDecimals = getAssetDecimals("RBN")
const rbnDecimals = getAssetDecimals("RBN");

const useAirdrop = () => {
const web3Context = useWeb3Wallet();
Expand All @@ -54,7 +57,7 @@ const useAirdrop = () => {
const [airdropInfo, setAirdropInfo] = useState<GovernanceAirdropInfoData>();
const { pendingTransactions } = usePendingTransactions();

const [loading, setLoading] = useState(false)
const [loading, setLoading] = useState(false);

const updateAirdropInfo = useCallback(async () => {
if (chainId !== CHAINID.ETH_MAINNET || !account || !merkleDistributor) {
Expand All @@ -63,8 +66,8 @@ const useAirdrop = () => {
}

const airdropClaim = proof["claims"][account];
const totalBn = BigNumber.from(airdropClaim?.amount || 0)
const total = parseFloat(formatUnits(totalBn, rbnDecimals))
const totalBn = BigNumber.from(airdropClaim?.amount || 0);
const total = parseFloat(formatUnits(totalBn, rbnDecimals));

if (!airdropClaim || !total) {
setAirdropInfo(undefined);
Expand All @@ -75,7 +78,7 @@ const useAirdrop = () => {
try {
claimedAmount = await merkleDistributor.claimed(account);
} catch (error) {
console.error("Unable to get claimed amount")
console.error("Unable to get claimed amount");
}

setAirdropInfo({
Expand All @@ -84,17 +87,18 @@ const useAirdrop = () => {
proof: { ...airdropClaim, amount: BigNumber.from(airdropClaim.amount) },
breakdown: {
[AirdropBreakdownKeys.maxStaked]: !totalBn.isZero(),
[AirdropBreakdownKeys.heldRbnAfterTGE]: airdropBreakdown[account.toLowerCase()]?.heldRbnAfterTGE
[AirdropBreakdownKeys.heldRbnAfterTGE]:
airdropBreakdown[account.toLowerCase()]?.heldRbnAfterTGE,
},
unclaimedAmount: totalBn.sub(claimedAmount)
unclaimedAmount: totalBn.sub(claimedAmount),
});
}, [account, merkleDistributor, setAirdropInfo, chainId]);

useEffect(() => {
if (!airdropInfo || airdropInfo.account !== account) {
setLoading(true)
setLoading(true);
updateAirdropInfo().finally(() => {
setLoading(false)
setLoading(false);
});
}
}, [account, airdropInfo, updateAirdropInfo]);
Expand Down
5 changes: 4 additions & 1 deletion governance/src/hooks/useMerkleDistributor.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useEffect, useState } from "react";
import { useWeb3Wallet } from "shared/lib/hooks/useWeb3Wallet";

import { MerkleDistributorAdjustable, MerkleDistributorAdjustable__factory } from "shared/lib/codegen";
import {
MerkleDistributorAdjustable,
MerkleDistributorAdjustable__factory,
} from "shared/lib/codegen";
import deployments from "shared/lib/constants/v1Deployments.json";
import { isProduction } from "shared/lib/utils/env";

Expand Down
Loading

0 comments on commit abf5afc

Please sign in to comment.