diff --git a/app/javascript/src/pages/Orders/Exchange/Exchange.tsx b/app/javascript/src/pages/Orders/Exchange/Exchange.tsx index d90f59e..bd4e91b 100644 --- a/app/javascript/src/pages/Orders/Exchange/Exchange.tsx +++ b/app/javascript/src/pages/Orders/Exchange/Exchange.tsx @@ -12,12 +12,7 @@ export const Exchange = () => { graphql` query ExchangeQuery { currentUser { - fiatBalance { - ...ExchangePanel_fiatBalances - } - balance { - ...ExchangePanel_balances - } + ...ExchangePanel_user } buyCryptoOrders { ...ExchangeHistory_buyCryptoOrders @@ -32,13 +27,7 @@ export const Exchange = () => { return (
- {data.currentUser && ( - - )} - + = ({ - fiatBalancesRefs, - balancesRefs, -}) => { - const { isAuthenticated } = useCurrentUser(); +export const ExchangePanel: FC = ({ userRef }) => { const environment = useRelayEnvironment(); const [exchangeOption, setExchangeOption] = useState<"BUY" | "SELL">("BUY"); const [cryptoDock, setCryptoDock] = useState("0"); const [fiatDock, setFiatDock] = useState("0.00"); - const fiatBalance = useFragment( + const user = useFragment( graphql` - fragment ExchangePanel_fiatBalances on FiatBalance { - amountCents + fragment ExchangePanel_user on User { + fiatBalance { + amountCents + } + balance { + amount + } } `, - fiatBalancesRefs + userRef ); - const balance = useFragment( - graphql` - fragment ExchangePanel_balances on Balance { - amount - } - `, - balancesRefs - ); + const balanceAmount = user?.balance?.amount ?? 0; + const fiatBalanceAmount = user?.fiatBalance.amountCents ?? 0; - if (!isAuthenticated) return ; - - const avaliableCrypto = new BigNumber(balance.amount); + const avaliableCrypto = new BigNumber(balanceAmount); const avaliableFiat = ( - fiatBalance.amountCents ? fiatBalance.amountCents / 100 : 0 + fiatBalanceAmount ? fiatBalanceAmount / 100 : 0 ).toFixed(2); const handleSellTabClick = () => { @@ -154,7 +143,7 @@ export const ExchangePanel: FC = ({ > {exchangeOption === "SELL" ? "CAKE" : "BRL"} disponível:{" "} - {exchangeOption === "SELL" ? balance.amount : avaliableFiat} + {exchangeOption === "SELL" ? balanceAmount : avaliableFiat}
{exchangeOption === "BUY" ? ( diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_balances.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_balances.graphql.ts deleted file mode 100644 index 5b92977..0000000 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_balances.graphql.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @ts-nocheck - -import { ReaderFragment } from "relay-runtime"; -import { FragmentRefs } from "relay-runtime"; -export type ExchangePanel_balances = { - readonly amount: string; - readonly " $refType": "ExchangePanel_balances"; -}; -export type ExchangePanel_balances$data = ExchangePanel_balances; -export type ExchangePanel_balances$key = { - readonly " $data"?: ExchangePanel_balances$data; - readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_balances">; -}; - - - -const node: ReaderFragment = { - "argumentDefinitions": [], - "kind": "Fragment", - "metadata": null, - "name": "ExchangePanel_balances", - "selections": [ - { - "alias": null, - "args": null, - "kind": "ScalarField", - "name": "amount", - "storageKey": null - } - ], - "type": "Balance", - "abstractKey": null -}; -(node as any).hash = '99736114264996104eaa4907673d9849'; -export default node; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_fiatBalances.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_fiatBalances.graphql.ts deleted file mode 100644 index a3e688f..0000000 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_fiatBalances.graphql.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -// @ts-nocheck - -import { ReaderFragment } from "relay-runtime"; -import { FragmentRefs } from "relay-runtime"; -export type ExchangePanel_fiatBalances = { - readonly amountCents: number; - readonly " $refType": "ExchangePanel_fiatBalances"; -}; -export type ExchangePanel_fiatBalances$data = ExchangePanel_fiatBalances; -export type ExchangePanel_fiatBalances$key = { - readonly " $data"?: ExchangePanel_fiatBalances$data; - readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_fiatBalances">; -}; - - - -const node: ReaderFragment = { - "argumentDefinitions": [], - "kind": "Fragment", - "metadata": null, - "name": "ExchangePanel_fiatBalances", - "selections": [ - { - "alias": null, - "args": null, - "kind": "ScalarField", - "name": "amountCents", - "storageKey": null - } - ], - "type": "FiatBalance", - "abstractKey": null -}; -(node as any).hash = '9f9bd030f967a665c247facbf641b760'; -export default node; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_user.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_user.graphql.ts new file mode 100644 index 0000000..8a7c3b5 --- /dev/null +++ b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_user.graphql.ts @@ -0,0 +1,71 @@ +/* tslint:disable */ +/* eslint-disable */ +// @ts-nocheck + +import { ReaderFragment } from "relay-runtime"; +import { FragmentRefs } from "relay-runtime"; +export type ExchangePanel_user = { + readonly fiatBalance: { + readonly amountCents: number; + }; + readonly balance: { + readonly amount: string; + }; + readonly " $refType": "ExchangePanel_user"; +}; +export type ExchangePanel_user$data = ExchangePanel_user; +export type ExchangePanel_user$key = { + readonly " $data"?: ExchangePanel_user$data; + readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_user">; +}; + + + +const node: ReaderFragment = { + "argumentDefinitions": [], + "kind": "Fragment", + "metadata": null, + "name": "ExchangePanel_user", + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "FiatBalance", + "kind": "LinkedField", + "name": "fiatBalance", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "amountCents", + "storageKey": null + } + ], + "storageKey": null + }, + { + "alias": null, + "args": null, + "concreteType": "Balance", + "kind": "LinkedField", + "name": "balance", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "amount", + "storageKey": null + } + ], + "storageKey": null + } + ], + "type": "User", + "abstractKey": null +}; +(node as any).hash = '2d9248ccbe47532d3f3ac0f21f02a274'; +export default node; diff --git a/app/javascript/src/pages/Orders/Exchange/__generated__/ExchangeQuery.graphql.ts b/app/javascript/src/pages/Orders/Exchange/__generated__/ExchangeQuery.graphql.ts index 3e1114a..78cfb3f 100644 --- a/app/javascript/src/pages/Orders/Exchange/__generated__/ExchangeQuery.graphql.ts +++ b/app/javascript/src/pages/Orders/Exchange/__generated__/ExchangeQuery.graphql.ts @@ -7,12 +7,7 @@ import { FragmentRefs } from "relay-runtime"; export type ExchangeQueryVariables = {}; export type ExchangeQueryResponse = { readonly currentUser: { - readonly fiatBalance: { - readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_fiatBalances">; - }; - readonly balance: { - readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_balances">; - }; + readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_user">; } | null; readonly buyCryptoOrders: { readonly " $fragmentRefs": FragmentRefs<"ExchangeHistory_buyCryptoOrders">; @@ -31,14 +26,7 @@ export type ExchangeQuery = { /* query ExchangeQuery { currentUser { - fiatBalance { - ...ExchangePanel_fiatBalances - id - } - balance { - ...ExchangePanel_balances - id - } + ...ExchangePanel_user id } buyCryptoOrders { @@ -75,12 +63,15 @@ fragment ExchangeHistory_sellCryptoOrders on SellCryptoOrderConnection { } } -fragment ExchangePanel_balances on Balance { - amount -} - -fragment ExchangePanel_fiatBalances on FiatBalance { - amountCents +fragment ExchangePanel_user on User { + fiatBalance { + amountCents + id + } + balance { + amount + id + } } */ @@ -129,36 +120,9 @@ return { "plural": false, "selections": [ { - "alias": null, "args": null, - "concreteType": "FiatBalance", - "kind": "LinkedField", - "name": "fiatBalance", - "plural": false, - "selections": [ - { - "args": null, - "kind": "FragmentSpread", - "name": "ExchangePanel_fiatBalances" - } - ], - "storageKey": null - }, - { - "alias": null, - "args": null, - "concreteType": "Balance", - "kind": "LinkedField", - "name": "balance", - "plural": false, - "selections": [ - { - "args": null, - "kind": "FragmentSpread", - "name": "ExchangePanel_balances" - } - ], - "storageKey": null + "kind": "FragmentSpread", + "name": "ExchangePanel_user" } ], "storageKey": null @@ -360,14 +324,14 @@ return { ] }, "params": { - "cacheID": "3312f3d7aa6ac4b7051376b61f10c957", + "cacheID": "fdc958a4c6802df3461f7a625f94729c", "id": null, "metadata": {}, "name": "ExchangeQuery", "operationKind": "query", - "text": "query ExchangeQuery {\n currentUser {\n fiatBalance {\n ...ExchangePanel_fiatBalances\n id\n }\n balance {\n ...ExchangePanel_balances\n id\n }\n id\n }\n buyCryptoOrders {\n ...ExchangeHistory_buyCryptoOrders\n }\n sellCryptoOrders {\n ...ExchangeHistory_sellCryptoOrders\n }\n}\n\nfragment ExchangeHistory_buyCryptoOrders on BuyCryptoOrderConnection {\n edges {\n node {\n id\n status\n createdAt\n paidAmountCents\n receivedAmount\n __typename\n }\n }\n}\n\nfragment ExchangeHistory_sellCryptoOrders on SellCryptoOrderConnection {\n edges {\n node {\n id\n status\n paidAmount\n receivedAmountCents\n createdAt\n __typename\n }\n }\n}\n\nfragment ExchangePanel_balances on Balance {\n amount\n}\n\nfragment ExchangePanel_fiatBalances on FiatBalance {\n amountCents\n}\n" + "text": "query ExchangeQuery {\n currentUser {\n ...ExchangePanel_user\n id\n }\n buyCryptoOrders {\n ...ExchangeHistory_buyCryptoOrders\n }\n sellCryptoOrders {\n ...ExchangeHistory_sellCryptoOrders\n }\n}\n\nfragment ExchangeHistory_buyCryptoOrders on BuyCryptoOrderConnection {\n edges {\n node {\n id\n status\n createdAt\n paidAmountCents\n receivedAmount\n __typename\n }\n }\n}\n\nfragment ExchangeHistory_sellCryptoOrders on SellCryptoOrderConnection {\n edges {\n node {\n id\n status\n paidAmount\n receivedAmountCents\n createdAt\n __typename\n }\n }\n}\n\nfragment ExchangePanel_user on User {\n fiatBalance {\n amountCents\n id\n }\n balance {\n amount\n id\n }\n}\n" } }; })(); -(node as any).hash = '85296680bd82d278a1f5d485b8b101f3'; +(node as any).hash = '88aea5fd6077cc7a1b4fe6369c34a4ec'; export default node;