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

add: minipay btn #48

Open
wants to merge 2 commits into
base: worldcoin-bypass
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Web3Button } from '@web3modal/react'
import { SITE_NAME } from 'utils/config'
import { LinkComponent } from './LinkComponent'
import { PassportScore } from './PassportScore'
import { ConnectMiniPay } from '../../providers/Web3'

import ChainSelector from 'components/ChainSelector'

Expand All @@ -26,6 +27,7 @@ export function Header(props: Props) {
<PassportScore />
<ChainSelector />
<Web3Button icon="hide" label="Connect Wallet" />
<ConnectMiniPay />
{/* <ThemeSwitcher /> */}
</Flex>
</Flex>
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/SuccessComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const SuccessComponent = ({ link, data, message = '', subtitle = '' }: { link: s
<Box margin="5" fontFamily="Dm Sans">
<Button variant="link">
{/* <a href={`https://etherscan.io/tx/${data?.hash}`}> */}
<a target="_blank" href={`https://goerli-optimism.etherscan.io/tx/${data?.hash}#eventlog`}>
<a target="_blank" href={`https://alfajores.celoscan.io/tx/${data?.hash}`}>
Check txn
<Icon as={FiExternalLink} />
</a>
Expand Down
48 changes: 35 additions & 13 deletions src/pages/retrieve.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ import Container from 'components/layout/Container'
import History from 'components/layout/History'
import SuccessComponent from 'components/layout/SuccessComponent'
import referralCampaignContract from '../../contracts/out/ReferralCampaign.sol/ReferralCampaign.json'
import account from './api/account'

const CreateLink: NextPage = () => {
// TODO: Fetch proof from shared state
const account = useAccount()
const { address } = useAccount()
const { colorMode } = useColorMode()
const formWidth = useBreakpointValue({ base: '90%', md: '600px' })
const toast = useToast()
const router = useRouter()

const [campaignId, setCampaignId] = useState<any>('')
const [campaignAddy, setCampaignAddy] = useState<any>('')
const [ref, setRef] = useState<any>('a')
const [ref, setRef] = useState<any>('')
const [isSubmitting, setIsSubmitting] = useState(false)
const [args, setArgs] = useState<any[]>([])
const [proof, setProof] = useState<BigInt[]>([BigInt(1), BigInt(1), BigInt(1), BigInt(1), BigInt(1), BigInt(1), BigInt(1), BigInt(1)])
Expand All @@ -33,8 +34,6 @@ const CreateLink: NextPage = () => {

const [isReadyToSubmit, setIsReadyToSubmit] = useState(false)

const { address } = account

useEffect(() => {
const { ref: refParam, campaignId: campaignIdParam, campaignAddy: campaignAddyParam } = router.query

Expand All @@ -53,13 +52,18 @@ const CreateLink: NextPage = () => {

useEffect(() => {
console.log('Checking if ready to submit')
console.log(`address`)
console.log(address)
console.log(`root`)
console.log(root)
console.log(`nullifier`)
console.log(nullifier)
console.log(`proof`)
console.log(proof)
// address _referrer, address signal, uint256 root, uint256 nullifierHash, uint256[8] calldata proof
// FIXME: the second is the address of the claimer or the campaignId?
setArgs([address, address, root, nullifier, proof])
// first is address of referrer, second is address of referree
setArgs([ref, address, root, nullifier, proof])

if (!address) return
console.log('address passed')
Expand All @@ -76,8 +80,7 @@ const CreateLink: NextPage = () => {
}, [address, root, nullifier, proof])

// TODO: Add history on Atom
console.log('isReadyToSubmit')
console.log(isReadyToSubmit)
console.log(`isReadyToSubmit: ${isReadyToSubmit}`)
const history = []
const {
config,
Expand All @@ -92,9 +95,25 @@ const CreateLink: NextPage = () => {
onSettled(data, error) {
console.warn('Settled', { data, error })
},
})
});

if(isPrepareError) {
console.log("usePrepareContractWrite has following error");
console.log(prepareError);
}

const { data, error, isError, write } = useContractWrite(config)
console.log("config");
console.log(config);

const { data, error, isError, write } = useContractWrite(config);

console.log(`write`);
console.log(write);

if (isError) {
console.log("useContractWrite has following error");
console.log(error);
}

const execute = () => {
if (!!write) {
Expand All @@ -103,9 +122,11 @@ const CreateLink: NextPage = () => {
console.log('executed')
} else {
console.warn("Can't execute because useContractWrite is not yet ready")
console.log(args)
console.log(`args`)
console.log(args);
console.log('sendTx')
console.log(write)
console.log(`write`)
console.log(write);
setIsSubmitting(false)
}
}
Expand Down Expand Up @@ -201,8 +222,9 @@ const CreateLink: NextPage = () => {
<Box display="flex" justifyContent="center" mt={5}>
{!isSuccess && (
<Box>
<Box>{campaignId && <Worldcoin proof={proof} setProof={setProof} setNullifier={setNullifier} setRoot={setRoot} action={campaignId} />}</Box>
{proof?.length > 0 && (
{/* <Box>{campaignId && <Worldcoin proof={proof} setProof={setProof} setNullifier={setNullifier} setRoot={setRoot} action={campaignId} />}</Box> */}
{/* {proof?.length > 0 && ( */}
{(
<motion.div whileHover={{ scale: 1.05 }} transition={{ duration: 0.2 }}>
<Button
backgroundColor="purple.300"
Expand Down
14 changes: 14 additions & 0 deletions src/providers/Web3.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ReactNode, useEffect, useState } from 'react'
import { ETH_CHAINS, THEME_COLOR_SCHEME } from 'utils/config'
import { WagmiConfig, configureChains, createConfig } from 'wagmi'
import { publicProvider } from 'wagmi/providers/public'
import { useAccount, useConnect, useEnsName } from 'wagmi'
import { InjectedConnector } from 'wagmi/connectors/injected'

interface Props {
children: ReactNode
Expand Down Expand Up @@ -49,3 +51,15 @@ export function Web3Provider(props: Props) {
</>
)
}

export function ConnectMiniPay() {
const { address, isConnected } = useAccount()
const { data: ensName } = useEnsName({ address })

const { connect } = useConnect({
connector: new InjectedConnector(),
});

if (isConnected) return <div>Connected to {ensName ?? address}</div>
return <button onClick={() => connect()}>Connect to Injected Wallet</button>
}