From d21bd334360fd94f8f1e454b8b4ef86b1e50d93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Wed, 18 Aug 2021 15:58:04 -0300 Subject: [PATCH] add wallet address to user --- app/dashboards/user_dashboard.rb | 10 +- app/graphql/types/user_type.rb | 4 +- app/javascript/__generated__/schema.graphql | 2 +- .../src/__generated__/AppQuery.graphql.ts | 12 +- app/javascript/src/contexts/UserProvider.tsx | 3 + .../UserProvider_user.graphql.ts | 10 +- app/models/user.rb | 5 +- ...210818185019_add_wallet_address_to_user.rb | 6 + db/schema.rb | 3 +- erd.svg | 146 ++++++++++-------- spec/factories/users.rb | 1 + spec/graphql/types/user_type_spec.rb | 4 +- spec/models/user_spec.rb | 1 + spec/requests/home_spec.rb | 4 +- 14 files changed, 125 insertions(+), 86 deletions(-) create mode 100644 db/migrate/20210818185019_add_wallet_address_to_user.rb diff --git a/app/dashboards/user_dashboard.rb b/app/dashboards/user_dashboard.rb index 41e33f7..ead8ca2 100644 --- a/app/dashboards/user_dashboard.rb +++ b/app/dashboards/user_dashboard.rb @@ -10,10 +10,10 @@ class UserDashboard < Administrate::BaseDashboard # on pages throughout the dashboard. ATTRIBUTE_TYPES = { id: Field::Number, - full_name: Field::String, + email: Field::String, first_name: Field::String, last_name: Field::String, - email: Field::String, + wallet_address: Field::String, created_at: Field::DateTime, updated_at: Field::DateTime, }.freeze @@ -23,16 +23,16 @@ class UserDashboard < 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 = [:full_name, :email].freeze + COLLECTION_ATTRIBUTES = [:id, :first_name, :last_name, :wallet_address, :email].freeze # SHOW_PAGE_ATTRIBUTES # an array of attributes that will be displayed on the model's show page. - SHOW_PAGE_ATTRIBUTES = [:id, :first_name, :last_name, :email, :created_at, :updated_at].freeze + SHOW_PAGE_ATTRIBUTES = [:id, :first_name, :last_name, :wallet_address, :email, :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 = [:first_name, :last_name].freeze + FORM_ATTRIBUTES = [:first_name, :last_name, :wallet_address].freeze # COLLECTION_FILTERS # a hash that defines filters that can be used while searching via the search diff --git a/app/graphql/types/user_type.rb b/app/graphql/types/user_type.rb index efd0c7b..b52c493 100644 --- a/app/graphql/types/user_type.rb +++ b/app/graphql/types/user_type.rb @@ -7,9 +7,9 @@ module Types graphql_name "User" field :id, ID, null: false + field :email, String, null: false field :first_name, String, null: false field :last_name, String, null: false - field :full_name, String, null: false - field :email, String, null: false + field :wallet_address, String, null: true end end diff --git a/app/javascript/__generated__/schema.graphql b/app/javascript/__generated__/schema.graphql index a627303..c046336 100644 --- a/app/javascript/__generated__/schema.graphql +++ b/app/javascript/__generated__/schema.graphql @@ -506,7 +506,7 @@ type StakeOrderEdge { type User { email: String! firstName: String! - fullName: String! id: ID! lastName: String! + walletAddress: String } diff --git a/app/javascript/src/__generated__/AppQuery.graphql.ts b/app/javascript/src/__generated__/AppQuery.graphql.ts index 1a9ad9b..71f5f3f 100644 --- a/app/javascript/src/__generated__/AppQuery.graphql.ts +++ b/app/javascript/src/__generated__/AppQuery.graphql.ts @@ -27,6 +27,7 @@ query AppQuery { fragment UserProvider_user on User { firstName + walletAddress } */ @@ -78,6 +79,13 @@ const node: ConcreteRequest = { "name": "firstName", "storageKey": null }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "walletAddress", + "storageKey": null + }, { "alias": null, "args": null, @@ -91,12 +99,12 @@ const node: ConcreteRequest = { ] }, "params": { - "cacheID": "ce9692d3fdea00e7368e2a6404748f16", + "cacheID": "56b4be302cf9b9ec226ad8145170961b", "id": null, "metadata": {}, "name": "AppQuery", "operationKind": "query", - "text": "query AppQuery {\n currentUser {\n ...UserProvider_user\n id\n }\n}\n\nfragment UserProvider_user on User {\n firstName\n}\n" + "text": "query AppQuery {\n currentUser {\n ...UserProvider_user\n id\n }\n}\n\nfragment UserProvider_user on User {\n firstName\n walletAddress\n}\n" } }; (node as any).hash = 'aac57a65620cf50754d54f3c8d6495cf'; diff --git a/app/javascript/src/contexts/UserProvider.tsx b/app/javascript/src/contexts/UserProvider.tsx index ab60bfe..6d295e8 100644 --- a/app/javascript/src/contexts/UserProvider.tsx +++ b/app/javascript/src/contexts/UserProvider.tsx @@ -8,6 +8,7 @@ import type { UserProvider_user$key } from "./__generated__/UserProvider_user.gr type CurrentUserContext = { user: { firstName: string; + walletAddress: string | null; } | null; isAuthenticated: boolean; }; @@ -32,6 +33,7 @@ export const UserProvider: FC = ({ userRef, children }) => { graphql` fragment UserProvider_user on User { firstName + walletAddress } `, userRef @@ -40,6 +42,7 @@ export const UserProvider: FC = ({ userRef, children }) => { const user = userData ? { firstName: userData.firstName, + walletAddress: userData.walletAddress, } : null; diff --git a/app/javascript/src/contexts/__generated__/UserProvider_user.graphql.ts b/app/javascript/src/contexts/__generated__/UserProvider_user.graphql.ts index 5520642..46f7aa4 100644 --- a/app/javascript/src/contexts/__generated__/UserProvider_user.graphql.ts +++ b/app/javascript/src/contexts/__generated__/UserProvider_user.graphql.ts @@ -6,6 +6,7 @@ import { ReaderFragment } from "relay-runtime"; import { FragmentRefs } from "relay-runtime"; export type UserProvider_user = { readonly firstName: string; + readonly walletAddress: string | null; readonly " $refType": "UserProvider_user"; }; export type UserProvider_user$data = UserProvider_user; @@ -28,10 +29,17 @@ const node: ReaderFragment = { "kind": "ScalarField", "name": "firstName", "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "walletAddress", + "storageKey": null } ], "type": "User", "abstractKey": null }; -(node as any).hash = '352cdd208485d062f3f7c2e22e287a99'; +(node as any).hash = 'ef997d2646b4d39178c6f3318509a7cb'; export default node; diff --git a/app/models/user.rb b/app/models/user.rb index 47c0853..8ad27cb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,7 @@ # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string +# wallet_address :string # created_at :datetime not null # updated_at :datetime not null # @@ -34,10 +35,6 @@ class User < ApplicationRecord validates :first_name, :last_name, :email, presence: true validates :email, uniqueness: true - def full_name - "#{first_name} #{last_name}" - end - after_create do create_balances end diff --git a/db/migrate/20210818185019_add_wallet_address_to_user.rb b/db/migrate/20210818185019_add_wallet_address_to_user.rb new file mode 100644 index 0000000..c08d2c8 --- /dev/null +++ b/db/migrate/20210818185019_add_wallet_address_to_user.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true +class AddWalletAddressToUser < ActiveRecord::Migration[6.1] + def change + add_column(:users, :wallet_address, :string) + end +end diff --git a/db/schema.rb b/db/schema.rb index 89ef41a..e907945 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_17_233439) do +ActiveRecord::Schema.define(version: 2021_08_18_185019) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -134,6 +134,7 @@ ActiveRecord::Schema.define(version: 2021_08_17_233439) do t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" + t.string "wallet_address" t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/erd.svg b/erd.svg index 25c19e1..72c6180 100644 --- a/erd.svg +++ b/erd.svg @@ -4,28 +4,28 @@ - + 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 @@ -40,6 +40,29 @@ user_id integer (8) ∗ FK + + +m_PaperTrail::Version + +PaperTrail::Version + +event +string ∗ +item_id +integer (8) ∗ FK +item_type +string ∗ +object +text +whodunnit +string + + + +m_Balance->m_PaperTrail::Version + + + m_BuyCryptoOrder @@ -67,13 +90,13 @@ string ∗ - + m_Currency->m_Balance - - + + - + m_Currency->m_BuyCryptoOrder @@ -96,7 +119,7 @@ integer (8) ∗ FK - + m_Currency->m_SellCryptoOrder @@ -119,7 +142,7 @@ integer (8) ∗ FK - + m_Currency->m_StakeOrder @@ -137,69 +160,60 @@ user_id integer (8) ∗ FK - - -m_PaperTrail::Version - -PaperTrail::Version - -event -string ∗ -item_id -integer (8) ∗ -item_type -string ∗ -object -text -whodunnit -string + + +m_FiatBalance->m_PaperTrail::Version + + 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 + +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 @@ -216,10 +230,10 @@ integer (8) ∗ FK - + m_User->m_UserDocument - - + + diff --git a/spec/factories/users.rb b/spec/factories/users.rb index fda8d14..81f3435 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -12,6 +12,7 @@ # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string +# wallet_address :string # created_at :datetime not null # updated_at :datetime not null # diff --git a/spec/graphql/types/user_type_spec.rb b/spec/graphql/types/user_type_spec.rb index ca35ed6..777c5e2 100644 --- a/spec/graphql/types/user_type_spec.rb +++ b/spec/graphql/types/user_type_spec.rb @@ -6,9 +6,9 @@ RSpec.describe(Types::UserType) do describe "arguments" do it { is_expected.to(have_a_field(:id).of_type("ID!")) } + it { is_expected.to(have_a_field(:email).of_type("String!")) } it { is_expected.to(have_a_field(:first_name).of_type("String!")) } it { is_expected.to(have_a_field(:last_name).of_type("String!")) } - it { is_expected.to(have_a_field(:full_name).of_type("String!")) } - it { is_expected.to(have_a_field(:email).of_type("String!")) } + it { is_expected.to(have_a_field(:wallet_address).of_type("String")) } end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index f53c346..ca81c81 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -12,6 +12,7 @@ # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string +# wallet_address :string # created_at :datetime not null # updated_at :datetime not null # diff --git a/spec/requests/home_spec.rb b/spec/requests/home_spec.rb index d8e5638..f6d9d23 100644 --- a/spec/requests/home_spec.rb +++ b/spec/requests/home_spec.rb @@ -2,9 +2,9 @@ require "rails_helper" RSpec.describe("Homes", type: :request) do - describe "GET /index" do + describe "GET /" do it "returns http success" do - get "/home/index" + get "/" expect(response).to(have_http_status(:success)) end end