show exchange panel to unauthenticated users
This commit is contained in:
@@ -12,12 +12,7 @@ export const Exchange = () => {
|
|||||||
graphql`
|
graphql`
|
||||||
query ExchangeQuery {
|
query ExchangeQuery {
|
||||||
currentUser {
|
currentUser {
|
||||||
fiatBalance {
|
...ExchangePanel_user
|
||||||
...ExchangePanel_fiatBalances
|
|
||||||
}
|
|
||||||
balance {
|
|
||||||
...ExchangePanel_balances
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buyCryptoOrders {
|
buyCryptoOrders {
|
||||||
...ExchangeHistory_buyCryptoOrders
|
...ExchangeHistory_buyCryptoOrders
|
||||||
@@ -32,13 +27,7 @@ export const Exchange = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
{data.currentUser && (
|
<ExchangePanel userRef={data.currentUser} />
|
||||||
<ExchangePanel
|
|
||||||
balancesRefs={data.currentUser.balance}
|
|
||||||
fiatBalancesRefs={data.currentUser.fiatBalance}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ExchangeHistory
|
<ExchangeHistory
|
||||||
sellCryptoOrdersRefs={data.sellCryptoOrders}
|
sellCryptoOrdersRefs={data.sellCryptoOrders}
|
||||||
buyCryptoOrdersRefs={data.buyCryptoOrders}
|
buyCryptoOrdersRefs={data.buyCryptoOrders}
|
||||||
|
|||||||
@@ -5,13 +5,10 @@ import { useFragment, useRelayEnvironment } from "react-relay";
|
|||||||
import { BigNumber } from "bignumber.js";
|
import { BigNumber } from "bignumber.js";
|
||||||
import cx from "classnames";
|
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 { commitCreateSellCryptoOrderMutation } from "./createSellCryptoOrder";
|
||||||
import { commitCreateBuyCryptoOrderMutation } from "./createBuyCryptoOrder";
|
import { commitCreateBuyCryptoOrderMutation } from "./createBuyCryptoOrder";
|
||||||
import { Input, Button } from "../../../../components";
|
import { Input, Button } from "../../../../components";
|
||||||
|
import type { ExchangePanel_user$key } from "./__generated__/ExchangePanel_user.graphql";
|
||||||
|
|
||||||
const tabBaseStyles =
|
const tabBaseStyles =
|
||||||
"w-full text-base font-bold text-black px-4 py-2 focus:ring-blue-500";
|
"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";
|
"bg-blue-600 hover:bg-blue-700 rounded-l-frounded-full text-white";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
fiatBalancesRefs: ExchangePanel_fiatBalances$key;
|
userRef: ExchangePanel_user$key | null;
|
||||||
balancesRefs: ExchangePanel_balances$key;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ExchangePanel: FC<Props> = ({
|
export const ExchangePanel: FC<Props> = ({ userRef }) => {
|
||||||
fiatBalancesRefs,
|
|
||||||
balancesRefs,
|
|
||||||
}) => {
|
|
||||||
const { isAuthenticated } = useCurrentUser();
|
|
||||||
const environment = useRelayEnvironment();
|
const environment = useRelayEnvironment();
|
||||||
const [exchangeOption, setExchangeOption] = useState<"BUY" | "SELL">("BUY");
|
const [exchangeOption, setExchangeOption] = useState<"BUY" | "SELL">("BUY");
|
||||||
const [cryptoDock, setCryptoDock] = useState<string>("0");
|
const [cryptoDock, setCryptoDock] = useState<string>("0");
|
||||||
const [fiatDock, setFiatDock] = useState<string>("0.00");
|
const [fiatDock, setFiatDock] = useState<string>("0.00");
|
||||||
|
|
||||||
const fiatBalance = useFragment<ExchangePanel_fiatBalances$key>(
|
const user = useFragment<ExchangePanel_user$key>(
|
||||||
graphql`
|
graphql`
|
||||||
fragment ExchangePanel_fiatBalances on FiatBalance {
|
fragment ExchangePanel_user on User {
|
||||||
amountCents
|
fiatBalance {
|
||||||
|
amountCents
|
||||||
|
}
|
||||||
|
balance {
|
||||||
|
amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
fiatBalancesRefs
|
userRef
|
||||||
);
|
);
|
||||||
|
|
||||||
const balance = useFragment<ExchangePanel_balances$key>(
|
const balanceAmount = user?.balance?.amount ?? 0;
|
||||||
graphql`
|
const fiatBalanceAmount = user?.fiatBalance.amountCents ?? 0;
|
||||||
fragment ExchangePanel_balances on Balance {
|
|
||||||
amount
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
balancesRefs
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!isAuthenticated) return <Unauthenticated />;
|
const avaliableCrypto = new BigNumber(balanceAmount);
|
||||||
|
|
||||||
const avaliableCrypto = new BigNumber(balance.amount);
|
|
||||||
const avaliableFiat = (
|
const avaliableFiat = (
|
||||||
fiatBalance.amountCents ? fiatBalance.amountCents / 100 : 0
|
fiatBalanceAmount ? fiatBalanceAmount / 100 : 0
|
||||||
).toFixed(2);
|
).toFixed(2);
|
||||||
|
|
||||||
const handleSellTabClick = () => {
|
const handleSellTabClick = () => {
|
||||||
@@ -154,7 +143,7 @@ export const ExchangePanel: FC<Props> = ({
|
|||||||
>
|
>
|
||||||
<span className="mb-2">
|
<span className="mb-2">
|
||||||
{exchangeOption === "SELL" ? "CAKE" : "BRL"} disponível:{" "}
|
{exchangeOption === "SELL" ? "CAKE" : "BRL"} disponível:{" "}
|
||||||
{exchangeOption === "SELL" ? balance.amount : avaliableFiat}
|
{exchangeOption === "SELL" ? balanceAmount : avaliableFiat}
|
||||||
</span>
|
</span>
|
||||||
<div className="flex flex-row">
|
<div className="flex flex-row">
|
||||||
{exchangeOption === "BUY" ? (
|
{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 ExchangeQueryVariables = {};
|
||||||
export type ExchangeQueryResponse = {
|
export type ExchangeQueryResponse = {
|
||||||
readonly currentUser: {
|
readonly currentUser: {
|
||||||
readonly fiatBalance: {
|
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_user">;
|
||||||
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_fiatBalances">;
|
|
||||||
};
|
|
||||||
readonly balance: {
|
|
||||||
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_balances">;
|
|
||||||
};
|
|
||||||
} | null;
|
} | null;
|
||||||
readonly buyCryptoOrders: {
|
readonly buyCryptoOrders: {
|
||||||
readonly " $fragmentRefs": FragmentRefs<"ExchangeHistory_buyCryptoOrders">;
|
readonly " $fragmentRefs": FragmentRefs<"ExchangeHistory_buyCryptoOrders">;
|
||||||
@@ -31,14 +26,7 @@ export type ExchangeQuery = {
|
|||||||
/*
|
/*
|
||||||
query ExchangeQuery {
|
query ExchangeQuery {
|
||||||
currentUser {
|
currentUser {
|
||||||
fiatBalance {
|
...ExchangePanel_user
|
||||||
...ExchangePanel_fiatBalances
|
|
||||||
id
|
|
||||||
}
|
|
||||||
balance {
|
|
||||||
...ExchangePanel_balances
|
|
||||||
id
|
|
||||||
}
|
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
buyCryptoOrders {
|
buyCryptoOrders {
|
||||||
@@ -75,12 +63,15 @@ fragment ExchangeHistory_sellCryptoOrders on SellCryptoOrderConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment ExchangePanel_balances on Balance {
|
fragment ExchangePanel_user on User {
|
||||||
amount
|
fiatBalance {
|
||||||
}
|
amountCents
|
||||||
|
id
|
||||||
fragment ExchangePanel_fiatBalances on FiatBalance {
|
}
|
||||||
amountCents
|
balance {
|
||||||
|
amount
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -129,36 +120,9 @@ return {
|
|||||||
"plural": false,
|
"plural": false,
|
||||||
"selections": [
|
"selections": [
|
||||||
{
|
{
|
||||||
"alias": null,
|
|
||||||
"args": null,
|
"args": null,
|
||||||
"concreteType": "FiatBalance",
|
"kind": "FragmentSpread",
|
||||||
"kind": "LinkedField",
|
"name": "ExchangePanel_user"
|
||||||
"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
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"storageKey": null
|
"storageKey": null
|
||||||
@@ -360,14 +324,14 @@ return {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"params": {
|
"params": {
|
||||||
"cacheID": "3312f3d7aa6ac4b7051376b61f10c957",
|
"cacheID": "fdc958a4c6802df3461f7a625f94729c",
|
||||||
"id": null,
|
"id": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"name": "ExchangeQuery",
|
"name": "ExchangeQuery",
|
||||||
"operationKind": "query",
|
"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;
|
export default node;
|
||||||
|
|||||||
Reference in New Issue
Block a user