show exchange panel to unauthenticated users
This commit is contained in:
@@ -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 (
|
||||
<div className="w-full">
|
||||
{data.currentUser && (
|
||||
<ExchangePanel
|
||||
balancesRefs={data.currentUser.balance}
|
||||
fiatBalancesRefs={data.currentUser.fiatBalance}
|
||||
/>
|
||||
)}
|
||||
|
||||
<ExchangePanel userRef={data.currentUser} />
|
||||
<ExchangeHistory
|
||||
sellCryptoOrdersRefs={data.sellCryptoOrders}
|
||||
buyCryptoOrdersRefs={data.buyCryptoOrders}
|
||||
|
||||
@@ -5,13 +5,10 @@ import { useFragment, useRelayEnvironment } from "react-relay";
|
||||
import { BigNumber } from "bignumber.js";
|
||||
import cx from "classnames";
|
||||
|
||||
import { useCurrentUser } from "../../../../contexts/UserProvider";
|
||||
import { Unauthenticated } from "../../../../messages/Unauthenticated";
|
||||
import type { ExchangePanel_fiatBalances$key } from "./__generated__/ExchangePanel_fiatBalances.graphql";
|
||||
import type { ExchangePanel_balances$key } from "./__generated__/ExchangePanel_balances.graphql";
|
||||
import { commitCreateSellCryptoOrderMutation } from "./createSellCryptoOrder";
|
||||
import { commitCreateBuyCryptoOrderMutation } from "./createBuyCryptoOrder";
|
||||
import { Input, Button } from "../../../../components";
|
||||
import type { ExchangePanel_user$key } from "./__generated__/ExchangePanel_user.graphql";
|
||||
|
||||
const tabBaseStyles =
|
||||
"w-full text-base font-bold text-black px-4 py-2 focus:ring-blue-500";
|
||||
@@ -20,43 +17,35 @@ const selectedTabStyles =
|
||||
"bg-blue-600 hover:bg-blue-700 rounded-l-frounded-full text-white";
|
||||
|
||||
type Props = {
|
||||
fiatBalancesRefs: ExchangePanel_fiatBalances$key;
|
||||
balancesRefs: ExchangePanel_balances$key;
|
||||
userRef: ExchangePanel_user$key | null;
|
||||
};
|
||||
|
||||
export const ExchangePanel: FC<Props> = ({
|
||||
fiatBalancesRefs,
|
||||
balancesRefs,
|
||||
}) => {
|
||||
const { isAuthenticated } = useCurrentUser();
|
||||
export const ExchangePanel: FC<Props> = ({ userRef }) => {
|
||||
const environment = useRelayEnvironment();
|
||||
const [exchangeOption, setExchangeOption] = useState<"BUY" | "SELL">("BUY");
|
||||
const [cryptoDock, setCryptoDock] = useState<string>("0");
|
||||
const [fiatDock, setFiatDock] = useState<string>("0.00");
|
||||
|
||||
const fiatBalance = useFragment<ExchangePanel_fiatBalances$key>(
|
||||
const user = useFragment<ExchangePanel_user$key>(
|
||||
graphql`
|
||||
fragment ExchangePanel_fiatBalances on FiatBalance {
|
||||
fragment ExchangePanel_user on User {
|
||||
fiatBalance {
|
||||
amountCents
|
||||
}
|
||||
`,
|
||||
fiatBalancesRefs
|
||||
);
|
||||
|
||||
const balance = useFragment<ExchangePanel_balances$key>(
|
||||
graphql`
|
||||
fragment ExchangePanel_balances on Balance {
|
||||
balance {
|
||||
amount
|
||||
}
|
||||
}
|
||||
`,
|
||||
balancesRefs
|
||||
userRef
|
||||
);
|
||||
|
||||
if (!isAuthenticated) return <Unauthenticated />;
|
||||
const balanceAmount = user?.balance?.amount ?? 0;
|
||||
const fiatBalanceAmount = user?.fiatBalance.amountCents ?? 0;
|
||||
|
||||
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<Props> = ({
|
||||
>
|
||||
<span className="mb-2">
|
||||
{exchangeOption === "SELL" ? "CAKE" : "BRL"} disponível:{" "}
|
||||
{exchangeOption === "SELL" ? balance.amount : avaliableFiat}
|
||||
{exchangeOption === "SELL" ? balanceAmount : avaliableFiat}
|
||||
</span>
|
||||
<div className="flex flex-row">
|
||||
{exchangeOption === "BUY" ? (
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
71
app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_user.graphql.ts
generated
Normal file
71
app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/ExchangePanel_user.graphql.ts
generated
Normal file
@@ -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;
|
||||
@@ -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 {
|
||||
fragment ExchangePanel_user on User {
|
||||
fiatBalance {
|
||||
amountCents
|
||||
id
|
||||
}
|
||||
balance {
|
||||
amount
|
||||
id
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -127,38 +118,11 @@ return {
|
||||
"kind": "LinkedField",
|
||||
"name": "currentUser",
|
||||
"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
|
||||
"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;
|
||||
|
||||
Reference in New Issue
Block a user