From 06408a78845037390289de7f4af4efa966ce8b19 Mon Sep 17 00:00:00 2001 From: Anthony Potdevin Date: Wed, 26 Jun 2024 21:07:59 -0500 Subject: [PATCH] chore: swap queries --- .../queries/__generated__/swaps.generated.tsx | 115 ++++++++++++++++++ .../__generated__/wallet.generated.tsx | 26 +++- src/graphql/queries/swaps.ts | 18 +++ src/graphql/queries/wallet.ts | 12 +- src/graphql/types.ts | 26 +++- src/views/app/Dashboard.tsx | 74 +++++------ src/views/wallet/Settings.tsx | 53 ++++---- 7 files changed, 255 insertions(+), 69 deletions(-) create mode 100644 src/graphql/queries/__generated__/swaps.generated.tsx create mode 100644 src/graphql/queries/swaps.ts diff --git a/src/graphql/queries/__generated__/swaps.generated.tsx b/src/graphql/queries/__generated__/swaps.generated.tsx new file mode 100644 index 00000000..3b0c6c46 --- /dev/null +++ b/src/graphql/queries/__generated__/swaps.generated.tsx @@ -0,0 +1,115 @@ +/* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY. */ +/* eslint-disable no-unused-vars, @typescript-eslint/no-unused-vars */ +import { gql } from '@apollo/client'; +import * as Apollo from '@apollo/client'; + +import * as Types from '../../types'; + +const defaultOptions = {} as const; +export type GetWalletSwapsQueryVariables = Types.Exact<{ + id: Types.Scalars['String']['input']; +}>; + +export type GetWalletSwapsQuery = { + __typename?: 'Query'; + wallets: { + __typename?: 'WalletQueries'; + id: string; + find_one: { + __typename?: 'Wallet'; + id: string; + swaps: { + __typename?: 'WalletSwaps'; + id: string; + find_many: Array<{ __typename?: 'SimpleSwap'; id: string }>; + }; + }; + }; +}; + +export const GetWalletSwapsDocument = gql` + query getWalletSwaps($id: String!) { + wallets { + id + find_one(id: $id) { + id + swaps { + id + find_many { + id + } + } + } + } + } +`; + +/** + * __useGetWalletSwapsQuery__ + * + * To run a query within a React component, call `useGetWalletSwapsQuery` and pass it any options that fit your needs. + * When your component renders, `useGetWalletSwapsQuery` returns an object from Apollo Client that contains loading, error, and data properties + * you can use to render your UI. + * + * @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; + * + * @example + * const { data, loading, error } = useGetWalletSwapsQuery({ + * variables: { + * id: // value for 'id' + * }, + * }); + */ +export function useGetWalletSwapsQuery( + baseOptions: Apollo.QueryHookOptions< + GetWalletSwapsQuery, + GetWalletSwapsQueryVariables + > & + ( + | { variables: GetWalletSwapsQueryVariables; skip?: boolean } + | { skip: boolean } + ) +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useQuery( + GetWalletSwapsDocument, + options + ); +} +export function useGetWalletSwapsLazyQuery( + baseOptions?: Apollo.LazyQueryHookOptions< + GetWalletSwapsQuery, + GetWalletSwapsQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useLazyQuery( + GetWalletSwapsDocument, + options + ); +} +export function useGetWalletSwapsSuspenseQuery( + baseOptions?: Apollo.SuspenseQueryHookOptions< + GetWalletSwapsQuery, + GetWalletSwapsQueryVariables + > +) { + const options = { ...defaultOptions, ...baseOptions }; + return Apollo.useSuspenseQuery< + GetWalletSwapsQuery, + GetWalletSwapsQueryVariables + >(GetWalletSwapsDocument, options); +} +export type GetWalletSwapsQueryHookResult = ReturnType< + typeof useGetWalletSwapsQuery +>; +export type GetWalletSwapsLazyQueryHookResult = ReturnType< + typeof useGetWalletSwapsLazyQuery +>; +export type GetWalletSwapsSuspenseQueryHookResult = ReturnType< + typeof useGetWalletSwapsSuspenseQuery +>; +export type GetWalletSwapsQueryResult = Apollo.QueryResult< + GetWalletSwapsQuery, + GetWalletSwapsQueryVariables +>; diff --git a/src/graphql/queries/__generated__/wallet.generated.tsx b/src/graphql/queries/__generated__/wallet.generated.tsx index adecc3d6..990951a2 100644 --- a/src/graphql/queries/__generated__/wallet.generated.tsx +++ b/src/graphql/queries/__generated__/wallet.generated.tsx @@ -40,7 +40,12 @@ export type GetWalletDetailsQuery = { __typename?: 'Wallet'; id: string; name: string; - money_address?: string | null; + money_address: Array<{ + __typename?: 'MoneyAddress'; + id: string; + user: string; + domains: Array; + }>; details: { __typename?: 'WalletDetails'; id: string; @@ -64,7 +69,12 @@ export type GetWalletQuery = { __typename?: 'Wallet'; id: string; name: string; - money_address?: string | null; + money_address: Array<{ + __typename?: 'MoneyAddress'; + id: string; + user: string; + domains: Array; + }>; details: { __typename?: 'WalletDetails'; id: string; @@ -218,7 +228,11 @@ export const GetWalletDetailsDocument = gql` find_one(id: $id) { id name - money_address + money_address { + id + user + domains + } details { id type @@ -305,7 +319,11 @@ export const GetWalletDocument = gql` find_one(id: $id) { id name - money_address + money_address { + id + user + domains + } details { id type diff --git a/src/graphql/queries/swaps.ts b/src/graphql/queries/swaps.ts new file mode 100644 index 00000000..5deb6dbc --- /dev/null +++ b/src/graphql/queries/swaps.ts @@ -0,0 +1,18 @@ +import { gql } from '@apollo/client'; + +export const GetWalletSwaps = gql` + query getWalletSwaps($id: String!) { + wallets { + id + find_one(id: $id) { + id + swaps { + id + find_many { + id + } + } + } + } + } +`; diff --git a/src/graphql/queries/wallet.ts b/src/graphql/queries/wallet.ts index 5eff8949..fd1751ec 100644 --- a/src/graphql/queries/wallet.ts +++ b/src/graphql/queries/wallet.ts @@ -24,7 +24,11 @@ export const GetWalletDetails = gql` find_one(id: $id) { id name - money_address + money_address { + id + user + domains + } details { id type @@ -42,7 +46,11 @@ export const GetWallet = gql` find_one(id: $id) { id name - money_address + money_address { + id + user + domains + } details { id type diff --git a/src/graphql/types.ts b/src/graphql/types.ts index 82376d58..f10cd93f 100644 --- a/src/graphql/types.ts +++ b/src/graphql/types.ts @@ -185,6 +185,13 @@ export type LoginInput = { master_password_hash: Scalars['String']['input']; }; +export type MoneyAddress = { + __typename?: 'MoneyAddress'; + domains: Array; + id: Scalars['String']['output']; + user: Scalars['String']['output']; +}; + export type Mutation = { __typename?: 'Mutation'; checkPassword: Scalars['Boolean']['output']; @@ -192,7 +199,6 @@ export type Mutation = { login: NewAccount; logout: Scalars['Boolean']['output']; pay: PayMutations; - payInvoice: Scalars['Boolean']['output']; refreshToken: RefreshToken; signUp: NewAccount; wallets: WalletMutations; @@ -210,10 +216,6 @@ export type MutationPayArgs = { input: PayInput; }; -export type MutationPayInvoiceArgs = { - invoice: Scalars['String']['input']; -}; - export type MutationSignUpArgs = { input: SignUpInput; }; @@ -328,6 +330,11 @@ export type SignUpInput = { wallet?: InputMaybe; }; +export type SimpleSwap = { + __typename?: 'SimpleSwap'; + id: Scalars['String']['output']; +}; + export type SimpleWallet = { __typename?: 'SimpleWallet'; accounts: Array; @@ -361,9 +368,10 @@ export type Wallet = { contacts: WalletContacts; details: WalletDetails; id: Scalars['String']['output']; - money_address?: Maybe; + money_address: Array; name: Scalars['String']['output']; secp256k1_key_pair: Secp256k1KeyPair; + swaps: WalletSwaps; }; export type WalletAccount = { @@ -441,6 +449,12 @@ export type WalletQueriesFind_OneArgs = { id: Scalars['String']['input']; }; +export type WalletSwaps = { + __typename?: 'WalletSwaps'; + find_many: Array; + id: Scalars['String']['output']; +}; + export enum WalletType { ClientGenerated = 'CLIENT_GENERATED', } diff --git a/src/views/app/Dashboard.tsx b/src/views/app/Dashboard.tsx index 32fb236a..4d19f6a6 100644 --- a/src/views/app/Dashboard.tsx +++ b/src/views/app/Dashboard.tsx @@ -38,14 +38,11 @@ const WalletDetails: FC<{ id: string }> = ({ id }) => { onError: err => console.log('ERROR', err), }); - const address = useMemo(() => { + const addresses = useMemo(() => { if (!data?.wallets.find_one.money_address) { - return null; + return []; } - - const [user, domain] = data.wallets.find_one.money_address.split('@'); - - return { user, domain, full: data.wallets.find_one.money_address }; + return data.wallets.find_one.money_address; }, [data]); const [copiedText, copy] = useCopyToClipboard(); @@ -76,36 +73,43 @@ const WalletDetails: FC<{ id: string }> = ({ id }) => {
- - - Money Address - - - -
- {!!address ? ( - <> -
-
{address.user}
-
-

- {'@' + address.domain} -

- - + {!addresses.length ? null : ( + + + + Money Address + + + + +
+ {addresses.map(a => { + return ( +
+
{a.user}
+ {a.domains.map(d => { + return ( +
+

+ {'@' + d} +

+ +
+ ); + })}
-
- - ) : null} -
- - + ); + })} +
+ + + )}
); diff --git a/src/views/wallet/Settings.tsx b/src/views/wallet/Settings.tsx index 8c6e5fdb..34135755 100644 --- a/src/views/wallet/Settings.tsx +++ b/src/views/wallet/Settings.tsx @@ -102,28 +102,37 @@ export const WalletSettings: FC<{ walletId: string }> = ({ walletId }) => { receive money. - -
- -
- - -
-
+ + {!data?.wallets.find_one.money_address.length ? ( +

+ No money address found. +

+ ) : ( + data.wallets.find_one.money_address.map(a => { + return a.domains.map(d => { + return ( +
+ +
+ + +
+
+ ); + }); + }) + )}