import { useQuery, useMutation, gql } from '@apollo/client' import * as R from 'ramda' import React, { useState } from 'react' import { H4, Info3 } from '../../../../components/typography' import FormRenderer from '../../../Services/FormRenderer' import WarningIcon from '../../../../styling/icons/warning-icon/comet.svg?react' import { Button, SupportLinkButton } from '../../../../components/buttons' import { RadioGroup } from '../../../../components/inputs' import _schema from '../../../Services/schemas' import bitgo from '../../../Services/schemas/singlebitgo' import classes from './Shared.module.css' import { getItems } from './getItems' 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.includes(it)(['infura', 'bitgo', 'trongrid', 'galoy']) const isLocalHosted = it => R.includes(it)([ 'bitcoind', 'geth', 'litecoind', 'dashd', 'zcashd', 'bitcoincashd', ]) const ChooseWallet = ({ data: currentData, addData }) => { // no need to fetch exchange config here const schema = _schema() 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