Skip to content

Commit

Permalink
chore: swap queries
Browse files Browse the repository at this point in the history
  • Loading branch information
apotdevin committed Jun 27, 2024
1 parent d0bd0e5 commit 06408a7
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 69 deletions.
115 changes: 115 additions & 0 deletions src/graphql/queries/__generated__/swaps.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions src/graphql/queries/__generated__/wallet.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions src/graphql/queries/swaps.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
`;
12 changes: 10 additions & 2 deletions src/graphql/queries/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const GetWalletDetails = gql`
find_one(id: $id) {
id
name
money_address
money_address {
id
user
domains
}
details {
id
type
Expand All @@ -42,7 +46,11 @@ export const GetWallet = gql`
find_one(id: $id) {
id
name
money_address
money_address {
id
user
domains
}
details {
id
type
Expand Down
26 changes: 20 additions & 6 deletions src/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,20 @@ export type LoginInput = {
master_password_hash: Scalars['String']['input'];
};

export type MoneyAddress = {
__typename?: 'MoneyAddress';
domains: Array<Scalars['String']['output']>;
id: Scalars['String']['output'];
user: Scalars['String']['output'];
};

export type Mutation = {
__typename?: 'Mutation';
checkPassword: Scalars['Boolean']['output'];
contacts: ContactMutations;
login: NewAccount;
logout: Scalars['Boolean']['output'];
pay: PayMutations;
payInvoice: Scalars['Boolean']['output'];
refreshToken: RefreshToken;
signUp: NewAccount;
wallets: WalletMutations;
Expand All @@ -210,10 +216,6 @@ export type MutationPayArgs = {
input: PayInput;
};

export type MutationPayInvoiceArgs = {
invoice: Scalars['String']['input'];
};

export type MutationSignUpArgs = {
input: SignUpInput;
};
Expand Down Expand Up @@ -328,6 +330,11 @@ export type SignUpInput = {
wallet?: InputMaybe<CreateWalletInput>;
};

export type SimpleSwap = {
__typename?: 'SimpleSwap';
id: Scalars['String']['output'];
};

export type SimpleWallet = {
__typename?: 'SimpleWallet';
accounts: Array<SimpleWalletAccount>;
Expand Down Expand Up @@ -361,9 +368,10 @@ export type Wallet = {
contacts: WalletContacts;
details: WalletDetails;
id: Scalars['String']['output'];
money_address?: Maybe<Scalars['String']['output']>;
money_address: Array<MoneyAddress>;
name: Scalars['String']['output'];
secp256k1_key_pair: Secp256k1KeyPair;
swaps: WalletSwaps;
};

export type WalletAccount = {
Expand Down Expand Up @@ -441,6 +449,12 @@ export type WalletQueriesFind_OneArgs = {
id: Scalars['String']['input'];
};

export type WalletSwaps = {
__typename?: 'WalletSwaps';
find_many: Array<SimpleSwap>;
id: Scalars['String']['output'];
};

export enum WalletType {
ClientGenerated = 'CLIENT_GENERATED',
}
74 changes: 39 additions & 35 deletions src/views/app/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -76,36 +73,43 @@ const WalletDetails: FC<{ id: string }> = ({ id }) => {
</div>
</div>
<div className="md:flex">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Money Address</CardTitle>
<Handshake className={'h-4 w-4 text-muted-foreground'} />
</CardHeader>
<CardContent>
<div className="flex items-center justify-between gap-2">
{!!address ? (
<>
<div>
<div className="text-2xl font-bold">{address.user}</div>
<div className="flex gap-1">
<p className="text-xs text-muted-foreground">
{'@' + address.domain}
</p>

<button onClick={() => copy(address.full)}>
{copiedText ? (
<CopyCheck className="size-3" color={'green'} />
) : (
<Copy className="size-3" />
)}
</button>
{!addresses.length ? null : (
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">
Money Address
</CardTitle>
<Handshake className={'h-4 w-4 text-muted-foreground'} />
</CardHeader>
<CardContent>
<div className="flex items-center justify-between gap-2">
{addresses.map(a => {
return (
<div key={a.id}>
<div className="text-2xl font-bold">{a.user}</div>
{a.domains.map(d => {
return (
<div className="flex gap-1" key={d}>
<p className="text-xs text-muted-foreground">
{'@' + d}
</p>
<button onClick={() => copy(`${a.user}@${d}`)}>
{copiedText ? (
<CopyCheck className="size-3" color={'green'} />
) : (
<Copy className="size-3" />
)}
</button>
</div>
);
})}
</div>
</div>
</>
) : null}
</div>
</CardContent>
</Card>
);
})}
</div>
</CardContent>
</Card>
)}
</div>
</div>
);
Expand Down
Loading

0 comments on commit 06408a7

Please sign in to comment.