From 0d10e865262ec8abd24632e76838512e2ce0ce08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Sat, 28 Aug 2021 01:29:07 -0300 Subject: [PATCH] remove currency model and all references --- .../admin/currencies_controller.rb | 8 - app/dashboards/balance_dashboard.rb | 7 +- app/dashboards/buy_crypto_order_dashboard.rb | 8 +- app/dashboards/currency_dashboard.rb | 52 ---- app/dashboards/sell_crypto_order_dashboard.rb | 7 +- app/dashboards/stake_order_dashboard.rb | 7 +- ...reate_buy_crypto_order_attributes_input.rb | 1 - ...eate_sell_crypto_order_attributes_input.rb | 1 - .../mutations/create_buy_crypto_order.rb | 3 - .../mutations/create_sell_crypto_order.rb | 5 +- app/graphql/mutations/create_stake_order.rb | 5 +- .../mutations/create_stake_remove_order.rb | 2 - app/graphql/types/balance_type.rb | 5 - app/graphql/types/buy_crypto_order_type.rb | 6 - app/graphql/types/currency_type.rb | 12 - app/graphql/types/query_type.rb | 10 - app/graphql/types/sell_crypto_order_type.rb | 6 - app/graphql/types/user_type.rb | 3 + app/graphql/x_stake_schema.rb | 2 - app/javascript/__generated__/schema.graphql | 114 +------ app/javascript/src/pages/Home/PoolListing.tsx | 19 +- .../__generated__/PoolListingQuery.graphql.ts | 121 ++----- .../src/pages/Orders/Exchange/Exchange.tsx | 22 +- .../ExchangeHistory/ExchangeHistory.tsx | 13 +- ...ExchangeHistory_buyCryptoOrders.graphql.ts | 23 +- ...xchangeHistory_sellCryptoOrders.graphql.ts | 23 +- .../Exchange/ExchangePanel/ExchangePanel.tsx | 34 +- .../ExchangePanel_balances.graphql.ts | 57 +--- .../ExchangePanel_fiatBalances.graphql.ts | 36 +-- .../createBuyCryptoOrderMutation.graphql.ts | 48 +-- .../createSellCryptoOrderMutation.graphql.ts | 48 +-- .../ExchangePanel/createBuyCryptoOrder.ts | 13 +- .../ExchangePanel/createSellCryptoOrder.ts | 11 +- .../__generated__/ExchangeQuery.graphql.ts | 218 +++++-------- app/javascript/src/pages/Wallet/Balance.tsx | 71 +++++ app/javascript/src/pages/Wallet/Balances.tsx | 85 ----- .../{FiatBalances.tsx => FiatBalance.tsx} | 24 +- app/javascript/src/pages/Wallet/Wallet.tsx | 24 +- .../__generated__/Balance_balance.graphql.ts | 37 +++ .../Balances_balances.graphql.ts | 92 ------ .../FiatBalance_fiatBalance.graphql.ts | 45 +++ .../FiatBalances_fiatBalances.graphql.ts | 71 ----- .../__generated__/WalletQuery.graphql.ts | 209 +++++-------- app/models/balance.rb | 16 +- app/models/buy_crypto_order.rb | 6 +- app/models/currency.rb | 14 - app/models/sell_crypto_order.rb | 8 +- app/models/stake_order.rb | 20 +- app/models/user.rb | 2 +- app/services/create_user_balances.rb | 11 +- config/locales/pt-BR.yml | 7 - db/migrate/20210828041104_drop_currency.rb | 11 + db/schema.rb | 20 +- db/seeds.rb | 2 - erd.svg | 294 ++++++++---------- spec/factories/balances.rb | 16 +- spec/factories/buy_crypto_orders.rb | 6 +- spec/factories/currencies.rb | 16 - spec/factories/sell_crypto_orders.rb | 6 +- spec/factories/stake_orders.rb | 19 +- ..._buy_crypto_order_attributes_input_spec.rb | 1 - ...sell_crypto_order_attributes_input_spec.rb | 1 - .../mutations/create_buy_crypto_order_spec.rb | 17 +- .../create_sell_crypto_order_spec.rb | 29 +- .../mutations/create_stake_order_spec.rb | 14 +- .../create_stake_remove_order_spec.rb | 12 +- .../types/buy_crypto_order_type_spec.rb | 1 - .../types/sell_crypto_order_type_spec.rb | 1 - spec/models/balance_spec.rb | 16 +- spec/models/buy_crypto_order_spec.rb | 6 +- spec/models/currency_spec.rb | 18 -- spec/models/sell_crypto_order_spec.rb | 6 +- spec/models/stake_order_spec.rb | 20 +- spec/models/user_spec.rb | 2 +- 74 files changed, 665 insertions(+), 1561 deletions(-) delete mode 100644 app/controllers/admin/currencies_controller.rb delete mode 100644 app/dashboards/currency_dashboard.rb delete mode 100644 app/graphql/types/currency_type.rb create mode 100644 app/javascript/src/pages/Wallet/Balance.tsx delete mode 100644 app/javascript/src/pages/Wallet/Balances.tsx rename app/javascript/src/pages/Wallet/{FiatBalances.tsx => FiatBalance.tsx} (76%) create mode 100644 app/javascript/src/pages/Wallet/__generated__/Balance_balance.graphql.ts delete mode 100644 app/javascript/src/pages/Wallet/__generated__/Balances_balances.graphql.ts create mode 100644 app/javascript/src/pages/Wallet/__generated__/FiatBalance_fiatBalance.graphql.ts delete mode 100644 app/javascript/src/pages/Wallet/__generated__/FiatBalances_fiatBalances.graphql.ts delete mode 100644 app/models/currency.rb create mode 100644 db/migrate/20210828041104_drop_currency.rb delete mode 100644 spec/factories/currencies.rb delete mode 100644 spec/models/currency_spec.rb diff --git a/app/controllers/admin/currencies_controller.rb b/app/controllers/admin/currencies_controller.rb deleted file mode 100644 index 46afa63..0000000 --- a/app/controllers/admin/currencies_controller.rb +++ /dev/null @@ -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 diff --git a/app/dashboards/balance_dashboard.rb b/app/dashboards/balance_dashboard.rb index e7ffaa1..354c20b 100644 --- a/app/dashboards/balance_dashboard.rb +++ b/app/dashboards/balance_dashboard.rb @@ -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 diff --git a/app/dashboards/buy_crypto_order_dashboard.rb b/app/dashboards/buy_crypto_order_dashboard.rb index f5d60aa..3114259 100644 --- a/app/dashboards/buy_crypto_order_dashboard.rb +++ b/app/dashboards/buy_crypto_order_dashboard.rb @@ -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 diff --git a/app/dashboards/currency_dashboard.rb b/app/dashboards/currency_dashboard.rb deleted file mode 100644 index bbf9036..0000000 --- a/app/dashboards/currency_dashboard.rb +++ /dev/null @@ -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 diff --git a/app/dashboards/sell_crypto_order_dashboard.rb b/app/dashboards/sell_crypto_order_dashboard.rb index d585994..7b4cbb6 100644 --- a/app/dashboards/sell_crypto_order_dashboard.rb +++ b/app/dashboards/sell_crypto_order_dashboard.rb @@ -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 diff --git a/app/dashboards/stake_order_dashboard.rb b/app/dashboards/stake_order_dashboard.rb index 034bae6..0b9f972 100644 --- a/app/dashboards/stake_order_dashboard.rb +++ b/app/dashboards/stake_order_dashboard.rb @@ -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 diff --git a/app/graphql/inputs/create_buy_crypto_order_attributes_input.rb b/app/graphql/inputs/create_buy_crypto_order_attributes_input.rb index 3b3f37e..ab5d6df 100644 --- a/app/graphql/inputs/create_buy_crypto_order_attributes_input.rb +++ b/app/graphql/inputs/create_buy_crypto_order_attributes_input.rb @@ -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 diff --git a/app/graphql/inputs/create_sell_crypto_order_attributes_input.rb b/app/graphql/inputs/create_sell_crypto_order_attributes_input.rb index e6da70f..96a59f5 100644 --- a/app/graphql/inputs/create_sell_crypto_order_attributes_input.rb +++ b/app/graphql/inputs/create_sell_crypto_order_attributes_input.rb @@ -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 diff --git a/app/graphql/mutations/create_buy_crypto_order.rb b/app/graphql/mutations/create_buy_crypto_order.rb index 0b22ec6..0a7dde9 100644 --- a/app/graphql/mutations/create_buy_crypto_order.rb +++ b/app/graphql/mutations/create_buy_crypto_order.rb @@ -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, ) diff --git a/app/graphql/mutations/create_sell_crypto_order.rb b/app/graphql/mutations/create_sell_crypto_order.rb index 637031a..e8ca79a 100644 --- a/app/graphql/mutations/create_sell_crypto_order.rb +++ b/app/graphql/mutations/create_sell_crypto_order.rb @@ -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, ) diff --git a/app/graphql/mutations/create_stake_order.rb b/app/graphql/mutations/create_stake_order.rb index eb89826..fabb38a 100644 --- a/app/graphql/mutations/create_stake_order.rb +++ b/app/graphql/mutations/create_stake_order.rb @@ -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, ) diff --git a/app/graphql/mutations/create_stake_remove_order.rb b/app/graphql/mutations/create_stake_remove_order.rb index 9b191c0..1bc9424 100644 --- a/app/graphql/mutations/create_stake_remove_order.rb +++ b/app/graphql/mutations/create_stake_remove_order.rb @@ -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 ) diff --git a/app/graphql/types/balance_type.rb b/app/graphql/types/balance_type.rb index 7549855..76b8b6f 100644 --- a/app/graphql/types/balance_type.rb +++ b/app/graphql/types/balance_type.rb @@ -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 diff --git a/app/graphql/types/buy_crypto_order_type.rb b/app/graphql/types/buy_crypto_order_type.rb index 1c28420..e4a5b68 100644 --- a/app/graphql/types/buy_crypto_order_type.rb +++ b/app/graphql/types/buy_crypto_order_type.rb @@ -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 diff --git a/app/graphql/types/currency_type.rb b/app/graphql/types/currency_type.rb deleted file mode 100644 index 6c35166..0000000 --- a/app/graphql/types/currency_type.rb +++ /dev/null @@ -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 diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index 23d6dc6..ff4b89b 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -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) diff --git a/app/graphql/types/sell_crypto_order_type.rb b/app/graphql/types/sell_crypto_order_type.rb index c70bcde..ca39858 100644 --- a/app/graphql/types/sell_crypto_order_type.rb +++ b/app/graphql/types/sell_crypto_order_type.rb @@ -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 diff --git a/app/graphql/types/user_type.rb b/app/graphql/types/user_type.rb index b52c493..de366bf 100644 --- a/app/graphql/types/user_type.rb +++ b/app/graphql/types/user_type.rb @@ -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 diff --git a/app/graphql/x_stake_schema.rb b/app/graphql/x_stake_schema.rb index f3dab93..268a968 100644 --- a/app/graphql/x_stake_schema.rb +++ b/app/graphql/x_stake_schema.rb @@ -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 diff --git a/app/javascript/__generated__/schema.graphql b/app/javascript/__generated__/schema.graphql index b72d7ad..878a20c 100644 --- a/app/javascript/__generated__/schema.graphql +++ b/app/javascript/__generated__/schema.graphql @@ -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! diff --git a/app/javascript/src/pages/Home/PoolListing.tsx b/app/javascript/src/pages/Home/PoolListing.tsx index 82ffb26..a1cb443 100644 --- a/app/javascript/src/pages/Home/PoolListing.tsx +++ b/app/javascript/src/pages/Home/PoolListing.tsx @@ -7,17 +7,12 @@ import { Pool } from "./Pool"; import type { PoolListingQuery } from "./__generated__/PoolListingQuery.graphql"; export const PoolListing = () => { - const { balances } = useLazyLoadQuery( + const { currentUser } = useLazyLoadQuery( 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 (
diff --git a/app/javascript/src/pages/Home/__generated__/PoolListingQuery.graphql.ts b/app/javascript/src/pages/Home/__generated__/PoolListingQuery.graphql.ts index c359895..18e7ed0 100644 --- a/app/javascript/src/pages/Home/__generated__/PoolListingQuery.graphql.ts +++ b/app/javascript/src/pages/Home/__generated__/PoolListingQuery.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Orders/Exchange/Exchange.tsx b/app/javascript/src/pages/Orders/Exchange/Exchange.tsx index e3665b4..d90f59e 100644 --- a/app/javascript/src/pages/Orders/Exchange/Exchange.tsx +++ b/app/javascript/src/pages/Orders/Exchange/Exchange.tsx @@ -11,11 +11,13 @@ export const Exchange = () => { const data = useLazyLoadQuery( 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 (
- + {data.currentUser && ( + + )} = ({ createdAt paidAmountCents receivedAmount - currency { - name - } __typename } } @@ -68,9 +66,6 @@ export const ExchangeHistory: FC = ({ paidAmount receivedAmountCents createdAt - currency { - name - } __typename } } @@ -95,7 +90,7 @@ export const ExchangeHistory: FC = ({ 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 = ({ 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 = ({ return null; }); - if (!orderRows.length) return null; + if (!orderRows.length) return ; return (
diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_buyCryptoOrders.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_buyCryptoOrders.graphql.ts index f84084c..e0fe78a 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_buyCryptoOrders.graphql.ts +++ b/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_buyCryptoOrders.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_sellCryptoOrders.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_sellCryptoOrders.graphql.ts index 20022fb..3b57ddb 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_sellCryptoOrders.graphql.ts +++ b/app/javascript/src/pages/Orders/Exchange/ExchangeHistory/__generated__/ExchangeHistory_sellCryptoOrders.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/ExchangePanel.tsx b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/ExchangePanel.tsx index 658bb30..ce98d57 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/ExchangePanel.tsx +++ b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/ExchangePanel.tsx @@ -36,30 +36,19 @@ export const ExchangePanel: FC = ({ const [cryptoDock, setCryptoDock] = useState("0"); const [fiatDock, setFiatDock] = useState("0.00"); - const fiatBalances = useFragment( + const fiatBalance = useFragment( graphql` - fragment ExchangePanel_fiatBalances on FiatBalanceConnection { - edges { - node { - amountCents - } - } + fragment ExchangePanel_fiatBalances on FiatBalance { + amountCents } `, fiatBalancesRefs ); - const balances = useFragment( + const balance = useFragment( 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 = ({ if (!isAuthenticated) return ; - 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 = ({ 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 = ({ > {exchangeOption === "SELL" ? "CAKE" : "BRL"} disponível:{" "} - {exchangeOption === "SELL" ? crypto.node.amount : avaliableFiat} + {exchangeOption === "SELL" ? balance.amount : 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 index f6d2da2..5b92977 100644 --- 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 @@ -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; 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 index 9860210..a3e688f 100644 --- 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 @@ -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; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createBuyCryptoOrderMutation.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createBuyCryptoOrderMutation.graphql.ts index d4fd5be..b2b8f9c 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createBuyCryptoOrderMutation.graphql.ts +++ b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createBuyCryptoOrderMutation.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createSellCryptoOrderMutation.graphql.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createSellCryptoOrderMutation.graphql.ts index 0ea924e..4035c59 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createSellCryptoOrderMutation.graphql.ts +++ b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/__generated__/createSellCryptoOrderMutation.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createBuyCryptoOrder.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createBuyCryptoOrder.ts index e5a098d..ad50e9f 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createBuyCryptoOrder.ts +++ b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createBuyCryptoOrder.ts @@ -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(); }, diff --git a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createSellCryptoOrder.ts b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createSellCryptoOrder.ts index d285f43..1033bb3 100644 --- a/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createSellCryptoOrder.ts +++ b/app/javascript/src/pages/Orders/Exchange/ExchangePanel/createSellCryptoOrder.ts @@ -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(); }, 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 3ce39a2..3e1114a 100644 --- a/app/javascript/src/pages/Orders/Exchange/__generated__/ExchangeQuery.graphql.ts +++ b/app/javascript/src/pages/Orders/Exchange/__generated__/ExchangeQuery.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Wallet/Balance.tsx b/app/javascript/src/pages/Wallet/Balance.tsx new file mode 100644 index 0000000..9dd5f12 --- /dev/null +++ b/app/javascript/src/pages/Wallet/Balance.tsx @@ -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 = ({ balancesRef }) => { + const node = useFragment( + graphql` + fragment Balance_balance on Balance { + amount + } + `, + balancesRef + ); + + if (!node) return null; + + return ( +
+
+ + + + + + + + + + + + + +
+ Moeda + + Saldo +
+
+
+ CAKE icon +
+
+

CAKE

+
+
+
+

+ {node.amount} +

+
+
+
+ ); +}; diff --git a/app/javascript/src/pages/Wallet/Balances.tsx b/app/javascript/src/pages/Wallet/Balances.tsx deleted file mode 100644 index 9c4473d..0000000 --- a/app/javascript/src/pages/Wallet/Balances.tsx +++ /dev/null @@ -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 = ({ balancesRef }) => { - const { edges } = useFragment( - graphql` - fragment Balances_balances on BalanceConnection { - edges { - node { - id - amount - currency { - name - } - } - } - } - `, - balancesRef - ); - - if (!edges.length) return null; - - return ( -
-
- - - - - - - - - {edges.map(({ node }) => { - return ( - - - - - ); - })} - -
- Moeda - - Saldo -
-
-
- {`${node.currency.name} -
-
-

- {node.currency.name} -

-
-
-
-

- {node.amount} -

-
-
-
- ); -}; diff --git a/app/javascript/src/pages/Wallet/FiatBalances.tsx b/app/javascript/src/pages/Wallet/FiatBalance.tsx similarity index 76% rename from app/javascript/src/pages/Wallet/FiatBalances.tsx rename to app/javascript/src/pages/Wallet/FiatBalance.tsx index c6fa6d4..162a162 100644 --- a/app/javascript/src/pages/Wallet/FiatBalances.tsx +++ b/app/javascript/src/pages/Wallet/FiatBalance.tsx @@ -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 = ({ fiatBalancesRef }) => { - const { edges } = useFragment( +export const FiatBalance: FC = ({ fiatBalancesRef }) => { + const userFiatBalance = useFragment( 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); diff --git a/app/javascript/src/pages/Wallet/Wallet.tsx b/app/javascript/src/pages/Wallet/Wallet.tsx index 891a31c..65dbac1 100644 --- a/app/javascript/src/pages/Wallet/Wallet.tsx +++ b/app/javascript/src/pages/Wallet/Wallet.tsx @@ -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( + const { currentUser } = useLazyLoadQuery( graphql` query WalletQuery { - fiatBalances { - ...FiatBalances_fiatBalances - } - balances { - ...Balances_balances + currentUser { + fiatBalance { + ...FiatBalance_fiatBalance + } + balance { + ...Balance_balance + } } } `, {} ); - if (!isAuthenticated) return ; + if (!isAuthenticated || !currentUser) return ; return (
- - + +
diff --git a/app/javascript/src/pages/Wallet/__generated__/Balance_balance.graphql.ts b/app/javascript/src/pages/Wallet/__generated__/Balance_balance.graphql.ts new file mode 100644 index 0000000..4a7217b --- /dev/null +++ b/app/javascript/src/pages/Wallet/__generated__/Balance_balance.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Wallet/__generated__/Balances_balances.graphql.ts b/app/javascript/src/pages/Wallet/__generated__/Balances_balances.graphql.ts deleted file mode 100644 index da224c7..0000000 --- a/app/javascript/src/pages/Wallet/__generated__/Balances_balances.graphql.ts +++ /dev/null @@ -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; diff --git a/app/javascript/src/pages/Wallet/__generated__/FiatBalance_fiatBalance.graphql.ts b/app/javascript/src/pages/Wallet/__generated__/FiatBalance_fiatBalance.graphql.ts new file mode 100644 index 0000000..7b34332 --- /dev/null +++ b/app/javascript/src/pages/Wallet/__generated__/FiatBalance_fiatBalance.graphql.ts @@ -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; diff --git a/app/javascript/src/pages/Wallet/__generated__/FiatBalances_fiatBalances.graphql.ts b/app/javascript/src/pages/Wallet/__generated__/FiatBalances_fiatBalances.graphql.ts deleted file mode 100644 index a0e22c0..0000000 --- a/app/javascript/src/pages/Wallet/__generated__/FiatBalances_fiatBalances.graphql.ts +++ /dev/null @@ -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; diff --git a/app/javascript/src/pages/Wallet/__generated__/WalletQuery.graphql.ts b/app/javascript/src/pages/Wallet/__generated__/WalletQuery.graphql.ts index 6854bd6..9a892e7 100644 --- a/app/javascript/src/pages/Wallet/__generated__/WalletQuery.graphql.ts +++ b/app/javascript/src/pages/Wallet/__generated__/WalletQuery.graphql.ts @@ -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; diff --git a/app/models/balance.rb b/app/models/balance.rb index 1020d1e..65dde6e 100644 --- a/app/models/balance.rb +++ b/app/models/balance.rb @@ -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 } diff --git a/app/models/buy_crypto_order.rb b/app/models/buy_crypto_order.rb index 9ecdb52..7ebe81d 100644 --- a/app/models/buy_crypto_order.rb +++ b/app/models/buy_crypto_order.rb @@ -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 diff --git a/app/models/currency.rb b/app/models/currency.rb deleted file mode 100644 index 1b32a3a..0000000 --- a/app/models/currency.rb +++ /dev/null @@ -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 diff --git a/app/models/sell_crypto_order.rb b/app/models/sell_crypto_order.rb index 2b64346..7f869d2 100644 --- a/app/models/sell_crypto_order.rb +++ b/app/models/sell_crypto_order.rb @@ -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 diff --git a/app/models/stake_order.rb b/app/models/stake_order.rb index 7d3d8b6..b5f9561 100644 --- a/app/models/stake_order.rb +++ b/app/models/stake_order.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 8ad27cb..380efb8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/services/create_user_balances.rb b/app/services/create_user_balances.rb index 885693f..3fac56e 100644 --- a/app/services/create_user_balances.rb +++ b/app/services/create_user_balances.rb @@ -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 diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 139e33b..17a2610 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -9,10 +9,6 @@ pt-BR: one: Administrador other: Administradores - currency: - one: Moeda - other: Moedas - balance: one: Saldo other: Saldos @@ -46,9 +42,6 @@ pt-BR: amount_formatted: Quantia amount_cents: Quantia - currency: - name: Nome - errors: models: balance: diff --git a/db/migrate/20210828041104_drop_currency.rb b/db/migrate/20210828041104_drop_currency.rb new file mode 100644 index 0000000..38dd0c4 --- /dev/null +++ b/db/migrate/20210828041104_drop_currency.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true +class DropCurrency < ActiveRecord::Migration[6.1] + def up + remove_reference(:balances, :currency, index: true, foreign_key: true) + remove_reference(:buy_crypto_orders, :currency, index: true, foreign_key: true) + remove_reference(:sell_crypto_orders, :currency, index: true, foreign_key: true) + remove_reference(:stake_orders, :currency, index: true, foreign_key: true) + + drop_table(:currencies) + end +end diff --git a/db/schema.rb b/db/schema.rb index e907945..0dccd51 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_18_185019) do +ActiveRecord::Schema.define(version: 2021_08_28_041104) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -57,32 +57,22 @@ ActiveRecord::Schema.define(version: 2021_08_18_185019) do create_table "balances", force: :cascade do |t| t.bigint "user_id", null: false - t.bigint "currency_id", null: false t.decimal "amount", precision: 20, scale: 10, default: "0.0", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["currency_id"], name: "index_balances_on_currency_id" t.index ["user_id"], name: "index_balances_on_user_id" end create_table "buy_crypto_orders", force: :cascade do |t| t.bigint "user_id", null: false - t.bigint "currency_id", null: false t.string "status", null: false t.integer "paid_amount_cents", default: 0, null: false t.decimal "received_amount", precision: 20, scale: 10, default: "0.0", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["currency_id"], name: "index_buy_crypto_orders_on_currency_id" t.index ["user_id"], name: "index_buy_crypto_orders_on_user_id" end - create_table "currencies", force: :cascade do |t| - t.string "name", null: false - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - end - create_table "fiat_balances", force: :cascade do |t| t.bigint "user_id", null: false t.integer "amount_cents", default: 0, null: false @@ -94,13 +84,11 @@ ActiveRecord::Schema.define(version: 2021_08_18_185019) do create_table "sell_crypto_orders", force: :cascade do |t| t.bigint "user_id", null: false - t.bigint "currency_id", null: false t.string "status", null: false t.decimal "paid_amount", precision: 20, scale: 10, default: "0.0", null: false t.integer "received_amount_cents", default: 0, null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.index ["currency_id"], name: "index_sell_crypto_orders_on_currency_id" t.index ["user_id"], name: "index_sell_crypto_orders_on_user_id" end @@ -111,8 +99,6 @@ ActiveRecord::Schema.define(version: 2021_08_18_185019) do t.decimal "amount", precision: 20, scale: 10, default: "0.0", null: false t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.bigint "currency_id" - t.index ["currency_id"], name: "index_stake_orders_on_currency_id" t.index ["user_id"], name: "index_stake_orders_on_user_id" end @@ -151,14 +137,10 @@ ActiveRecord::Schema.define(version: 2021_08_18_185019) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" - add_foreign_key "balances", "currencies" add_foreign_key "balances", "users" - add_foreign_key "buy_crypto_orders", "currencies" add_foreign_key "buy_crypto_orders", "users" add_foreign_key "fiat_balances", "users" - add_foreign_key "sell_crypto_orders", "currencies" add_foreign_key "sell_crypto_orders", "users" - add_foreign_key "stake_orders", "currencies" add_foreign_key "stake_orders", "users" add_foreign_key "user_documents", "users" end diff --git a/db/seeds.rb b/db/seeds.rb index 1d01dc6..40b2083 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,8 +2,6 @@ AdminUser.create!(email: "admin@example.com", password: "password") -Currency.create!(name: "CAKE") - User.create!( first_name: "Test", last_name: "User", diff --git a/erd.svg b/erd.svg index 72c6180..ff3afa3 100644 --- a/erd.svg +++ b/erd.svg @@ -4,222 +4,180 @@ - - + + XStake - -XStake domain model + +XStake domain model m_AdminUser - -AdminUser - -email -string ∗ U -encrypted_password -string ∗ -remember_created_at -datetime -reset_password_sent_at -datetime -reset_password_token -string + +AdminUser + +email +string ∗ U +encrypted_password +string ∗ +remember_created_at +datetime +reset_password_sent_at +datetime +reset_password_token +string m_Balance - -Balance - -amount -decimal (20,10) ∗ -currency_id -integer (8) ∗ FK -user_id -integer (8) ∗ FK + +Balance + +amount +decimal (20,10) ∗ +user_id +integer (8) ∗ FK - + m_PaperTrail::Version - -PaperTrail::Version - -event -string ∗ -item_id -integer (8) ∗ FK -item_type -string ∗ -object -text -whodunnit -string + +PaperTrail::Version + +event +string ∗ +item_id +integer (8) ∗ FK +item_type +string ∗ +object +text +whodunnit +string m_Balance->m_PaperTrail::Version - - + + m_BuyCryptoOrder - -BuyCryptoOrder - -currency_id -integer (8) ∗ FK -paid_amount_cents -integer ∗ -received_amount -decimal (20,10) ∗ -status -string ∗ -user_id -integer (8) ∗ FK - - - -m_Currency - -Currency - -name -string ∗ - - - -m_Currency->m_Balance - - - - - -m_Currency->m_BuyCryptoOrder - - - - - -m_SellCryptoOrder - -SellCryptoOrder - -currency_id -integer (8) ∗ FK -paid_amount -decimal (20,10) ∗ -received_amount_cents -integer ∗ -status -string ∗ -user_id -integer (8) ∗ FK - - - -m_Currency->m_SellCryptoOrder - - - - - -m_StakeOrder - -StakeOrder - -amount -decimal (20,10) ∗ -currency_id -integer (8) FK -pool_name -string ∗ -status -string ∗ -user_id -integer (8) ∗ FK - - - -m_Currency->m_StakeOrder - - + +BuyCryptoOrder + +paid_amount_cents +integer ∗ +received_amount +decimal (20,10) ∗ +status +string ∗ +user_id +integer (8) ∗ FK - + m_FiatBalance - -FiatBalance - -amount_cents -integer ∗ -amount_currency -string ∗ -user_id -integer (8) ∗ FK + +FiatBalance + +amount_cents +integer ∗ +amount_currency +string ∗ +user_id +integer (8) ∗ FK m_FiatBalance->m_PaperTrail::Version - - + + + + + +m_SellCryptoOrder + +SellCryptoOrder + +paid_amount +decimal (20,10) ∗ +received_amount_cents +integer ∗ +status +string ∗ +user_id +integer (8) ∗ FK + + + +m_StakeOrder + +StakeOrder + +amount +decimal (20,10) ∗ +pool_name +string ∗ +status +string ∗ +user_id +integer (8) ∗ FK - + m_User - -User - -email -string ∗ U -encrypted_password -string ∗ -first_name -string ∗ -last_name -string ∗ -remember_created_at -datetime -reset_password_sent_at -datetime -reset_password_token -string -wallet_address -string + +User + +email +string ∗ U +encrypted_password +string ∗ +first_name +string ∗ +last_name +string ∗ +remember_created_at +datetime +reset_password_sent_at +datetime +reset_password_token +string +wallet_address +string m_User->m_Balance - - + m_User->m_BuyCryptoOrder - - + + m_User->m_FiatBalance - + - + m_User->m_SellCryptoOrder - - + + m_User->m_StakeOrder - - + + - + m_UserDocument UserDocument @@ -232,8 +190,8 @@ m_User->m_UserDocument - - + + diff --git a/spec/factories/balances.rb b/spec/factories/balances.rb index 1aa9df3..b66c721 100644 --- a/spec/factories/balances.rb +++ b/spec/factories/balances.rb @@ -4,27 +4,23 @@ # # 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) # FactoryBot.define do factory :balance do association :user - association :currency amount { (rand * (10000 - 0) + 0) } end end diff --git a/spec/factories/buy_crypto_orders.rb b/spec/factories/buy_crypto_orders.rb index aad2aa1..b29e1ff 100644 --- a/spec/factories/buy_crypto_orders.rb +++ b/spec/factories/buy_crypto_orders.rb @@ -10,23 +10,19 @@ # 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) # FactoryBot.define do factory :buy_crypto_order do association :user - association :currency status { :processing } paid_amount_cents { rand(10000) } received_amount { rand * 10000 } diff --git a/spec/factories/currencies.rb b/spec/factories/currencies.rb deleted file mode 100644 index e294e90..0000000 --- a/spec/factories/currencies.rb +++ /dev/null @@ -1,16 +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 -# -FactoryBot.define do - factory :currency do - name { "CAKE" } - end -end diff --git a/spec/factories/sell_crypto_orders.rb b/spec/factories/sell_crypto_orders.rb index fc702fb..5bed1d1 100644 --- a/spec/factories/sell_crypto_orders.rb +++ b/spec/factories/sell_crypto_orders.rb @@ -10,23 +10,19 @@ # 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) # FactoryBot.define do factory :sell_crypto_order do association :user - association :currency status { :processing } received_amount_cents { rand(10000) } paid_amount { rand * 10000 } diff --git a/spec/factories/stake_orders.rb b/spec/factories/stake_orders.rb index 67d19b8..ef6182f 100644 --- a/spec/factories/stake_orders.rb +++ b/spec/factories/stake_orders.rb @@ -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) # FactoryBot.define do diff --git a/spec/graphql/inputs/create_buy_crypto_order_attributes_input_spec.rb b/spec/graphql/inputs/create_buy_crypto_order_attributes_input_spec.rb index 84a1cbc..d7a3386 100644 --- a/spec/graphql/inputs/create_buy_crypto_order_attributes_input_spec.rb +++ b/spec/graphql/inputs/create_buy_crypto_order_attributes_input_spec.rb @@ -6,7 +6,6 @@ describe Inputs::CreateBuyCryptoOrderAttributesInput do subject { described_class } describe "fields" do - it { is_expected.to(accept_argument("currency_id").of_type("ID!")) } it { is_expected.to(accept_argument("amount_cents").of_type("Int!")) } end end diff --git a/spec/graphql/inputs/create_sell_crypto_order_attributes_input_spec.rb b/spec/graphql/inputs/create_sell_crypto_order_attributes_input_spec.rb index 84607d7..bfe9cc9 100644 --- a/spec/graphql/inputs/create_sell_crypto_order_attributes_input_spec.rb +++ b/spec/graphql/inputs/create_sell_crypto_order_attributes_input_spec.rb @@ -6,7 +6,6 @@ describe Inputs::CreateSellCryptoOrderAttributesInput do subject { described_class } describe "fields" do - it { is_expected.to(accept_argument("currency_id").of_type("ID!")) } it { is_expected.to(accept_argument("amount").of_type("String!")) } end end diff --git a/spec/graphql/mutations/create_buy_crypto_order_spec.rb b/spec/graphql/mutations/create_buy_crypto_order_spec.rb index 2938694..e22c026 100644 --- a/spec/graphql/mutations/create_buy_crypto_order_spec.rb +++ b/spec/graphql/mutations/create_buy_crypto_order_spec.rb @@ -5,10 +5,9 @@ require "rails_helper" RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do let(:query_string) do <<~GQL - mutation($currencyId: ID!, $amountCents: Int!) { + mutation($amountCents: Int!) { createBuyCryptoOrder(input: { order: { - currencyId: $currencyId, amountCents: $amountCents, } }) { @@ -22,9 +21,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do status paidAmountCents receivedAmount - currency { - name - } } } } @@ -33,7 +29,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do context "when the user has enough balance" do it "withdraws from his account and creates a buy order" do - currency = create(:currency) user = create( :user, fiat_balance: build( @@ -42,10 +37,7 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do ), ) - currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id) - variables = { - "currencyId": currency_global_id, "amountCents": 90_00, } @@ -65,9 +57,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do "status" => "PROCESSING", "paidAmountCents" => 90_00, "receivedAmount" => "0.0", - "currency" => { - "name" => "CAKE", - }, }, }, }, @@ -79,7 +68,6 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do context "when the user does not have enough balance" do it "returns withdrawl error" do - currency = create(:currency) user = create( :user, fiat_balance: build( @@ -88,10 +76,7 @@ RSpec.describe(Mutations::CreateBuyCryptoOrder, type: :mutation) do ), ) - currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id) - variables = { - "currencyId": currency_global_id, "amountCents": 90_00, } diff --git a/spec/graphql/mutations/create_sell_crypto_order_spec.rb b/spec/graphql/mutations/create_sell_crypto_order_spec.rb index 0b7c57f..531871c 100644 --- a/spec/graphql/mutations/create_sell_crypto_order_spec.rb +++ b/spec/graphql/mutations/create_sell_crypto_order_spec.rb @@ -5,10 +5,9 @@ require "rails_helper" RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do let(:query_string) do <<~GQL - mutation($currencyId: ID!, $amount: String!) { + mutation($amount: String!) { createSellCryptoOrder(input: { order: { - currencyId: $currencyId, amount: $amount, } }) { @@ -22,9 +21,6 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do status paidAmount receivedAmountCents - currency { - name - } } } } @@ -33,18 +29,12 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do context "when the user has enough balance" do it "withdraws from his account and creates a buy order" do - currency = create(:currency) user = create( :user, - balances: [ - build(:balance, currency: currency, amount: 1.0034), - ] + balance: build(:balance, amount: 1.0034) ) - currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id) - variables = { - "currencyId": currency_global_id, "amount": "0.80", } @@ -64,32 +54,23 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do "status" => "PROCESSING", "paidAmount" => "0.8", "receivedAmountCents" => 0, - "currency" => { - "name" => "CAKE", - }, }, }, }, })) - expect(user.balances.first.reload.amount.to_s).to(eq("0.2034")) + expect(user.balance.reload.amount.to_s).to(eq("0.2034")) end end context "when the user does not have enough balance" do it "returns withdrawl error" do - currency = create(:currency) user = create( :user, - balances: [ - build(:balance, currency: currency, amount: 0.0034), - ] + balance: build(:balance, amount: 0.0034) ) - currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id) - variables = { - "currencyId": currency_global_id, "amount": "0.80", } @@ -115,7 +96,7 @@ RSpec.describe(Mutations::CreateSellCryptoOrder, type: :mutation) do }, })) - expect(user.balances.first.reload.amount.to_s).to(eq("0.0034")) + expect(user.balance.reload.amount.to_s).to(eq("0.0034")) end end end diff --git a/spec/graphql/mutations/create_stake_order_spec.rb b/spec/graphql/mutations/create_stake_order_spec.rb index 54f16ef..98f3b4a 100644 --- a/spec/graphql/mutations/create_stake_order_spec.rb +++ b/spec/graphql/mutations/create_stake_order_spec.rb @@ -33,12 +33,9 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do context "when the user has enough balance" do it "withdraws from his account and creates a buy order" do - currency = create(:currency) user = create( :user, - balances: [ - build(:balance, currency: currency, amount: 1.0034), - ] + balance: build(:balance, amount: 1.0034) ) variables = { @@ -68,18 +65,15 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do }, })) - expect(user.balances.first.reload.amount.to_s).to(eq("0.2034")) + expect(user.balance.reload.amount.to_s).to(eq("0.2034")) end end context "when the user does not have enough balance" do it "returns withdrawl error" do - currency = create(:currency) user = create( :user, - balances: [ - build(:balance, currency: currency, amount: 0.0034), - ] + balance: build(:balance, amount: 0.0034) ) variables = { @@ -109,7 +103,7 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do }, })) - expect(user.balances.first.reload.amount.to_s).to(eq("0.0034")) + expect(user.balance.reload.amount.to_s).to(eq("0.0034")) end end end diff --git a/spec/graphql/mutations/create_stake_remove_order_spec.rb b/spec/graphql/mutations/create_stake_remove_order_spec.rb index ea034f8..40c8547 100644 --- a/spec/graphql/mutations/create_stake_remove_order_spec.rb +++ b/spec/graphql/mutations/create_stake_remove_order_spec.rb @@ -33,12 +33,9 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do context "when the user has enough balance" do it "withdraws from his account and creates a buy order" do - currency = create(:currency) user = create( :user, - balances: [ - build(:balance, currency: currency, amount: 0), - ] + balance: build(:balance, amount: 0) ) variables = { @@ -72,15 +69,12 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do context "when it repeats the mutation with a request in `processing`" do it "update amount from the order" do - currency = create(:currency) user = create( :user, - balances: [ - build(:balance, currency: currency, amount: 0), - ] + balance: build(:balance, amount: 0) ) - create(:stake_order, amount: -200.8, user: user, pool_name: "CAKE/BNB", currency: currency) + create(:stake_order, amount: -200.8, user: user, pool_name: "CAKE/BNB") variables = { "amount": "200.80", diff --git a/spec/graphql/types/buy_crypto_order_type_spec.rb b/spec/graphql/types/buy_crypto_order_type_spec.rb index 27ed225..395d916 100644 --- a/spec/graphql/types/buy_crypto_order_type_spec.rb +++ b/spec/graphql/types/buy_crypto_order_type_spec.rb @@ -6,7 +6,6 @@ RSpec.describe(Types::BuyCryptoOrderType) do describe "arguments" do it { is_expected.to(have_a_field(:id).of_type("ID!")) } - it { is_expected.to(have_a_field(:currency).of_type("Currency!")) } it { is_expected.to(have_a_field(:paid_amount_cents).of_type("Int!")) } it { is_expected.to(have_a_field(:received_amount).of_type("String")) } it { is_expected.to(have_a_field(:status).of_type("ProcessStatus!")) } diff --git a/spec/graphql/types/sell_crypto_order_type_spec.rb b/spec/graphql/types/sell_crypto_order_type_spec.rb index 65b2e67..ca4de78 100644 --- a/spec/graphql/types/sell_crypto_order_type_spec.rb +++ b/spec/graphql/types/sell_crypto_order_type_spec.rb @@ -6,7 +6,6 @@ RSpec.describe(Types::SellCryptoOrderType) do describe "arguments" do it { is_expected.to(have_a_field(:id).of_type("ID!")) } - it { is_expected.to(have_a_field(:currency).of_type("Currency!")) } it { is_expected.to(have_a_field(:paid_amount).of_type("String!")) } it { is_expected.to(have_a_field(:received_amount_cents).of_type("Int")) } it { is_expected.to(have_a_field(:status).of_type("ProcessStatus!")) } diff --git a/spec/models/balance_spec.rb b/spec/models/balance_spec.rb index 0a3c3cf..1180747 100644 --- a/spec/models/balance_spec.rb +++ b/spec/models/balance_spec.rb @@ -4,21 +4,18 @@ # # 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) # require "rails_helper" @@ -30,7 +27,6 @@ RSpec.describe(Balance, type: :model) do describe "associations" do it { is_expected.to(belong_to(:user)) } - it { is_expected.to(belong_to(:currency)) } end describe ".withdrwal!" do diff --git a/spec/models/buy_crypto_order_spec.rb b/spec/models/buy_crypto_order_spec.rb index c17bd56..05e9aca 100644 --- a/spec/models/buy_crypto_order_spec.rb +++ b/spec/models/buy_crypto_order_spec.rb @@ -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) # require "rails_helper" @@ -51,6 +48,5 @@ RSpec.describe(BuyCryptoOrder, type: :model) do describe "associations" do it { is_expected.to(belong_to(:user)) } - it { is_expected.to(belong_to(:currency)) } end end diff --git a/spec/models/currency_spec.rb b/spec/models/currency_spec.rb deleted file mode 100644 index 85691fd..0000000 --- a/spec/models/currency_spec.rb +++ /dev/null @@ -1,18 +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 -# -require "rails_helper" - -RSpec.describe(Currency, type: :model) do - describe "validations" do - it { is_expected.to(validate_presence_of(:name)) } - end -end diff --git a/spec/models/sell_crypto_order_spec.rb b/spec/models/sell_crypto_order_spec.rb index c453847..9a8528d 100644 --- a/spec/models/sell_crypto_order_spec.rb +++ b/spec/models/sell_crypto_order_spec.rb @@ -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) # require "rails_helper" @@ -51,6 +48,5 @@ RSpec.describe(SellCryptoOrder, type: :model) do describe "associations" do it { is_expected.to(belong_to(:user)) } - it { is_expected.to(belong_to(:currency)) } end end diff --git a/spec/models/stake_order_spec.rb b/spec/models/stake_order_spec.rb index 2cb1448..c2f0cf5 100644 --- a/spec/models/stake_order_spec.rb +++ b/spec/models/stake_order_spec.rb @@ -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) # require "rails_helper" @@ -33,6 +30,5 @@ RSpec.describe(StakeOrder, type: :model) do describe "associations" do it { is_expected.to(belong_to(:user)) } - it { is_expected.to(belong_to(:currency)) } end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ca81c81..362feac 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -33,7 +33,7 @@ RSpec.describe(User, type: :model) do describe "associations" do it { is_expected.to(have_many(:documents)) } it { is_expected.to(have_many(:stake_orders)) } - it { is_expected.to(have_many(:balances)) } + it { is_expected.to(have_one(:balance)) } it { is_expected.to(have_one(:fiat_balance)) } end end