Skip to content

Commit

Permalink
Update Coinbase Wallet connector version, add CreateWalletButton
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively committed May 31, 2024
1 parent 6dce7fc commit dde22ae
Show file tree
Hide file tree
Showing 16 changed files with 1,403 additions and 1,562 deletions.
3 changes: 2 additions & 1 deletion earn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@apollo/client": "^3.10.3",
"@apollo/react-hooks": "^4.0.0",
"@coinbase/wallet-sdk": "^4.0.0",
"@craco/craco": "^7.0.0",
"@headlessui/react": "^1.4.3",
"@heroicons/react": "^1.0.5",
Expand Down Expand Up @@ -53,7 +54,7 @@
"styled-components": "^5.3.3",
"typescript": "5.0.4",
"viem": "2.x",
"wagmi": "^2.9.0",
"wagmi": "^2.9.7",
"walletconnect": "^1.7.1",
"web-vitals": "^2.1.4"
},
Expand Down
20 changes: 16 additions & 4 deletions earn/src/components/markets/modal/SupplyModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function getConfirmButton(state: ConfirmButtonState, token: Token): { text: stri
}

type DepositButtonProps = {
hasAuxiliaryFunds: boolean;
supplyAmount: GN;
userBalanceTotal: GN;
userBalanceToken: GN;
Expand All @@ -85,8 +86,17 @@ type DepositButtonProps = {
};

function DepositButton(props: DepositButtonProps) {
const { supplyAmount, userBalanceTotal, userBalanceToken, token, kitty, accountAddress, setIsOpen, setPendingTxn } =
props;
const {
hasAuxiliaryFunds,
supplyAmount,
userBalanceTotal,
userBalanceToken,
token,
kitty,
accountAddress,
setIsOpen,
setPendingTxn,
} = props;
const activeChain = useChain();

const supplyAmountToken = GN.min(supplyAmount, userBalanceToken);
Expand Down Expand Up @@ -121,7 +131,7 @@ function DepositButton(props: DepositButtonProps) {
confirmButtonState = ConfirmButtonState.WAITING_FOR_TRANSACTION;
} else if (supplyAmount.isZero()) {
confirmButtonState = ConfirmButtonState.LOADING;
} else if (supplyAmount.gt(userBalanceTotal)) {
} else if (supplyAmount.gt(userBalanceTotal) && !hasAuxiliaryFunds) {
confirmButtonState = ConfirmButtonState.INSUFFICIENT_ASSET;
} else {
confirmButtonState = permit2StateToButtonStateMap[permit2State] ?? ConfirmButtonState.READY;
Expand Down Expand Up @@ -163,13 +173,14 @@ function DepositButton(props: DepositButtonProps) {

export type SupplyModalProps = {
isOpen: boolean;
hasAuxiliaryFunds: boolean;
selectedRow: SupplyTableRow;
setIsOpen: (isOpen: boolean) => void;
setPendingTxn: (pendingTxn: WriteContractReturnType | null) => void;
};

export default function SupplyModal(props: SupplyModalProps) {
const { isOpen, selectedRow, setIsOpen, setPendingTxn } = props;
const { isOpen, hasAuxiliaryFunds, selectedRow, setIsOpen, setPendingTxn } = props;
const [amount, setAmount] = useState<string>('');
const activeChain = useChain();
const { address: userAddress } = useAccount();
Expand Down Expand Up @@ -267,6 +278,7 @@ export default function SupplyModal(props: SupplyModalProps) {
</Text>
</div>
<DepositButton
hasAuxiliaryFunds={hasAuxiliaryFunds}
accountAddress={userAddress ?? '0x'}
supplyAmount={supplyAmount}
userBalanceTotal={userBalance}
Expand Down
6 changes: 4 additions & 2 deletions earn/src/components/markets/supply/SupplyTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ export type SupplyTableRow = {
};

export type SupplyTableProps = {
hasAuxiliaryFunds: boolean;
rows: SupplyTableRow[];
setPendingTxn: (pendingTxn: WriteContractReturnType | null) => void;
};

export default function SupplyTable(props: SupplyTableProps) {
const { rows, setPendingTxn } = props;
const { hasAuxiliaryFunds, rows, setPendingTxn } = props;
const activeChain = useChain();
const [currentPage, setCurrentPage] = useState(1);
const [selectedSupply, setSelectedSupply] = useState<SupplyTableRow | null>(null);
Expand Down Expand Up @@ -281,7 +282,7 @@ export default function SupplyTable(props: SupplyTableProps) {
onClick={() => {
if (userAddress) setSelectedSupply(row);
}}
disabled={userAddress && row.suppliableBalance === 0}
disabled={userAddress && row.suppliableBalance === 0 && !hasAuxiliaryFunds}
className='connect-wallet-button-trigger'
>
Supply
Expand Down Expand Up @@ -335,6 +336,7 @@ export default function SupplyTable(props: SupplyTableProps) {
</TableContainer>
{selectedSupply && (
<SupplyModal
hasAuxiliaryFunds={hasAuxiliaryFunds}
isOpen={true}
selectedRow={selectedSupply}
setIsOpen={() => {
Expand Down
4 changes: 3 additions & 1 deletion earn/src/pages/MarketsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ export default function MarketsPage() {
switch (selectedTab) {
default:
case TabOption.Supply:
tabContent = <SupplyTable rows={supplyRows} setPendingTxn={setPendingTxn} />;
tabContent = (
<SupplyTable hasAuxiliaryFunds={hasAuxiliaryFunds} rows={supplyRows} setPendingTxn={setPendingTxn} />
);
break;
case TabOption.Borrow:
tabContent = (
Expand Down
3 changes: 2 additions & 1 deletion prime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dependencies": {
"@apollo/client": "^3.10.3",
"@apollo/react-hooks": "^4.0.0",
"@coinbase/wallet-sdk": "^4.0.0",
"@craco/craco": "^7.0.0",
"@headlessui/react": "^1.4.3",
"@heroicons/react": "^1.0.5",
Expand Down Expand Up @@ -51,7 +52,7 @@
"styled-components": "^5.3.3",
"typescript": "5.0.4",
"viem": "2.x",
"wagmi": "^2.9.0",
"wagmi": "^2.9.7",
"walletconnect": "^1.7.1",
"web-vitals": "^2.1.4"
},
Expand Down
5 changes: 3 additions & 2 deletions shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"dependencies": {
"@apollo/client": "^3.10.3",
"@apollo/react-hooks": "^4.0.0",
"@coinbase/wallet-sdk": "^4.0.0",
"@heroicons/react": "^1.0.5",
"@metamask/jazzicon": "^2.0.0",
"@types/axios": "^0.14.0",
Expand All @@ -31,17 +32,17 @@
"big.js": "^6.1.1",
"ethereum-multicall": "^2.15.0",
"ethers": "5.7.1",
"jsbi": "^3.1.4",
"graphql": "^16.5.0",
"graphql-tag": "^2.12.6",
"jsbi": "^3.1.4",
"node-polyfill-webpack-plugin": "^1.1.4",
"postcss-nested": "^5.0.6",
"prettier": "^2.8.8",
"qrcode.react": "^3.1.0",
"styled-components": "^5.3.3",
"typescript": "5.0.4",
"viem": "2.x",
"wagmi": "^2.9.0"
"wagmi": "^2.9.7"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
Expand Down
2 changes: 1 addition & 1 deletion shared/src/components/WagmiConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const wagmiConfig = createConfig({
appName: metadata.name,
// appLogoUrl: // TODO: do better than favicon
// appChainIds: [mainnet.id, optimism.id, arbitrum.id, base.id],
darkMode: true,
preference: 'all',
}),
safe(),
],
Expand Down
26 changes: 13 additions & 13 deletions shared/src/components/common/Buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@ export const OutlinedGradientButton = styled(BaseButton)`
background: ${GREY_900};
}
}
@keyframes pulse-shadow {
0% {
box-shadow: 0px 0px 0px 0px rgba(126, 213, 197, 0.9), 0px 0px 0px -4px rgba(154, 173, 241, 0.9);
}
50% {
box-shadow: 0px 0px 0px 8px rgba(126, 213, 197, 0.3), 0px 0px 0px 4px rgba(154, 173, 241, 0.3);
transform: translate(-4px);
}
100% {
box-shadow: 0px 0px 0px 0px rgba(126, 213, 197, 0.9), 0px 0px 0px -4px rgba(154, 173, 241, 0.9);
}
}
`;

export const OutlinedWhiteButton = styled(BaseButton)`
Expand Down Expand Up @@ -338,19 +351,6 @@ export const FilledStylizedButton = styled(BaseButton)`
&:focus-visible {
box-shadow: 0px 0px 0px 2px ${GREY_900}, 0px 0px 0px 4px rgba(255, 255, 255, 0.2);
}
@keyframes pulse-shadow {
0% {
box-shadow: 0px 0px 0px 0px rgba(126, 213, 197, 0.9), 0px 0px 0px -4px rgba(154, 173, 241, 0.9);
}
50% {
box-shadow: 0px 0px 0px 8px rgba(126, 213, 197, 0.3), 0px 0px 0px 4px rgba(154, 173, 241, 0.3);
transform: translate(-4px);
}
100% {
box-shadow: 0px 0px 0px 0px rgba(126, 213, 197, 0.9), 0px 0px 0px -4px rgba(154, 173, 241, 0.9);
}
}
`;

export const OutlinedGradientRoundedButton = styled(BaseButton)`
Expand Down
10 changes: 4 additions & 6 deletions shared/src/components/common/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React from 'react';

import { Text } from './Typography';
import styled from 'styled-components';

import DiscordFooterIcon from '../../assets/svg/DiscordFooter';
import TwitterFooterIcon from '../../assets/svg/TwitterFooter';
import MediumFooterIcon from '../../assets/svg/MediumFooter';
import { RESPONSIVE_BREAKPOINT_TABLET } from '../../data/constants/Breakpoints';
import { RESPONSIVE_BREAKPOINTS } from '../../data/constants/Breakpoints';
import { GREY_400 } from '../../data/constants/Colors';
import { TERMS_OF_SERVICE_URL } from '../../data/constants/Values';

Expand All @@ -22,11 +20,11 @@ const StyledFooter = styled.footer`
min-height: 60px;
background-color: rgba(6, 11, 15, 1);
border-top: 1px solid rgba(18, 29, 37, 1);
padding-left: 188px;
padding-right: 180px;
padding-left: 20px;
padding-right: 20px;
z-index: 40;
@media (max-width: ${RESPONSIVE_BREAKPOINT_TABLET}) {
@media (max-width: ${RESPONSIVE_BREAKPOINTS.TABLET}px) {
display: none;
}
`;
Expand Down
9 changes: 5 additions & 4 deletions shared/src/components/navbar/ConnectWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useState } from 'react';

import { FilledStylizedButton } from '../common/Buttons';
import { FilledStylizedButton, OutlinedGradientButton } from '../common/Buttons';
import { Text } from '../common/Typography';
import { getIconForWagmiConnectorNamed } from './ConnectorIconMap';
import styled from 'styled-components';
Expand All @@ -14,6 +14,7 @@ const Container = styled.div.attrs((props: { fillWidth: boolean }) => props)`
`;

export type ConnectWalletButtonProps = {
shouldShortenText: boolean;
checkboxes: React.ReactNode[];
disabled?: boolean;
fillWidth?: boolean;
Expand Down Expand Up @@ -79,7 +80,7 @@ export default function ConnectWalletButton(props: ConnectWalletButtonProps) {

return (
<Container fillWidth={fillWidth}>
<FilledStylizedButton
<OutlinedGradientButton
onClick={() => {
setWalletModalOpen(true);
}}
Expand All @@ -88,8 +89,8 @@ export default function ConnectWalletButton(props: ConnectWalletButtonProps) {
disabled={disabled}
className='connect-wallet-button'
>
Connect Wallet
</FilledStylizedButton>
{props.shouldShortenText ? 'Connect' : 'Connect Wallet'}
</OutlinedGradientButton>
<Modal isOpen={walletModalOpen} setIsOpen={setWalletModalOpen} title={'Connect Wallet'}>
{acceptedTerms ? (
<div className='w-full'>
Expand Down
57 changes: 57 additions & 0 deletions shared/src/components/navbar/CreateWalletButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useCallback } from 'react';
import styled from 'styled-components';
import { useConnect } from 'wagmi';
import { RESPONSIVE_BREAKPOINTS } from '../../data/constants/Breakpoints';

export function CoinbaseWalletLogo({ size = 26 }) {
return (
<svg width={size} height={size} viewBox='0 0 32 32' fill='none' xmlns='http://www.w3.org/2000/svg'>
<path
// eslint-disable-next-line max-len
d='M2.66675 15.9998C2.66675 23.3628 8.63712 29.3332 16.0001 29.3332C23.363 29.3332 29.3334 23.3628 29.3334 15.9998C29.3334 8.63687 23.363 2.6665 16.0001 2.6665C8.63712 2.6665 2.66675 8.63687 2.66675 15.9998ZM12.5927 11.7035H19.4075C19.9001 11.7035 20.2964 12.0998 20.2964 12.5924V19.4072C20.2964 19.8998 19.9001 20.2961 19.4075 20.2961H12.5927C12.1001 20.2961 11.7038 19.8998 11.7038 19.4072V12.5924C11.7038 12.0998 12.1001 11.7035 12.5927 11.7035Z'
fill='white'
/>
</svg>
);
}

const StyledButton = styled.button`
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
gap: 0.75rem;
border-radius: 8px;
background: transparent;
background-color: #0052ff;
font-weight: 700;
font-size: 16px;
line-height: 21.6px;
white-space: nowrap;
padding: 12px 20px;
@media (max-width: ${RESPONSIVE_BREAKPOINTS.XS}px) {
display: none;
}
`;

export function BlueCreateWalletButton({ shouldShortenText }: { shouldShortenText: boolean }) {
const { connectors, connect } = useConnect();

const createWallet = useCallback(() => {
const coinbaseWalletConnector = connectors.find((connector) => connector.id === 'coinbaseWalletSDK');
if (coinbaseWalletConnector) {
connect({ connector: coinbaseWalletConnector });
}
}, [connectors, connect]);
return (
<StyledButton onClick={createWallet}>
<CoinbaseWalletLogo size={18} />
{shouldShortenText ? 'Create' : 'Create Wallet'}
</StyledButton>
);
}
Loading

0 comments on commit dde22ae

Please sign in to comment.