remove currency model and all references

This commit is contained in:
João Geonizeli
2021-08-28 01:29:07 -03:00
parent 31078f87ae
commit 0d10e86526
74 changed files with 665 additions and 1561 deletions

View File

@@ -0,0 +1,71 @@
import { graphql } from "babel-plugin-relay/macro";
import type { FC } from "react";
import React from "react";
import { useFragment } from "react-relay";
import { getCurrencyLogo } from "../../utils/getCurrencyLogo";
import type { Balance_balance$key } from "./__generated__/Balance_balance.graphql";
type Props = {
balancesRef: Balance_balance$key;
};
export const Balance: FC<Props> = ({ balancesRef }) => {
const node = useFragment<Balance_balance$key>(
graphql`
fragment Balance_balance on Balance {
amount
}
`,
balancesRef
);
if (!node) return null;
return (
<div className="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
<div className="inline-block min-w-full shadow rounded-lg overflow-hidden">
<table className="min-w-full leading-normal">
<thead>
<tr>
<th
scope="col"
className="px-5 py-3 bg-white border-b border-gray-200 text-gray-800 text-left text-sm uppercase font-normal"
>
Moeda
</th>
<th
scope="col"
className="px-5 py-3 bg-white border-b border-gray-200 text-gray-800 text-left text-sm uppercase font-normal"
>
Saldo
</th>
</tr>
</thead>
<tbody>
<tr>
<td className="px-5 py-5 border-b border-gray-200 bg-white text-sm">
<div className="flex items-center">
<div className="flex-shrink-0">
<img
alt="CAKE icon"
src={getCurrencyLogo("CAKE")}
className="mx-auto object-cover rounded-full h-10 w-10 "
/>
</div>
<div className="ml-3">
<p className="text-gray-900 whitespace-no-wrap">CAKE</p>
</div>
</div>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white text-sm">
<p className="text-gray-900 whitespace-no-wrap">
{node.amount}
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
);
};

View File

@@ -1,85 +0,0 @@
import { graphql } from "babel-plugin-relay/macro";
import type { FC } from "react";
import React from "react";
import { useFragment } from "react-relay";
import { getCurrencyLogo } from "../../utils/getCurrencyLogo";
import type { Balances_balances$key } from "./__generated__/Balances_balances.graphql";
type Props = {
balancesRef: Balances_balances$key;
};
export const Balances: FC<Props> = ({ balancesRef }) => {
const { edges } = useFragment<Balances_balances$key>(
graphql`
fragment Balances_balances on BalanceConnection {
edges {
node {
id
amount
currency {
name
}
}
}
}
`,
balancesRef
);
if (!edges.length) return null;
return (
<div className="-mx-4 sm:-mx-8 px-4 sm:px-8 py-4 overflow-x-auto">
<div className="inline-block min-w-full shadow rounded-lg overflow-hidden">
<table className="min-w-full leading-normal">
<thead>
<tr>
<th
scope="col"
className="px-5 py-3 bg-white border-b border-gray-200 text-gray-800 text-left text-sm uppercase font-normal"
>
Moeda
</th>
<th
scope="col"
className="px-5 py-3 bg-white border-b border-gray-200 text-gray-800 text-left text-sm uppercase font-normal"
>
Saldo
</th>
</tr>
</thead>
<tbody>
{edges.map(({ node }) => {
return (
<tr key={node.id}>
<td className="px-5 py-5 border-b border-gray-200 bg-white text-sm">
<div className="flex items-center">
<div className="flex-shrink-0">
<img
alt={`${node.currency.name} icon`}
src={getCurrencyLogo(node.currency.name)}
className="mx-auto object-cover rounded-full h-10 w-10 "
/>
</div>
<div className="ml-3">
<p className="text-gray-900 whitespace-no-wrap">
{node.currency.name}
</p>
</div>
</div>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white text-sm">
<p className="text-gray-900 whitespace-no-wrap">
{node.amount}
</p>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
);
};

View File

@@ -3,31 +3,25 @@ import type { FC } from "react";
import React from "react";
import { useFragment } from "react-relay";
import type { FiatBalances_fiatBalances$key } from "./__generated__/FiatBalances_fiatBalances.graphql";
import type { FiatBalance_fiatBalance$key } from "./__generated__/FiatBalance_fiatBalance.graphql";
type Props = {
fiatBalancesRef: FiatBalances_fiatBalances$key;
fiatBalancesRef: FiatBalance_fiatBalance$key;
};
export const FiatBalances: FC<Props> = ({ fiatBalancesRef }) => {
const { edges } = useFragment<FiatBalances_fiatBalances$key>(
export const FiatBalance: FC<Props> = ({ fiatBalancesRef }) => {
const userFiatBalance = useFragment<FiatBalance_fiatBalance$key>(
graphql`
fragment FiatBalances_fiatBalances on FiatBalanceConnection {
edges {
node {
amountCents
amountCurrency
}
}
fragment FiatBalance_fiatBalance on FiatBalance {
amountCents
amountCurrency
}
`,
fiatBalancesRef
);
if (!edges.length) return null;
if (!userFiatBalance) return null;
const [firstResult] = edges;
const { amountCents, amountCurrency } = firstResult.node;
const { amountCents, amountCurrency } = userFiatBalance;
const amount = (amountCents ? amountCents / 100 : 0).toFixed(2);

View File

@@ -5,34 +5,36 @@ import { useLazyLoadQuery } from "react-relay";
import { useCurrentUser } from "../../contexts/UserProvider";
import { Messages } from "../../messages";
import { Balances } from "./Balances";
import { FiatBalances } from "./FiatBalances";
import { Balance } from "./Balance";
import { FiatBalance } from "./FiatBalance";
import type { WalletQuery } from "./__generated__/WalletQuery.graphql";
export const Wallet: FC = () => {
const { isAuthenticated } = useCurrentUser();
const { fiatBalances, balances } = useLazyLoadQuery<WalletQuery>(
const { currentUser } = useLazyLoadQuery<WalletQuery>(
graphql`
query WalletQuery {
fiatBalances {
...FiatBalances_fiatBalances
}
balances {
...Balances_balances
currentUser {
fiatBalance {
...FiatBalance_fiatBalance
}
balance {
...Balance_balance
}
}
}
`,
{}
);
if (!isAuthenticated) return <Messages.Unauthenticated />;
if (!isAuthenticated || !currentUser) return <Messages.Unauthenticated />;
return (
<div className="flex flex-col h-full w-full overflow-x-hidden">
<div className="container mx-auto px-4 sm:px-8 max-w-3xl">
<div className="py-8">
<FiatBalances fiatBalancesRef={fiatBalances} />
<Balances balancesRef={balances} />
<FiatBalance fiatBalancesRef={currentUser.fiatBalance} />
<Balance balancesRef={currentUser.balance} />
</div>
</div>
</div>

View File

@@ -0,0 +1,37 @@
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type Balance_balance = {
readonly amount: string;
readonly " $refType": "Balance_balance";
};
export type Balance_balance$data = Balance_balance;
export type Balance_balance$key = {
readonly " $data"?: Balance_balance$data;
readonly " $fragmentRefs": FragmentRefs<"Balance_balance">;
};
const node: ReaderFragment = {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "Balance_balance",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amount",
"storageKey": null
}
],
"type": "Balance",
"abstractKey": null
};
(node as any).hash = '3f420063f1e6ebfcd91bd05b7bbb492a';
export default node;

View File

@@ -1,92 +0,0 @@
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type Balances_balances = {
readonly edges: ReadonlyArray<{
readonly node: {
readonly id: string;
readonly amount: string;
readonly currency: {
readonly name: string;
};
};
}>;
readonly " $refType": "Balances_balances";
};
export type Balances_balances$data = Balances_balances;
export type Balances_balances$key = {
readonly " $data"?: Balances_balances$data;
readonly " $fragmentRefs": FragmentRefs<"Balances_balances">;
};
const node: ReaderFragment = {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "Balances_balances",
"selections": [
{
"alias": null,
"args": null,
"concreteType": "BalanceEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Balance",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amount",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "Currency",
"kind": "LinkedField",
"name": "currency",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
],
"type": "BalanceConnection",
"abstractKey": null
};
(node as any).hash = 'f42e01739ec72a194e05843169435d96';
export default node;

View File

@@ -0,0 +1,45 @@
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type FiatBalance_fiatBalance = {
readonly amountCents: number;
readonly amountCurrency: string;
readonly " $refType": "FiatBalance_fiatBalance";
};
export type FiatBalance_fiatBalance$data = FiatBalance_fiatBalance;
export type FiatBalance_fiatBalance$key = {
readonly " $data"?: FiatBalance_fiatBalance$data;
readonly " $fragmentRefs": FragmentRefs<"FiatBalance_fiatBalance">;
};
const node: ReaderFragment = {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "FiatBalance_fiatBalance",
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCents",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCurrency",
"storageKey": null
}
],
"type": "FiatBalance",
"abstractKey": null
};
(node as any).hash = 'dc28e4dca104c7d25465a30412661af2';
export default node;

View File

@@ -1,71 +0,0 @@
/* tslint:disable */
/* eslint-disable */
// @ts-nocheck
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type FiatBalances_fiatBalances = {
readonly edges: ReadonlyArray<{
readonly node: {
readonly amountCents: number;
readonly amountCurrency: string;
};
}>;
readonly " $refType": "FiatBalances_fiatBalances";
};
export type FiatBalances_fiatBalances$data = FiatBalances_fiatBalances;
export type FiatBalances_fiatBalances$key = {
readonly " $data"?: FiatBalances_fiatBalances$data;
readonly " $fragmentRefs": FragmentRefs<"FiatBalances_fiatBalances">;
};
const node: ReaderFragment = {
"argumentDefinitions": [],
"kind": "Fragment",
"metadata": null,
"name": "FiatBalances_fiatBalances",
"selections": [
{
"alias": null,
"args": null,
"concreteType": "FiatBalanceEdge",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "FiatBalance",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCents",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCurrency",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
],
"type": "FiatBalanceConnection",
"abstractKey": null
};
(node as any).hash = 'a1454d1a8afc3cffb17cbfbe9e3555f7';
export default node;

View File

@@ -6,12 +6,14 @@ import { ConcreteRequest } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type WalletQueryVariables = {};
export type WalletQueryResponse = {
readonly fiatBalances: {
readonly " $fragmentRefs": FragmentRefs<"FiatBalances_fiatBalances">;
};
readonly balances: {
readonly " $fragmentRefs": FragmentRefs<"Balances_balances">;
};
readonly currentUser: {
readonly fiatBalance: {
readonly " $fragmentRefs": FragmentRefs<"FiatBalance_fiatBalance">;
};
readonly balance: {
readonly " $fragmentRefs": FragmentRefs<"Balance_balance">;
};
} | null;
};
export type WalletQuery = {
readonly response: WalletQueryResponse;
@@ -22,35 +24,26 @@ export type WalletQuery = {
/*
query WalletQuery {
fiatBalances {
...FiatBalances_fiatBalances
}
balances {
...Balances_balances
currentUser {
fiatBalance {
...FiatBalance_fiatBalance
id
}
balance {
...Balance_balance
id
}
id
}
}
fragment Balances_balances on BalanceConnection {
edges {
node {
id
amount
currency {
name
id
}
}
}
fragment Balance_balance on Balance {
amount
}
fragment FiatBalances_fiatBalances on FiatBalanceConnection {
edges {
node {
amountCents
amountCurrency
id
}
}
fragment FiatBalance_fiatBalance on FiatBalance {
amountCents
amountCurrency
}
*/
@@ -72,31 +65,42 @@ return {
{
"alias": null,
"args": null,
"concreteType": "FiatBalanceConnection",
"concreteType": "User",
"kind": "LinkedField",
"name": "fiatBalances",
"name": "currentUser",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "FragmentSpread",
"name": "FiatBalances_fiatBalances"
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "BalanceConnection",
"kind": "LinkedField",
"name": "balances",
"plural": false,
"selections": [
"concreteType": "FiatBalance",
"kind": "LinkedField",
"name": "fiatBalance",
"plural": false,
"selections": [
{
"args": null,
"kind": "FragmentSpread",
"name": "FiatBalance_fiatBalance"
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "FragmentSpread",
"name": "Balances_balances"
"concreteType": "Balance",
"kind": "LinkedField",
"name": "balance",
"plural": false,
"selections": [
{
"args": null,
"kind": "FragmentSpread",
"name": "Balance_balance"
}
],
"storageKey": null
}
],
"storageKey": null
@@ -114,122 +118,71 @@ return {
{
"alias": null,
"args": null,
"concreteType": "FiatBalanceConnection",
"concreteType": "User",
"kind": "LinkedField",
"name": "fiatBalances",
"name": "currentUser",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "FiatBalanceEdge",
"concreteType": "FiatBalance",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"name": "fiatBalance",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "FiatBalance",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCents",
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCurrency",
"storageKey": null
},
(v0/*: any*/)
],
"kind": "ScalarField",
"name": "amountCents",
"storageKey": null
}
},
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amountCurrency",
"storageKey": null
},
(v0/*: any*/)
],
"storageKey": null
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "BalanceConnection",
"kind": "LinkedField",
"name": "balances",
"plural": false,
"selections": [
},
{
"alias": null,
"args": null,
"concreteType": "BalanceEdge",
"concreteType": "Balance",
"kind": "LinkedField",
"name": "edges",
"plural": true,
"name": "balance",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"concreteType": "Balance",
"kind": "LinkedField",
"name": "node",
"plural": false,
"selections": [
(v0/*: any*/),
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amount",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "Currency",
"kind": "LinkedField",
"name": "currency",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
(v0/*: any*/)
],
"storageKey": null
}
],
"kind": "ScalarField",
"name": "amount",
"storageKey": null
}
},
(v0/*: any*/)
],
"storageKey": null
}
},
(v0/*: any*/)
],
"storageKey": null
}
]
},
"params": {
"cacheID": "6acfc80d1e8d7c882a03e25cc7902d72",
"cacheID": "d0537f2712255befa46df80db6c7246b",
"id": null,
"metadata": {},
"name": "WalletQuery",
"operationKind": "query",
"text": "query WalletQuery {\n fiatBalances {\n ...FiatBalances_fiatBalances\n }\n balances {\n ...Balances_balances\n }\n}\n\nfragment Balances_balances on BalanceConnection {\n edges {\n node {\n id\n amount\n currency {\n name\n id\n }\n }\n }\n}\n\nfragment FiatBalances_fiatBalances on FiatBalanceConnection {\n edges {\n node {\n amountCents\n amountCurrency\n id\n }\n }\n}\n"
"text": "query WalletQuery {\n currentUser {\n fiatBalance {\n ...FiatBalance_fiatBalance\n id\n }\n balance {\n ...Balance_balance\n id\n }\n id\n }\n}\n\nfragment Balance_balance on Balance {\n amount\n}\n\nfragment FiatBalance_fiatBalance on FiatBalance {\n amountCents\n amountCurrency\n}\n"
}
};
})();
(node as any).hash = '855efce679c691a77938b64376a1a805';
(node as any).hash = '61fbc56a1e87c83a8a0a4460c231be53';
export default node;