Files
js/components/buttons/TransactionButton.tsx
T
5db96a64c7 [SOLANA] (#486)
* init solana dashboard

* some updates

* deploying programs works?

* solana program page is go

* more updates

* various updates and improvements

* git add maybe?

* working state

* working minting / nft list

* working drop lazy mint + latest nightly

* dashboard works

* forgot to add things

* fix various small things

* fix rpc

* implement token page + code organization

* update SDK

* rename accounts to program

* implement token mint button

* split dashboard into evm vs sol and separate out solana programs

* fix caching

* upgrade to combined sdk

* merge in main

* update to latest nightly SDK

* tabs for days

* lul query client maybe?

* remove unused hook

* add super basic nft drawer

* lots of updates to start on nft drawer etc

* add code tab content

* fix merge conflicts

* pass program address to code tab

* some changes

* some minor updates

* new nft drawer and table

* drawer for solana done (v1)

* fix a bunch of stuff

* fix some tracking

* update nightly

* add programId to program deploy event

* adapt to changes in react lib

* upgrade to dev version

* Add batch upload to Solana (#539)

* First small necessary refactor

* Working version

* Working version with yalc

* Use nightly

* Move everything around

* Remove unused imports

* Fix types

* Add state for hasTried

* Fix conditions

* Add solana

* Move selectedReveal to be part of the form

* Improve logic

* Update dependencies

* Make drawer fullscreen

* Fix hasFailed logic

* Fix types

* Make inputs required conditionally

* Fix types

* Make loading work

* Remove repeated code

* Remove unused

* Pass progress as a prop

* Move common files to core-ui

* massive cleanup

Co-authored-by: Jonas Daniels <[email protected]>

* feat(faucet): build solana faucet (#528)

* feat(faucet): build solana faucet

* chore: update names

* fix: type

Co-authored-by: Jonas Daniels <[email protected]>

* fix: minor stuff

Co-authored-by: Jonas Daniels <[email protected]>

* fix: feedback

* feat: minor improvements

* feat: add faq section

* refactor: refactor faq

* add accordion

* minor fix

Co-authored-by: Jonas Daniels <[email protected]>

* tiny fix

* Revert batch upload styles (#541)

* Fix typo, fix drawer width

* Revert to old batch upload styles

* Fix some more styles

* Fix progress bar styles

* Update to using TWRegistry

* [Solana] Add claim conditions to NFT Drop (#542)

* Add tab and getter

* Working version

* Delete unused imports

* Currency selector works but I hate it

* Add maxClaimable

* Fix build issue

* Make batch upload work again

* Fix claim conditions for devnet

* Test fix

* Delete console.logs

* A lot of solana stuff (#545)

* Remove unused banner

* Hide Claim Conditions tab for no drops

* Add loading state

* Remove comment

* Add helper text for nft drop supply

* Delete log

* Add loading state to program list

* Add redirect if you don't have any program deploys

* Add default instant reveal for Solana

* Fix styles

* Fix logic

* doc fixes

* fix(faucet): minor issues (#543)

* fix(spacing): fix spacing in faq

* feat: some updates from feedback

* fix: use linkButton

* feat: use fetch

* remove test code

* fix: err handling

* pass err

* fix sucecss state

* fix: link

* some updates

* small fixes

Co-authored-by: Nacho Iacovino <[email protected]>

* update to latest nightly

* fix up form and update deps

* Add claim button to Solana (#555)

* wip

* Add claim buttons, fix warning, disable buttons conditioanlly

* Use nightly

* Delete unused import

* Solana hackathon landing (#554)

* feat: build hackathon page (#547)

* wip: build hackathon page

* add some more stuff

* feat: responsievness and some minor stuff

Co-authored-by: Nacho Iacovino <[email protected]>

* First section

* Fix PrizeSection

* Add link to register now

* Add judges and footer

* Update startTime for hackathon

* Fix Schedule

* Add tracking

* Add pageId

* Prettier?

* Prettier again

* Prettier you're drunk

* This is my life now

* Remove unused import

* Add og metadata

* Update SEO

Co-authored-by: Avneesh Agarwal <[email protected]>
Co-authored-by: Jonas Daniels <[email protected]>

* Add solana landing page (#556)

* Add landing page for Solana

* Add solana landing page

* Add shopify landing

* Add shopify

* Remove quote

* Add meta tags

* Add landing page updates

* Add links

* small cleanups

* fix various & pagination on nft table solana

* Show unclaimed instead of tokenId for lazy minted tokens

* add full install command for solana react

* show create cli command in code tab for react

* add funds notice for solana

* add various things

* various updates

* various updates

* updated some guides and copy based on juan feedback

* Fix Solana faucet link

* Add disclaimer on how to deploy with Devnet

* Small fixes

* Update guidelines

* Fix currency selector bug

* Update hero copy

* fix build issues

* update to latest

* link solana cards

* Add partners

* update og images for shopify & solana

* Add solanathon og:image

* copy changes

* Update image size

* Center sponsors

Co-authored-by: Joaquim Verges <[email protected]>
Co-authored-by: Nacho Iacovino <[email protected]>
Co-authored-by: Avneesh Agarwal <[email protected]>
Co-authored-by: Nacho Iacovino <[email protected]>
Co-authored-by: Adam Majmudar <[email protected]>
2022-10-12 17:41:45 +00:00

230 lines
6.5 KiB
TypeScript

import { MismatchButton } from "./MismatchButton";
import { EcosystemButtonprops } from "@3rdweb-sdk/react";
import {
Center,
Flex,
Icon,
Popover,
PopoverArrow,
PopoverBody,
PopoverContent,
PopoverTrigger,
Tooltip,
} from "@chakra-ui/react";
import { useAccount, useAddress, useChainId } from "@thirdweb-dev/react";
import { CHAIN_ID_TO_GNOSIS } from "constants/mappings";
import React, { useEffect, useMemo, useRef, useState } from "react";
import useDimensions from "react-cool-dimensions";
import { BiTransferAlt } from "react-icons/bi";
import { FiInfo } from "react-icons/fi";
import { Card, Heading, LinkButton, Text } from "tw-components";
export interface TransactionButtonProps
extends Omit<EcosystemButtonprops, "leftIcon"> {
transactionCount: number;
isLoading: boolean;
}
export const TransactionButton: React.FC<TransactionButtonProps> = ({
children,
transactionCount,
isLoading,
size,
colorScheme,
variant,
ecosystem,
...restButtonProps
}) => {
const { observe, width } = useDimensions<HTMLSpanElement | null>();
const [{ data }] = useAccount();
const connectorRequiresExternalConfirmation = useMemo(() => {
return (
data?.connector?.id === "gnosis" ||
data?.connector?.id === "walletConnect"
);
}, [data?.connector?.id]);
const initialFocusRef = useRef<HTMLButtonElement>(null);
return (
<Popover
returnFocusOnClose={false}
initialFocusRef={initialFocusRef}
isLazy
isOpen={connectorRequiresExternalConfirmation && isLoading}
>
<PopoverTrigger>
<MismatchButton
ecosystem={ecosystem}
borderRadius="md"
position="relative"
role="group"
colorScheme={colorScheme}
isLoading={isLoading}
size={size}
variant={variant}
{...restButtonProps}
overflow="hidden"
pl={
isLoading
? undefined
: `calc(${width * 2}px + var(--chakra-space-${
size === "sm" ? 3 : size === "lg" ? 6 : size === "xs" ? 2 : 4
}))`
}
>
{children}
<Tooltip
bg="transparent"
boxShadow="none"
p={0}
w="auto"
label={
<Card w="auto" py={2}>
<Text>
This action will trigger {transactionCount}{" "}
{transactionCount > 1 ? "transactions" : "transaction"}.
</Text>
</Card>
}
>
<Center
_groupHover={{
bg:
variant === "solid" || !variant
? `${colorScheme}.800`
: `${colorScheme}.200`,
}}
transitionProperty="var(--chakra-transition-property-common)"
transitionDuration="var(--chakra-transition-duration-normal)"
ref={observe}
as="span"
bg={
variant === "solid" || !variant
? `${colorScheme}.700`
: `${colorScheme}.100`
}
position="absolute"
top={0}
bottom={0}
left={0}
px={size === "sm" ? 3 : size === "lg" ? 6 : size === "xs" ? 2 : 4}
>
<Flex
as="span"
color="whiteAlpha.900"
justify="center"
gap={1}
align="center"
>
<Text color="inherit" size="label.md" fontFamily="mono">
{transactionCount}
</Text>
<BiTransferAlt />
</Flex>
</Center>
</Tooltip>
</MismatchButton>
</PopoverTrigger>
<Card
maxW="sm"
w="auto"
as={PopoverContent}
bg="backgroundCardHighlight"
mx={6}
boxShadow="0px 0px 2px 0px var(--popper-arrow-shadow-color)"
>
<PopoverArrow bg="backgroundCardHighlight" />
<PopoverBody>
<ExternalApprovalNotice
connectorId={data?.connector?.id}
initialFocusRef={initialFocusRef}
/>
</PopoverBody>
</Card>
</Popover>
);
};
interface ExternalApprovalNoticeProps {
connectorId?: string;
initialFocusRef: React.RefObject<HTMLButtonElement>;
}
const ExternalApprovalNotice: React.FC<ExternalApprovalNoticeProps> = ({
connectorId,
initialFocusRef,
}) => {
const address = useAddress();
const chainId = useChainId() || -1;
const [showHint, setShowHint] = useState(false);
useEffect(() => {
const t = setTimeout(() => {
setShowHint(true);
}, 15_000);
return () => clearTimeout(t);
}, []);
if (connectorId === "gnosis") {
const isChainIdSupported = chainId in CHAIN_ID_TO_GNOSIS;
return (
<Flex direction="column" gap={4}>
<Heading size="label.lg">
<Flex gap={2} align="center">
<Icon color="blue.500" boxSize={6} as={FiInfo} />
<span>Execute Transaction</span>
</Flex>
</Heading>
<Text>
You will need to execute this transaction in your Gnosis Safe to
continue.
</Text>
{showHint && (
<Text fontStyle="italic" size="body.sm">
Once you have approved and executed the transaction in your Gnosis
Safe this action will continue automatically.
</Text>
)}
<LinkButton
isDisabled={!isChainIdSupported}
ref={initialFocusRef}
colorScheme="primary"
size="sm"
href={`https://gnosis-safe.io/app/${
CHAIN_ID_TO_GNOSIS[chainId as keyof typeof CHAIN_ID_TO_GNOSIS]
}:${address}/transactions/queue`}
isExternal
>
Go To Gnosis Safe
</LinkButton>
</Flex>
);
} else if (connectorId === "walletConnect") {
return (
<Flex direction="column" gap={4}>
<Heading size="label.lg">
<Flex gap={2} align="center">
<Icon color="blue.500" boxSize={6} as={FiInfo} />
<span>Approve Transaction</span>
</Flex>
</Heading>
<Text>
You will need to approve this transaction in your connected wallet.
</Text>
{showHint && (
<Text fontStyle="italic" size="body.sm">
Once you have approved the transaction in your connected wallet this
action will continue automatically.
</Text>
)}
</Flex>
);
}
return null;
};