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

@@ -1,8 +0,0 @@
# frozen_string_literal: true
module Admin
class CurrenciesController < Admin::ApplicationController
def valid_action?(name, resource = resource_class)
["new", "edit", "destroy"].exclude?(name.to_s) && super
end
end
end

View File

@@ -10,7 +10,6 @@ class BalanceDashboard < Administrate::BaseDashboard
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
user: Field::BelongsTo,
currency: Field::BelongsTo,
id: Field::Number,
amount: Field::String.with_options(searchable: false),
created_at: Field::DateTime,
@@ -22,16 +21,16 @@ class BalanceDashboard < Administrate::BaseDashboard
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [:user, :currency, :id, :amount].freeze
COLLECTION_ATTRIBUTES = [:user, :id, :amount].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [:user, :currency, :id, :amount, :created_at, :updated_at].freeze
SHOW_PAGE_ATTRIBUTES = [:user, :id, :amount, :created_at, :updated_at].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [:user, :currency, :amount].freeze
FORM_ATTRIBUTES = [:user, :amount].freeze
# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search

View File

@@ -10,7 +10,6 @@ class BuyCryptoOrderDashboard < Administrate::BaseDashboard
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
user: Field::BelongsTo,
currency: Field::BelongsTo,
id: Field::Number,
status: Field::Enumerize,
paid_amount_cents: Field::Number,
@@ -24,17 +23,16 @@ class BuyCryptoOrderDashboard < Administrate::BaseDashboard
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [:user, :currency, :id, :status].freeze
COLLECTION_ATTRIBUTES = [:user, :id, :status].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [:user, :currency, :id, :status, :paid_amount_cents, :received_amount, :created_at,
:updated_at,].freeze
SHOW_PAGE_ATTRIBUTES = [:user, :id, :status, :paid_amount_cents, :received_amount, :created_at, :updated_at].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [:user, :currency, :status, :paid_amount_cents, :received_amount].freeze
FORM_ATTRIBUTES = [:user, :status, :paid_amount_cents, :received_amount].freeze
# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search

View File

@@ -1,52 +0,0 @@
# frozen_string_literal: true
require "administrate/base_dashboard"
class CurrencyDashboard < Administrate::BaseDashboard
# ATTRIBUTE_TYPES
# a hash that describes the type of each of the model's fields.
#
# Each different type represents an Administrate::Field object,
# which determines how the attribute is displayed
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
id: Field::Number,
name: Field::String,
created_at: Field::DateTime,
updated_at: Field::DateTime,
}.freeze
# COLLECTION_ATTRIBUTES
# an array of attributes that will be displayed on the model's index page.
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [:id, :name, :created_at, :updated_at].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [:id, :name, :created_at, :updated_at].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [:name].freeze
# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search
# field of the dashboard.
#
# For example to add an option to search for open resources by typing "open:"
# in the search field:
#
# COLLECTION_FILTERS = {
# open: ->(resources) { resources.where(open: true) }
# }.freeze
COLLECTION_FILTERS = {}.freeze
# Overwrite this method to customize how currencies are displayed
# across all pages of the admin dashboard.
#
def display_resource(currency)
currency.name
end
end

View File

@@ -10,7 +10,6 @@ class SellCryptoOrderDashboard < Administrate::BaseDashboard
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
user: Field::BelongsTo,
currency: Field::BelongsTo,
id: Field::Number,
status: Field::Enumerize,
paid_amount: Field::String.with_options(searchable: false),
@@ -24,17 +23,17 @@ class SellCryptoOrderDashboard < Administrate::BaseDashboard
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [:user, :currency, :id, :status].freeze
COLLECTION_ATTRIBUTES = [:user, :id, :status].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [:user, :currency, :id, :status, :paid_amount, :received_amount_cents, :created_at,
SHOW_PAGE_ATTRIBUTES = [:user, :id, :status, :paid_amount, :received_amount_cents, :created_at,
:updated_at,].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [:user, :currency, :status, :paid_amount, :received_amount_cents].freeze
FORM_ATTRIBUTES = [:user, :status, :paid_amount, :received_amount_cents].freeze
# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search

View File

@@ -10,7 +10,6 @@ class StakeOrderDashboard < Administrate::BaseDashboard
# on pages throughout the dashboard.
ATTRIBUTE_TYPES = {
user: Field::BelongsTo,
currency: Field::BelongsTo,
id: Field::Number,
pool_name: Field::String,
status: Field::Enumerize,
@@ -24,16 +23,16 @@ class StakeOrderDashboard < Administrate::BaseDashboard
#
# By default, it's limited to four items to reduce clutter on index pages.
# Feel free to add, remove, or rearrange items.
COLLECTION_ATTRIBUTES = [:user, :currency, :id, :pool_name].freeze
COLLECTION_ATTRIBUTES = [:user, :id, :pool_name].freeze
# SHOW_PAGE_ATTRIBUTES
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = [:user, :currency, :id, :pool_name, :status, :amount, :created_at, :updated_at].freeze
SHOW_PAGE_ATTRIBUTES = [:user, :id, :pool_name, :status, :amount, :created_at, :updated_at].freeze
# FORM_ATTRIBUTES
# an array of attributes that will be displayed
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = [:user, :currency, :pool_name, :status, :amount].freeze
FORM_ATTRIBUTES = [:user, :pool_name, :status, :amount].freeze
# COLLECTION_FILTERS
# a hash that defines filters that can be used while searching via the search

View File

@@ -1,7 +1,6 @@
# frozen_string_literal: true
module Inputs
class CreateBuyCryptoOrderAttributesInput < Types::BaseInputObject
argument :currency_id, ID, required: true
argument :amount_cents, Integer, "Amount to be paid", required: true
end
end

View File

@@ -1,7 +1,6 @@
# frozen_string_literal: true
module Inputs
class CreateSellCryptoOrderAttributesInput < Types::BaseInputObject
argument :currency_id, ID, required: true
argument :amount, String, "Amount to be paid", required: true
end
end

View File

@@ -6,8 +6,6 @@ module Mutations
argument :order, Inputs::CreateBuyCryptoOrderAttributesInput, required: true
def resolve(order:)
currency_id = decode_id(order[:currency_id])
ActiveRecord::Base.transaction do
current_user
.fiat_balance
@@ -15,7 +13,6 @@ module Mutations
record = BuyCryptoOrder.create!(
paid_amount_cents: order[:amount_cents],
currency_id: currency_id,
user_id: current_user.id,
)

View File

@@ -6,18 +6,15 @@ module Mutations
argument :order, Inputs::CreateSellCryptoOrderAttributesInput, required: true
def resolve(order:)
currency_id = decode_id(order[:currency_id])
amount = BigDecimal(order[:amount])
ActiveRecord::Base.transaction do
current_user
.balances
.find_by!(currency_id: currency_id)
.balance
.withdrawal!(amount)
record = SellCryptoOrder.create!(
paid_amount: amount,
currency_id: currency_id,
user_id: current_user.id,
)

View File

@@ -6,18 +6,15 @@ module Mutations
argument :order, Inputs::CreateStakeOrderAttributesInput, required: true
def resolve(order:)
currency_id = Currency.find_by!(name: "CAKE").id
amount = BigDecimal(order[:amount])
ActiveRecord::Base.transaction do
current_user
.balances
.find_by!(currency_id: currency_id)
.balance
.withdrawal!(amount)
record = StakeOrder.create!(
amount: amount,
currency_id: currency_id,
pool_name: order[:pool_name],
user_id: current_user.id,
)

View File

@@ -6,14 +6,12 @@ module Mutations
argument :order, Inputs::CreateStakeOrderAttributesInput, required: true
def resolve(order:)
currency_id = Currency.find_by!(name: "CAKE").id
amount = -BigDecimal(order[:amount])
ActiveRecord::Base.transaction do
record = StakeOrder.find_or_initialize_by(
pool_name: order[:pool_name],
user_id: current_user.id,
currency_id: currency_id,
status: :processing
)

View File

@@ -8,10 +8,5 @@ module Types
field :id, ID, null: false
field :amount, String, null: false
field :currency, CurrencyType, null: false
def currency
dataloader.with(Dataloader::Source, Currency).load(object.currency_id)
end
end
end

View File

@@ -7,12 +7,6 @@ module Types
graphql_name "BuyCryptoOrder"
field :id, ID, null: false
field :currency, CurrencyType, null: false
def currency
dataloader.with(Dataloader::Source, Currency).load(object.currency_id)
end
field :status, ProcessStatusEnum, null: false
field :paid_amount_cents, Integer, null: false
field :received_amount, String, null: true

View File

@@ -1,12 +0,0 @@
# frozen_string_literal: true
module Types
class CurrencyType < Types::BaseObject
implements GraphQL::Types::Relay::Node
global_id_field :id
graphql_name "Currency"
field :id, ID, null: false
field :name, String, null: false
end
end

View File

@@ -10,16 +10,6 @@ module Types
context[:current_user]
end
field :balances, BalanceType.connection_type, null: false
def balances
Pundit.policy_scope(current_user, Balance)
end
field :fiat_balances, FiatBalanceType.connection_type, null: false
def fiat_balances
Pundit.policy_scope(current_user, FiatBalance)
end
field :sell_crypto_orders, SellCryptoOrderType.connection_type, null: false
def sell_crypto_orders
Pundit.policy_scope(current_user, SellCryptoOrder)

View File

@@ -7,12 +7,6 @@ module Types
graphql_name "SellCryptoOrder"
field :id, ID, null: false
field :currency, CurrencyType, null: false
def currency
dataloader.with(Dataloader::Source, Currency).load(object.currency_id)
end
field :status, ProcessStatusEnum, null: false
field :paid_amount, String, null: false
field :received_amount_cents, Integer, null: true

View File

@@ -11,5 +11,8 @@ module Types
field :first_name, String, null: false
field :last_name, String, null: false
field :wallet_address, String, null: true
field :balance, BalanceType, null: false
field :fiat_balance, FiatBalanceType, null: false
end
end

View File

@@ -6,8 +6,6 @@ class XStakeSchema < GraphQL::Schema
def self.resolve_type(abstract_type, obj, ctx)
case obj
when Currency
Types::CurrencyType
when Balance
Types::BalanceType
when FiatBalance

View File

@@ -1,42 +1,10 @@
type Balance implements Node {
amount: String!
currency: Currency!
id: ID!
}
"""
The connection type for Balance.
"""
type BalanceConnection {
"""
A list of edges.
"""
edges: [BalanceEdge!]!
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type BalanceEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: Balance!
}
type BuyCryptoOrder implements Node {
createdAt: ISO8601DateTime!
currency: Currency!
id: ID!
paidAmountCents: Int!
receivedAmount: String
@@ -79,7 +47,6 @@ input CreateBuyCryptoOrderAttributesInput {
Amount to be paid
"""
amountCents: Int!
currencyId: ID!
}
"""
@@ -114,7 +81,6 @@ input CreateSellCryptoOrderAttributesInput {
Amount to be paid
"""
amount: String!
currencyId: ID!
}
"""
@@ -206,47 +172,12 @@ type CreateStakeRemoveOrderPayload {
order: StakeOrder
}
type Currency implements Node {
id: ID!
name: String!
}
type FiatBalance implements Node {
amountCents: Int!
amountCurrency: String!
id: ID!
}
"""
The connection type for FiatBalance.
"""
type FiatBalanceConnection {
"""
A list of edges.
"""
edges: [FiatBalanceEdge!]!
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type FiatBalanceEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: FiatBalance!
}
"""
An ISO 8601-encoded datetime
"""
@@ -333,27 +264,6 @@ enum ProcessStatus {
}
type Query {
balances(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): BalanceConnection!
buyCryptoOrders(
"""
Returns the elements in the list that come after the specified cursor.
@@ -376,27 +286,6 @@ type Query {
last: Int
): BuyCryptoOrderConnection!
currentUser: User
fiatBalances(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): FiatBalanceConnection!
"""
Fetches an object given its ID.
@@ -471,7 +360,6 @@ type RecordInvalid {
type SellCryptoOrder implements Node {
createdAt: ISO8601DateTime!
currency: Currency!
id: ID!
paidAmount: String!
receivedAmountCents: Int
@@ -555,7 +443,9 @@ input StakeOrderFilterInput {
}
type User {
balance: Balance!
email: String!
fiatBalance: FiatBalance!
firstName: String!
id: ID!
lastName: String!

View File

@@ -7,17 +7,12 @@ import { Pool } from "./Pool";
import type { PoolListingQuery } from "./__generated__/PoolListingQuery.graphql";
export const PoolListing = () => {
const { balances } = useLazyLoadQuery<PoolListingQuery>(
const { currentUser } = useLazyLoadQuery<PoolListingQuery>(
graphql`
query PoolListingQuery {
balances {
edges {
node {
currency {
name
}
amount
}
currentUser {
balance {
amount
}
}
}
@@ -25,11 +20,7 @@ export const PoolListing = () => {
{}
);
const cakeBalance = balances.edges.find(
(edge) => edge.node.currency.name === "CAKE"
)?.node;
const balance = cakeBalance?.amount ?? "0";
const balance = currentUser?.balance.amount ?? "0";
return (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 place-items-center w-full gap-8 py-4 -mt-16 overflow-x-hidden">

View File

@@ -5,16 +5,11 @@
import { ConcreteRequest } from "relay-runtime";
export type PoolListingQueryVariables = {};
export type PoolListingQueryResponse = {
readonly balances: {
readonly edges: ReadonlyArray<{
readonly node: {
readonly currency: {
readonly name: string;
};
readonly amount: string;
};
}>;
};
readonly currentUser: {
readonly balance: {
readonly amount: string;
};
} | null;
};
export type PoolListingQuery = {
readonly response: PoolListingQueryResponse;
@@ -25,37 +20,25 @@ export type PoolListingQuery = {
/*
query PoolListingQuery {
balances {
edges {
node {
currency {
name
id
}
amount
id
}
currentUser {
balance {
amount
id
}
id
}
}
*/
const node: ConcreteRequest = (function(){
var v0 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "name",
"storageKey": null
},
v1 = {
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amount",
"storageKey": null
},
v2 = {
v1 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -72,43 +55,20 @@ return {
{
"alias": null,
"args": null,
"concreteType": "BalanceConnection",
"concreteType": "User",
"kind": "LinkedField",
"name": "balances",
"name": "currentUser",
"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": [
{
"alias": null,
"args": null,
"concreteType": "Currency",
"kind": "LinkedField",
"name": "currency",
"plural": false,
"selections": [
(v0/*: any*/)
],
"storageKey": null
},
(v1/*: any*/)
],
"storageKey": null
}
(v0/*: any*/)
],
"storageKey": null
}
@@ -128,62 +88,39 @@ return {
{
"alias": null,
"args": null,
"concreteType": "BalanceConnection",
"concreteType": "User",
"kind": "LinkedField",
"name": "balances",
"name": "currentUser",
"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": [
{
"alias": null,
"args": null,
"concreteType": "Currency",
"kind": "LinkedField",
"name": "currency",
"plural": false,
"selections": [
(v0/*: any*/),
(v2/*: any*/)
],
"storageKey": null
},
(v1/*: any*/),
(v2/*: any*/)
],
"storageKey": null
}
(v0/*: any*/),
(v1/*: any*/)
],
"storageKey": null
}
},
(v1/*: any*/)
],
"storageKey": null
}
]
},
"params": {
"cacheID": "6abf5e963429e49993af50df156f8e1c",
"cacheID": "6af4091073903ead7eb057e9f245a32c",
"id": null,
"metadata": {},
"name": "PoolListingQuery",
"operationKind": "query",
"text": "query PoolListingQuery {\n balances {\n edges {\n node {\n currency {\n name\n id\n }\n amount\n id\n }\n }\n }\n}\n"
"text": "query PoolListingQuery {\n currentUser {\n balance {\n amount\n id\n }\n id\n }\n}\n"
}
};
})();
(node as any).hash = '4fefb238e24b79198799686599255e6c';
(node as any).hash = 'e296b5abac1f659b33d8c77522fbfc55';
export default node;

View File

@@ -11,11 +11,13 @@ export const Exchange = () => {
const data = useLazyLoadQuery<ExchangeQuery>(
graphql`
query ExchangeQuery {
fiatBalances {
...ExchangePanel_fiatBalances
}
balances {
...ExchangePanel_balances
currentUser {
fiatBalance {
...ExchangePanel_fiatBalances
}
balance {
...ExchangePanel_balances
}
}
buyCryptoOrders {
...ExchangeHistory_buyCryptoOrders
@@ -30,10 +32,12 @@ export const Exchange = () => {
return (
<div className="w-full">
<ExchangePanel
balancesRefs={data.balances}
fiatBalancesRefs={data.fiatBalances}
/>
{data.currentUser && (
<ExchangePanel
balancesRefs={data.currentUser.balance}
fiatBalancesRefs={data.currentUser.fiatBalance}
/>
)}
<ExchangeHistory
sellCryptoOrdersRefs={data.sellCryptoOrders}

View File

@@ -3,6 +3,7 @@ import type { FC } from "react";
import React from "react";
import { useFragment } from "react-relay";
import { Messages } from "../../../../messages";
import { centsToUnit } from "../../../../utils/fiatMoney";
import type { CryptoExchangeOrderProps } from "./components/CryptoExchangeOrder";
import { CryptoExchangeOrder } from "./components/CryptoExchangeOrder";
@@ -47,9 +48,6 @@ export const ExchangeHistory: FC<Props> = ({
createdAt
paidAmountCents
receivedAmount
currency {
name
}
__typename
}
}
@@ -68,9 +66,6 @@ export const ExchangeHistory: FC<Props> = ({
paidAmount
receivedAmountCents
createdAt
currency {
name
}
__typename
}
}
@@ -95,7 +90,7 @@ export const ExchangeHistory: FC<Props> = ({
if (node?.__typename === "SellCryptoOrder") {
return {
id: node.id,
payed: `${node.paidAmount} ${node.currency.name}`,
payed: `${node.paidAmount} CAKE`,
received: `${centsToUnit(node.receivedAmountCents)} BRL`,
createdAt: new Date(node.createdAt as string).toLocaleString(),
kind: node.__typename,
@@ -107,7 +102,7 @@ export const ExchangeHistory: FC<Props> = ({
return {
id: node.id,
payed: `${centsToUnit(node.paidAmountCents)} BRL`,
received: `${node.receivedAmount} ${node.currency.name}`,
received: `${node.receivedAmount} CAKE`,
createdAt: new Date(node.createdAt as string).toLocaleString(),
kind: node.__typename,
status: node.status,
@@ -117,7 +112,7 @@ export const ExchangeHistory: FC<Props> = ({
return null;
});
if (!orderRows.length) return null;
if (!orderRows.length) return <Messages.NoHistory historyName="troca" />;
return (
<div className="container mx-auto px-4 sm:px-8">

View File

@@ -13,9 +13,6 @@ export type ExchangeHistory_buyCryptoOrders = {
readonly createdAt: unknown;
readonly paidAmountCents: number;
readonly receivedAmount: string | null;
readonly currency: {
readonly name: string;
};
readonly __typename: string;
};
}>;
@@ -86,24 +83,6 @@ const node: ReaderFragment = {
"name": "receivedAmount",
"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
},
{
"alias": null,
"args": null,
@@ -121,5 +100,5 @@ const node: ReaderFragment = {
"type": "BuyCryptoOrderConnection",
"abstractKey": null
};
(node as any).hash = 'da0e93160594d0e07defe123a9bd755b';
(node as any).hash = 'cf603cb2594ebe32eb4c562df9b03585';
export default node;

View File

@@ -13,9 +13,6 @@ export type ExchangeHistory_sellCryptoOrders = {
readonly paidAmount: string;
readonly receivedAmountCents: number | null;
readonly createdAt: unknown;
readonly currency: {
readonly name: string;
};
readonly __typename: string;
};
}>;
@@ -86,24 +83,6 @@ const node: ReaderFragment = {
"name": "createdAt",
"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
},
{
"alias": null,
"args": null,
@@ -121,5 +100,5 @@ const node: ReaderFragment = {
"type": "SellCryptoOrderConnection",
"abstractKey": null
};
(node as any).hash = '384d1326525240c150d450555796a621';
(node as any).hash = '0a6fbd33935e0dcd241ffa3270f1ea30';
export default node;

View File

@@ -36,30 +36,19 @@ export const ExchangePanel: FC<Props> = ({
const [cryptoDock, setCryptoDock] = useState<string>("0");
const [fiatDock, setFiatDock] = useState<string>("0.00");
const fiatBalances = useFragment<ExchangePanel_fiatBalances$key>(
const fiatBalance = useFragment<ExchangePanel_fiatBalances$key>(
graphql`
fragment ExchangePanel_fiatBalances on FiatBalanceConnection {
edges {
node {
amountCents
}
}
fragment ExchangePanel_fiatBalances on FiatBalance {
amountCents
}
`,
fiatBalancesRefs
);
const balances = useFragment<ExchangePanel_balances$key>(
const balance = useFragment<ExchangePanel_balances$key>(
graphql`
fragment ExchangePanel_balances on BalanceConnection {
edges {
node {
amount
currency {
id
}
}
}
fragment ExchangePanel_balances on Balance {
amount
}
`,
balancesRefs
@@ -67,12 +56,9 @@ export const ExchangePanel: FC<Props> = ({
if (!isAuthenticated) return <Unauthenticated />;
const [crypto] = balances.edges;
const [fiat] = fiatBalances.edges;
const avaliableCrypto = new BigNumber(crypto.node.amount);
const avaliableCrypto = new BigNumber(balance.amount);
const avaliableFiat = (
fiat.node.amountCents ? fiat.node.amountCents / 100 : 0
fiatBalance.amountCents ? fiatBalance.amountCents / 100 : 0
).toFixed(2);
const handleSellTabClick = () => {
@@ -123,14 +109,12 @@ export const ExchangePanel: FC<Props> = ({
if (exchangeOption === "SELL") {
commitCreateSellCryptoOrderMutation(environment, {
amount: cryptoDock,
currencyId: crypto.node.currency.id,
});
}
if (exchangeOption === "BUY") {
commitCreateBuyCryptoOrderMutation(environment, {
amountCents: parseFloat(fiatDock) * 100,
currencyId: crypto.node.currency.id,
});
}
};
@@ -172,7 +156,7 @@ export const ExchangePanel: FC<Props> = ({
>
<span className="mb-2">
{exchangeOption === "SELL" ? "CAKE" : "BRL"} disponível:{" "}
{exchangeOption === "SELL" ? crypto.node.amount : avaliableFiat}
{exchangeOption === "SELL" ? balance.amount : avaliableFiat}
</span>
<div className="flex flex-row">
{exchangeOption === "BUY" ? (

View File

@@ -5,14 +5,7 @@
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type ExchangePanel_balances = {
readonly edges: ReadonlyArray<{
readonly node: {
readonly amount: string;
readonly currency: {
readonly id: string;
};
};
}>;
readonly amount: string;
readonly " $refType": "ExchangePanel_balances";
};
export type ExchangePanel_balances$data = ExchangePanel_balances;
@@ -32,53 +25,13 @@ const node: ReaderFragment = {
{
"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": "amount",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "Currency",
"kind": "LinkedField",
"name": "currency",
"plural": false,
"selections": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "id",
"storageKey": null
}
],
"storageKey": null
}
],
"storageKey": null
}
],
"kind": "ScalarField",
"name": "amount",
"storageKey": null
}
],
"type": "BalanceConnection",
"type": "Balance",
"abstractKey": null
};
(node as any).hash = '3be851ad99a353609459a7edc960f272';
(node as any).hash = '99736114264996104eaa4907673d9849';
export default node;

View File

@@ -5,11 +5,7 @@
import { ReaderFragment } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type ExchangePanel_fiatBalances = {
readonly edges: ReadonlyArray<{
readonly node: {
readonly amountCents: number;
};
}>;
readonly amountCents: number;
readonly " $refType": "ExchangePanel_fiatBalances";
};
export type ExchangePanel_fiatBalances$data = ExchangePanel_fiatBalances;
@@ -29,35 +25,13 @@ const node: ReaderFragment = {
{
"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
}
],
"storageKey": null
}
],
"kind": "ScalarField",
"name": "amountCents",
"storageKey": null
}
],
"type": "FiatBalanceConnection",
"type": "FiatBalance",
"abstractKey": null
};
(node as any).hash = '14b79d15c8353d856f3e74bb7c181cf7';
(node as any).hash = '9f9bd030f967a665c247facbf641b760';
export default node;

View File

@@ -4,7 +4,6 @@
import { ConcreteRequest } from "relay-runtime";
export type createBuyCryptoOrderMutationVariables = {
currencyId: string;
amountCents: number;
};
export type createBuyCryptoOrderMutationResponse = {
@@ -26,10 +25,9 @@ export type createBuyCryptoOrderMutation = {
/*
mutation createBuyCryptoOrderMutation(
$currencyId: ID!
$amountCents: Int!
) {
createBuyCryptoOrder(input: {order: {currencyId: $currencyId, amountCents: $amountCents}}) {
createBuyCryptoOrder(input: {order: {amountCents: $amountCents}}) {
errors {
messages
}
@@ -41,17 +39,14 @@ mutation createBuyCryptoOrderMutation(
*/
const node: ConcreteRequest = (function(){
var v0 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "amountCents"
},
v1 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "currencyId"
},
v2 = [
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "amountCents"
}
],
v1 = [
{
"alias": null,
"args": [
@@ -63,11 +58,6 @@ v2 = [
"kind": "Variable",
"name": "amountCents",
"variableName": "amountCents"
},
{
"kind": "Variable",
"name": "currencyId",
"variableName": "currencyId"
}
],
"kind": "ObjectValue",
@@ -125,36 +115,30 @@ v2 = [
];
return {
"fragment": {
"argumentDefinitions": [
(v0/*: any*/),
(v1/*: any*/)
],
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "createBuyCryptoOrderMutation",
"selections": (v2/*: any*/),
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": [
(v1/*: any*/),
(v0/*: any*/)
],
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "createBuyCryptoOrderMutation",
"selections": (v2/*: any*/)
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "d7cc0c483d893b14f46781408d9d3f2f",
"cacheID": "aad8a1ea13e8a77031c98f59b0c5e0db",
"id": null,
"metadata": {},
"name": "createBuyCryptoOrderMutation",
"operationKind": "mutation",
"text": "mutation createBuyCryptoOrderMutation(\n $currencyId: ID!\n $amountCents: Int!\n) {\n createBuyCryptoOrder(input: {order: {currencyId: $currencyId, amountCents: $amountCents}}) {\n errors {\n messages\n }\n order {\n id\n }\n }\n}\n"
"text": "mutation createBuyCryptoOrderMutation(\n $amountCents: Int!\n) {\n createBuyCryptoOrder(input: {order: {amountCents: $amountCents}}) {\n errors {\n messages\n }\n order {\n id\n }\n }\n}\n"
}
};
})();
(node as any).hash = 'a272ce6d5ae676a9cdc4e38eb7cc3cbe';
(node as any).hash = '1eceec2d8340693381f746a9e75476b8';
export default node;

View File

@@ -4,7 +4,6 @@
import { ConcreteRequest } from "relay-runtime";
export type createSellCryptoOrderMutationVariables = {
currencyId: string;
amount: string;
};
export type createSellCryptoOrderMutationResponse = {
@@ -26,10 +25,9 @@ export type createSellCryptoOrderMutation = {
/*
mutation createSellCryptoOrderMutation(
$currencyId: ID!
$amount: String!
) {
createSellCryptoOrder(input: {order: {currencyId: $currencyId, amount: $amount}}) {
createSellCryptoOrder(input: {order: {amount: $amount}}) {
errors {
messages
}
@@ -41,17 +39,14 @@ mutation createSellCryptoOrderMutation(
*/
const node: ConcreteRequest = (function(){
var v0 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "amount"
},
v1 = {
"defaultValue": null,
"kind": "LocalArgument",
"name": "currencyId"
},
v2 = [
var v0 = [
{
"defaultValue": null,
"kind": "LocalArgument",
"name": "amount"
}
],
v1 = [
{
"alias": null,
"args": [
@@ -63,11 +58,6 @@ v2 = [
"kind": "Variable",
"name": "amount",
"variableName": "amount"
},
{
"kind": "Variable",
"name": "currencyId",
"variableName": "currencyId"
}
],
"kind": "ObjectValue",
@@ -125,36 +115,30 @@ v2 = [
];
return {
"fragment": {
"argumentDefinitions": [
(v0/*: any*/),
(v1/*: any*/)
],
"argumentDefinitions": (v0/*: any*/),
"kind": "Fragment",
"metadata": null,
"name": "createSellCryptoOrderMutation",
"selections": (v2/*: any*/),
"selections": (v1/*: any*/),
"type": "Mutation",
"abstractKey": null
},
"kind": "Request",
"operation": {
"argumentDefinitions": [
(v1/*: any*/),
(v0/*: any*/)
],
"argumentDefinitions": (v0/*: any*/),
"kind": "Operation",
"name": "createSellCryptoOrderMutation",
"selections": (v2/*: any*/)
"selections": (v1/*: any*/)
},
"params": {
"cacheID": "2c81ae5adf76b4fa157bc5453df40fcc",
"cacheID": "d4cb659efe0d2b63262cce510327ae11",
"id": null,
"metadata": {},
"name": "createSellCryptoOrderMutation",
"operationKind": "mutation",
"text": "mutation createSellCryptoOrderMutation(\n $currencyId: ID!\n $amount: String!\n) {\n createSellCryptoOrder(input: {order: {currencyId: $currencyId, amount: $amount}}) {\n errors {\n messages\n }\n order {\n id\n }\n }\n}\n"
"text": "mutation createSellCryptoOrderMutation(\n $amount: String!\n) {\n createSellCryptoOrder(input: {order: {amount: $amount}}) {\n errors {\n messages\n }\n order {\n id\n }\n }\n}\n"
}
};
})();
(node as any).hash = '073e3f84d5921279ded3149dd9ec7db9';
(node as any).hash = '5ce66da95c141385c607a3be499805f7';
export default node;

View File

@@ -10,15 +10,8 @@ export const commitCreateBuyCryptoOrderMutation = (
) => {
return commitMutation(environment, {
mutation: graphql`
mutation createBuyCryptoOrderMutation(
$currencyId: ID!
$amountCents: Int!
) {
createBuyCryptoOrder(
input: {
order: { currencyId: $currencyId, amountCents: $amountCents }
}
) {
mutation createBuyCryptoOrderMutation($amountCents: Int!) {
createBuyCryptoOrder(input: { order: { amountCents: $amountCents } }) {
errors {
messages
}
@@ -28,7 +21,7 @@ export const commitCreateBuyCryptoOrderMutation = (
}
}
`,
variables: { ...variables },
variables,
onCompleted: (_response) => {
window.location.reload();
},

View File

@@ -10,13 +10,8 @@ export const commitCreateSellCryptoOrderMutation = (
) => {
return commitMutation(environment, {
mutation: graphql`
mutation createSellCryptoOrderMutation(
$currencyId: ID!
$amount: String!
) {
createSellCryptoOrder(
input: { order: { currencyId: $currencyId, amount: $amount } }
) {
mutation createSellCryptoOrderMutation($amount: String!) {
createSellCryptoOrder(input: { order: { amount: $amount } }) {
errors {
messages
}
@@ -26,7 +21,7 @@ export const commitCreateSellCryptoOrderMutation = (
}
}
`,
variables: { ...variables },
variables,
onCompleted: (_response) => {
window.location.reload();
},

View File

@@ -6,12 +6,14 @@ import { ConcreteRequest } from "relay-runtime";
import { FragmentRefs } from "relay-runtime";
export type ExchangeQueryVariables = {};
export type ExchangeQueryResponse = {
readonly fiatBalances: {
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_fiatBalances">;
};
readonly balances: {
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_balances">;
};
readonly currentUser: {
readonly fiatBalance: {
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_fiatBalances">;
};
readonly balance: {
readonly " $fragmentRefs": FragmentRefs<"ExchangePanel_balances">;
};
} | null;
readonly buyCryptoOrders: {
readonly " $fragmentRefs": FragmentRefs<"ExchangeHistory_buyCryptoOrders">;
};
@@ -28,11 +30,16 @@ export type ExchangeQuery = {
/*
query ExchangeQuery {
fiatBalances {
...ExchangePanel_fiatBalances
}
balances {
...ExchangePanel_balances
currentUser {
fiatBalance {
...ExchangePanel_fiatBalances
id
}
balance {
...ExchangePanel_balances
id
}
id
}
buyCryptoOrders {
...ExchangeHistory_buyCryptoOrders
@@ -50,10 +57,6 @@ fragment ExchangeHistory_buyCryptoOrders on BuyCryptoOrderConnection {
createdAt
paidAmountCents
receivedAmount
currency {
name
id
}
__typename
}
}
@@ -67,34 +70,17 @@ fragment ExchangeHistory_sellCryptoOrders on SellCryptoOrderConnection {
paidAmount
receivedAmountCents
createdAt
currency {
name
id
}
__typename
}
}
}
fragment ExchangePanel_balances on BalanceConnection {
edges {
node {
amount
currency {
id
}
id
}
}
fragment ExchangePanel_balances on Balance {
amount
}
fragment ExchangePanel_fiatBalances on FiatBalanceConnection {
edges {
node {
amountCents
id
}
}
fragment ExchangePanel_fiatBalances on FiatBalance {
amountCents
}
*/
@@ -121,25 +107,6 @@ v2 = {
"storageKey": null
},
v3 = {
"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
},
v4 = {
"alias": null,
"args": null,
"kind": "ScalarField",
@@ -156,31 +123,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": "ExchangePanel_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": "ExchangePanel_fiatBalances"
}
],
"storageKey": null
},
{
"alias": null,
"args": null,
"kind": "FragmentSpread",
"name": "ExchangePanel_balances"
"concreteType": "Balance",
"kind": "LinkedField",
"name": "balance",
"plural": false,
"selections": [
{
"args": null,
"kind": "FragmentSpread",
"name": "ExchangePanel_balances"
}
],
"storageKey": null
}
],
"storageKey": null
@@ -230,94 +208,50 @@ 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
},
(v0/*: any*/)
],
"kind": "ScalarField",
"name": "amountCents",
"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": [
{
"alias": null,
"args": null,
"kind": "ScalarField",
"name": "amount",
"storageKey": null
},
{
"alias": null,
"args": null,
"concreteType": "Currency",
"kind": "LinkedField",
"name": "currency",
"plural": false,
"selections": [
(v0/*: any*/)
],
"storageKey": null
},
(v0/*: any*/)
],
"kind": "ScalarField",
"name": "amount",
"storageKey": null
}
},
(v0/*: any*/)
],
"storageKey": null
}
},
(v0/*: any*/)
],
"storageKey": null
},
@@ -362,8 +296,7 @@ return {
"name": "receivedAmount",
"storageKey": null
},
(v3/*: any*/),
(v4/*: any*/)
(v3/*: any*/)
],
"storageKey": null
}
@@ -414,8 +347,7 @@ return {
"storageKey": null
},
(v2/*: any*/),
(v3/*: any*/),
(v4/*: any*/)
(v3/*: any*/)
],
"storageKey": null
}
@@ -428,14 +360,14 @@ return {
]
},
"params": {
"cacheID": "424352bbffec52284c44f109ce54a441",
"cacheID": "3312f3d7aa6ac4b7051376b61f10c957",
"id": null,
"metadata": {},
"name": "ExchangeQuery",
"operationKind": "query",
"text": "query ExchangeQuery {\n fiatBalances {\n ...ExchangePanel_fiatBalances\n }\n balances {\n ...ExchangePanel_balances\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 currency {\n name\n id\n }\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 currency {\n name\n id\n }\n __typename\n }\n }\n}\n\nfragment ExchangePanel_balances on BalanceConnection {\n edges {\n node {\n amount\n currency {\n id\n }\n id\n }\n }\n}\n\nfragment ExchangePanel_fiatBalances on FiatBalanceConnection {\n edges {\n node {\n amountCents\n id\n }\n }\n}\n"
"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"
}
};
})();
(node as any).hash = '3d09bb5b003cac17750666dc76088801';
(node as any).hash = '85296680bd82d278a1f5d485b8b101f3';
export default node;

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;

View File

@@ -4,28 +4,24 @@
#
# Table name: balances
#
# id :bigint not null, primary key
# amount :decimal(20, 10) default(0.0), not null
# created_at :datetime not null
# updated_at :datetime not null
# currency_id :bigint not null
# user_id :bigint not null
# id :bigint not null, primary key
# amount :decimal(20, 10) default(0.0), not null
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_balances_on_currency_id (currency_id)
# index_balances_on_user_id (user_id)
# index_balances_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (currency_id => currencies.id)
# fk_rails_... (user_id => users.id)
#
class Balance < ApplicationRecord
include Trackable
belongs_to :user
belongs_to :currency
validates :amount, presence: true, numericality: { greater_than_or_equal_to: 0 }

View File

@@ -10,17 +10,14 @@
# status :string not null
# created_at :datetime not null
# updated_at :datetime not null
# currency_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_buy_crypto_orders_on_currency_id (currency_id)
# index_buy_crypto_orders_on_user_id (user_id)
# index_buy_crypto_orders_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (currency_id => currencies.id)
# fk_rails_... (user_id => users.id)
#
class BuyCryptoOrder < ApplicationRecord
@@ -28,7 +25,6 @@ class BuyCryptoOrder < ApplicationRecord
include Notifiable
belongs_to :user
belongs_to :currency
monetize :paid_amount_cents

View File

@@ -1,14 +0,0 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: currencies
#
# id :bigint not null, primary key
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Currency < ApplicationRecord
validates :name, presence: true
end

View File

@@ -10,17 +10,14 @@
# status :string not null
# created_at :datetime not null
# updated_at :datetime not null
# currency_id :bigint not null
# user_id :bigint not null
#
# Indexes
#
# index_sell_crypto_orders_on_currency_id (currency_id)
# index_sell_crypto_orders_on_user_id (user_id)
# index_sell_crypto_orders_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (currency_id => currencies.id)
# fk_rails_... (user_id => users.id)
#
class SellCryptoOrder < ApplicationRecord
@@ -28,7 +25,6 @@ class SellCryptoOrder < ApplicationRecord
include Notifiable
belongs_to :user
belongs_to :currency
monetize :received_amount_cents
@@ -41,7 +37,7 @@ class SellCryptoOrder < ApplicationRecord
"
💸 New sell crypto order! 💸\n
user: #{user.email} \n
amount: #{paid_amount} #{currency.name}
amount: #{paid_amount} CAKE
"
end
end

View File

@@ -4,23 +4,20 @@
#
# Table name: stake_orders
#
# id :bigint not null, primary key
# amount :decimal(20, 10) default(0.0), not null
# pool_name :string not null
# status :string not null
# created_at :datetime not null
# updated_at :datetime not null
# currency_id :bigint
# user_id :bigint not null
# id :bigint not null, primary key
# amount :decimal(20, 10) default(0.0), not null
# pool_name :string not null
# status :string not null
# created_at :datetime not null
# updated_at :datetime not null
# user_id :bigint not null
#
# Indexes
#
# index_stake_orders_on_currency_id (currency_id)
# index_stake_orders_on_user_id (user_id)
# index_stake_orders_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (currency_id => currencies.id)
# fk_rails_... (user_id => users.id)
#
class StakeOrder < ApplicationRecord
@@ -28,7 +25,6 @@ class StakeOrder < ApplicationRecord
include Notifiable
belongs_to :user
belongs_to :currency
validates :pool_name, presence: true
validates :amount, presence: true

View File

@@ -29,7 +29,7 @@ class User < ApplicationRecord
has_many :documents, class_name: "UserDocument", dependent: :destroy
has_many :stake_orders, dependent: :restrict_with_error
has_many :balances, dependent: :restrict_with_error
has_one :balance, dependent: :restrict_with_error
has_one :fiat_balance, dependent: :restrict_with_error
validates :first_name, :last_name, :email, presence: true

View File

@@ -24,13 +24,8 @@ class CreateUserBalances
end
def create_balances
Currency.in_batches.each do |relation|
relation.each do |currency|
Balance.find_or_create_by(
user_id: user.id,
currency_id: currency.id,
)
end
end
Balance.find_or_create_by(
user_id: user.id
)
end
end