import { useQuery, useMutation } from '@apollo/react-hooks' import { makeStyles } from '@material-ui/core' import gql from 'graphql-tag' import * as R from 'ramda' import React, { useState } from 'react' import { Button, SupportLinkButton } from 'src/components/buttons' import { RadioGroup } from 'src/components/inputs' import { H4, Info3 } from 'src/components/typography' import FormRenderer from 'src/pages/Services/FormRenderer' import schema from 'src/pages/Services/schemas' import bitgo from 'src/pages/Services/schemas/singlebitgo' import { ReactComponent as WarningIcon } from 'src/styling/icons/warning-icon/comet.svg' import styles from './Shared.styles' import { getItems } from './getItems' const useStyles = makeStyles(styles) const GET_CONFIG = gql` { accounts accountsConfig { code display class cryptos } cryptoCurrencies { code display } } ` const SAVE_ACCOUNTS = gql` mutation Save($accounts: JSONObject) { saveAccounts(accounts: $accounts) } ` const isConfigurable = it => R.contains(it)(['infura', 'bitgo', 'trongrid', 'galoy']) const isLocalHosted = it => R.contains(it)([ 'bitcoind', 'geth', 'litecoind', 'dashd', 'zcashd', 'bitcoincashd' ]) const ChooseWallet = ({ data: currentData, addData }) => { const classes = useStyles() const { data } = useQuery(GET_CONFIG) const [saveAccounts] = useMutation(SAVE_ACCOUNTS, { onCompleted: () => submit() }) const [selected, setSelected] = useState(null) const [error, setError] = useState(false) const accounts = data?.accounts ?? [] const accountsConfig = data?.accountsConfig ?? [] const coin = currentData.coin const wallets = getItems(accountsConfig, accounts, 'wallet', coin) const saveWallet = name => wallet => { const accounts = { [name]: wallet } return saveAccounts({ variables: { accounts } }) } const submit = () => { if (!selected) return setError(true) addData({ wallet: selected }) } const onSelect = e => { setSelected(e.target.value) setError(false) } return (

Choose your wallet

{isLocalHosted(selected) && ( <>
To set up {selected} please read the node wallet instructions from our support portal.
)} {!isConfigurable(selected) && ( )} {selected === 'bitgo' && ( <>
Make sure you set up a BitGo wallet to enter the necessary information below. Please follow the instructions on our support page if you haven’t.

Enter wallet information

)} {selected === 'infura' && ( <>

Enter wallet information

)} {selected === 'trongrid' && ( <>

Enter wallet information

)} {selected === 'galoy' && ( <>

Enter wallet information

)}
) } export default ChooseWallet