diff --git a/src/graphql/mutations/__generated__/wallet.generated.tsx b/src/graphql/mutations/__generated__/wallet.generated.tsx index 8f6a3a37..41465478 100644 --- a/src/graphql/mutations/__generated__/wallet.generated.tsx +++ b/src/graphql/mutations/__generated__/wallet.generated.tsx @@ -18,6 +18,16 @@ export type CreateWalletMutation = { }; }; +export type ChangeWalletNameMutationVariables = Types.Exact<{ + id: Types.Scalars['String']['input']; + name: Types.Scalars['String']['input']; +}>; + +export type ChangeWalletNameMutation = { + __typename?: 'Mutation'; + wallets: { __typename?: 'WalletMutations'; change_name: boolean }; +}; + export const CreateWalletDocument = gql` mutation CreateWallet($input: CreateWalletInput!) { wallets { @@ -70,3 +80,54 @@ export type CreateWalletMutationOptions = Apollo.BaseMutationOptions< CreateWalletMutation, CreateWalletMutationVariables >; +export const ChangeWalletNameDocument = gql` + mutation ChangeWalletName($id: String!, $name: String!) { + wallets { + change_name(id: $id, name: $name) + } + } +`; +export type ChangeWalletNameMutationFn = Apollo.MutationFunction< + ChangeWalletNameMutation, + ChangeWalletNameMutationVariables +>; + +/** + * __useChangeWalletNameMutation__ + * + * To run a mutation, you first call `useChangeWalletNameMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `useChangeWalletNameMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [changeWalletNameMutation, { data, loading, error }] = useChangeWalletNameMutation({ + * variables: { + * id: // value for 'id' + * name: // value for 'name' + * }, + * }); + */ +export function useChangeWalletNameMutation( + baseOptions?: Apollo.MutationHookOptions< + ChangeWalletNameMutation, + ChangeWalletNameMutationVariables + > +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useMutation< + ChangeWalletNameMutation, + ChangeWalletNameMutationVariables + >(ChangeWalletNameDocument, options); +} +export type ChangeWalletNameMutationHookResult = ReturnType< + typeof useChangeWalletNameMutation +>; +export type ChangeWalletNameMutationResult = + Apollo.MutationResult; +export type ChangeWalletNameMutationOptions = Apollo.BaseMutationOptions< + ChangeWalletNameMutation, + ChangeWalletNameMutationVariables +>; diff --git a/src/graphql/mutations/wallet.ts b/src/graphql/mutations/wallet.ts index cea689d0..50220471 100644 --- a/src/graphql/mutations/wallet.ts +++ b/src/graphql/mutations/wallet.ts @@ -9,3 +9,11 @@ export const CreateWallet = gql` } } `; + +export const ChangeWalletName = gql` + mutation ChangeWalletName($id: String!, $name: String!) { + wallets { + change_name(id: $id, name: $name) + } + } +`; diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 73ac061f..60427df8 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -253,6 +253,7 @@ export type PayMutations = { lightning_invoice: CreateLiquidTransaction; liquid_address: CreateLiquidTransaction; money_address: CreateLiquidTransaction; + network_swap: CreateLiquidTransaction; }; export type PayMutationsLightning_InvoiceArgs = { @@ -267,6 +268,24 @@ export type PayMutationsMoney_AddressArgs = { input: PayLnAddressInput; }; +export type PayMutationsNetwork_SwapArgs = { + input: PayNetworkSwapInput; +}; + +export type PayNetworkSwapInput = { + quote_id: Scalars['String']['input']; + settle_address: Scalars['String']['input']; +}; + +export type PayQueries = { + __typename?: 'PayQueries'; + network_swap_quote: SwapQuote; +}; + +export type PayQueriesNetwork_Swap_QuoteArgs = { + input: SwapQuoteInput; +}; + export enum PaymentOptionCode { Btc = 'BTC', Lightning = 'LIGHTNING', @@ -281,10 +300,27 @@ export enum PaymentOptionNetwork { export type Query = { __typename?: 'Query'; hello: Scalars['String']['output']; + pay: PayQueries; user: User; wallets: WalletQueries; }; +export type ReceiveSwap = { + __typename?: 'ReceiveSwap'; + coin: SwapCoin; + id: Scalars['String']['output']; + max: Scalars['String']['output']; + min: Scalars['String']['output']; + network: SwapNetwork; + receive_address: Scalars['String']['output']; +}; + +export type ReceiveSwapInput = { + deposit_coin: SwapCoin; + deposit_network: SwapNetwork; + wallet_account_id: Scalars['String']['input']; +}; + export type RefreshToken = { __typename?: 'RefreshToken'; access_token: Scalars['String']['output']; @@ -355,11 +391,50 @@ export type SimpleWalletContact = { money_address: Scalars['String']['output']; }; +export enum SwapCoin { + Btc = 'BTC', + Usdt = 'USDT', +} + +export enum SwapNetwork { + Bitcoin = 'bitcoin', + Ethereum = 'ethereum', + Liquid = 'liquid', + Tron = 'tron', +} + +export type SwapQuote = { + __typename?: 'SwapQuote'; + created_at: Scalars['String']['output']; + deposit_amount: Scalars['String']['output']; + deposit_coin: Scalars['String']['output']; + deposit_network: Scalars['String']['output']; + expires_at: Scalars['String']['output']; + id: Scalars['String']['output']; + rate: Scalars['String']['output']; + settle_amount: Scalars['String']['output']; + settle_coin: Scalars['String']['output']; + settle_network: Scalars['String']['output']; +}; + +export type SwapQuoteInput = { + settle_amount: Scalars['String']['input']; + settle_coin: SwapCoin; + settle_network: SwapNetwork; +}; + export type User = { __typename?: 'User'; default_wallet_id?: Maybe; email: Scalars['String']['output']; id: Scalars['String']['output']; + swap_info: UserSwapInfo; +}; + +export type UserSwapInfo = { + __typename?: 'UserSwapInfo'; + id: Scalars['String']['output']; + shifts_enabled: Scalars['Boolean']['output']; }; export type Wallet = { @@ -417,8 +492,10 @@ export type WalletDetails = { export type WalletMutations = { __typename?: 'WalletMutations'; broadcast_liquid_transaction: BroadcastLiquidTransaction; + change_name: Scalars['Boolean']['output']; create: CreateWallet; create_onchain_address: CreateOnchainAddress; + create_onchain_address_swap: ReceiveSwap; refresh_wallet: Scalars['Boolean']['output']; }; @@ -426,6 +503,11 @@ export type WalletMutationsBroadcast_Liquid_TransactionArgs = { input: BroadcastLiquidTransactionInput; }; +export type WalletMutationsChange_NameArgs = { + id: Scalars['String']['input']; + name: Scalars['String']['input']; +}; + export type WalletMutationsCreateArgs = { input: CreateWalletInput; }; @@ -434,6 +516,10 @@ export type WalletMutationsCreate_Onchain_AddressArgs = { input: CreateOnchainAddressInput; }; +export type WalletMutationsCreate_Onchain_Address_SwapArgs = { + input: ReceiveSwapInput; +}; + export type WalletMutationsRefresh_WalletArgs = { input: RefreshWalletInput; }; diff --git a/src/views/app/Dashboard.tsx b/src/views/app/Dashboard.tsx index 7fa3f895..3d390be0 100644 --- a/src/views/app/Dashboard.tsx +++ b/src/views/app/Dashboard.tsx @@ -86,23 +86,28 @@ const WalletDetails: FC<{ id: string }> = ({ id }) => { {addresses.map(a => { return (
-
{a.user}
- {a.domains.map(d => { - return ( -
-

- {'@' + d} -

- -
- ); - })} +
{a.user}
+
+ {a.domains.map(d => { + return ( +
+

+ {'@' + d} +

+ +
+ ); + })} +
); })} diff --git a/src/views/wallet/Settings.tsx b/src/views/wallet/Settings.tsx index e5c8ca66..fee95dea 100644 --- a/src/views/wallet/Settings.tsx +++ b/src/views/wallet/Settings.tsx @@ -1,6 +1,6 @@ 'use client'; -import { Copy, CopyCheck } from 'lucide-react'; +import { Copy, CopyCheck, Loader2 } from 'lucide-react'; import { FC, ReactNode, useEffect, useRef, useState } from 'react'; import { useCopyToClipboard } from 'usehooks-ts'; @@ -8,8 +8,11 @@ import { VaultButton } from '@/components/button/VaultButton'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; +import { useToast } from '@/components/ui/use-toast'; +import { useChangeWalletNameMutation } from '@/graphql/mutations/__generated__/wallet.generated'; import { useGetWalletDetailsQuery } from '@/graphql/queries/__generated__/wallet.generated'; import { useKeyStore } from '@/stores/keys'; +import { handleApolloError } from '@/utils/error'; import { CryptoWorkerMessage, CryptoWorkerResponse, @@ -34,7 +37,75 @@ const Section: FC<{ ); }; -export const WalletSettings: FC<{ walletId: string }> = ({ walletId }) => { +const WalletName: FC<{ walletId: string }> = ({ walletId }) => { + const { toast } = useToast(); + + const [name, setName] = useState(); + + const { data } = useGetWalletDetailsQuery({ + variables: { id: walletId }, + errorPolicy: 'ignore', + }); + + const [changeName, { loading }] = useChangeWalletNameMutation({ + onCompleted: () => { + toast({ + title: 'Wallet name saved.', + }); + }, + onError: err => { + const messages = handleApolloError(err); + + toast({ + variant: 'destructive', + title: 'Error creating new wallet.', + description: messages.join(', '), + }); + }, + refetchQueries: ['getWalletDetails', 'getAllWallets'], + }); + + useEffect(() => { + if (!data) return; + setName(data.wallets.find_one.name); + }, [data]); + + if (!data) return null; + + const hasChange = name !== data.wallets.find_one.name; + + return ( +
+
+ +
+ setName(e.target.value)} + defaultValue={data.wallets.find_one.name} + placeholder="Wallet Name" + /> + +
+
+
+ ); +}; + +const WalletMnemonic: FC<{ walletId: string }> = ({ walletId }) => { const workerRef = useRef(); const [stateLoading, setLoading] = useState(false); @@ -100,13 +171,96 @@ export const WalletSettings: FC<{ walletId: string }> = ({ walletId }) => { } }; - const [copiedText, copy] = useCopyToClipboard(); const [copiedMnemonic, copyMnemonic] = useCopyToClipboard(); const loading = stateLoading || walletLoading; + return ( +
+
+ +
+ + {!masterKey ? ( + + ) : ( + + )} +
+
+ +
+ +
+ + + +
+
+
+ ); +}; + +export const WalletSettings: FC<{ walletId: string }> = ({ walletId }) => { + const { data, loading } = useGetWalletDetailsQuery({ + variables: { id: walletId }, + errorPolicy: 'ignore', + }); + + const [copiedText, copy] = useCopyToClipboard(); + + if (loading) { + return ( +
+ +
+ ); + } + + if (!data?.wallets.find_one.id) { + return ( +
+

Error loading wallet.

+
+ ); + } + return (
+
-
- -
- - {!masterKey ? ( - - ) : ( - - )} -
-
- -
- -
- - - -
-
-
+
); };