add commitCreateStakeRemoveRequestMutation
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -28,6 +28,7 @@ gem "money-rails"
|
||||
gem "enumerize"
|
||||
gem "graphql"
|
||||
gem "pundit"
|
||||
gem "ransack", "~> 2.4"
|
||||
|
||||
group :development, :test do
|
||||
gem "dotenv-rails"
|
||||
|
||||
@@ -235,6 +235,10 @@ GEM
|
||||
thor (~> 1.0)
|
||||
rainbow (3.0.0)
|
||||
rake (13.0.6)
|
||||
ransack (2.4.2)
|
||||
activerecord (>= 5.2.4)
|
||||
activesupport (>= 5.2.4)
|
||||
i18n
|
||||
rb-fsevent (0.11.0)
|
||||
rb-inotify (0.10.1)
|
||||
ffi (~> 1.0)
|
||||
@@ -373,6 +377,7 @@ DEPENDENCIES
|
||||
rails (~> 6.1.4)
|
||||
rails-erd
|
||||
rails-i18n (~> 6.0)
|
||||
ransack (~> 2.4)
|
||||
rspec-graphql_matchers (~> 1.3)
|
||||
rspec-rails
|
||||
rubocop-rails
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
module Inputs
|
||||
class CreateStakeOrderAttributesInput < Types::BaseInputObject
|
||||
argument :currency_id, ID, required: true
|
||||
argument :pool_name, String, required: true
|
||||
argument :amount, String, "Amount to be paid", required: true
|
||||
end
|
||||
|
||||
9
app/graphql/inputs/predicate_input.rb
Normal file
9
app/graphql/inputs/predicate_input.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
module Inputs
|
||||
class PredicateInput < Types::BaseInputObject
|
||||
# https://github.com/activerecord-hackery/ransack#search-matchers
|
||||
# add others if necessary
|
||||
argument :eq, String, "Equal", required: false
|
||||
argument :lt, Float, "Less than", required: false
|
||||
end
|
||||
end
|
||||
10
app/graphql/inputs/stake_order_filter_input.rb
Normal file
10
app/graphql/inputs/stake_order_filter_input.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
module Inputs
|
||||
class StakeOrderFilterInput < Types::BaseInputObject
|
||||
StakeOrder.ransackable_attributes.each do |attr|
|
||||
argument attr, PredicateInput, required: false
|
||||
end
|
||||
|
||||
argument :status, [Types::ProcessStatusEnum], required: false
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ module Mutations
|
||||
argument :order, Inputs::CreateStakeOrderAttributesInput, required: true
|
||||
|
||||
def resolve(order:)
|
||||
currency_id = decode_id(order[:currency_id])
|
||||
currency_id = Currency.find_by!(name: "CAKE").id
|
||||
amount = BigDecimal(order[:amount])
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
|
||||
@@ -6,8 +6,8 @@ module Mutations
|
||||
argument :order, Inputs::CreateStakeOrderAttributesInput, required: true
|
||||
|
||||
def resolve(order:)
|
||||
currency_id = decode_id(order[:currency_id])
|
||||
amount = BigDecimal(order[:amount])
|
||||
currency_id = Currency.find_by!(name: "CAKE").id
|
||||
amount = -BigDecimal(order[:amount])
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
record = StakeOrder.find_or_initialize_by(
|
||||
|
||||
21
app/graphql/ransack_support.rb
Normal file
21
app/graphql/ransack_support.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
module RansackSupport
|
||||
def ransack(base, filter)
|
||||
base.ransack(build_ransack_query(base, filter)).result
|
||||
end
|
||||
|
||||
def build_ransack_query(base, filter)
|
||||
filter = filter.to_h
|
||||
mapped_filter = {}
|
||||
|
||||
filter.each do |parent_key, parent_value|
|
||||
next unless base.ransackable_attributes.include?(parent_key.to_s)
|
||||
|
||||
parent_value.each do |children_key, children_value|
|
||||
mapped_filter["#{parent_key}_#{children_key}".to_sym] = children_value
|
||||
end
|
||||
end
|
||||
|
||||
mapped_filter
|
||||
end
|
||||
end
|
||||
@@ -3,6 +3,7 @@ module Types
|
||||
class QueryType < Types::BaseObject
|
||||
include GraphQL::Types::Relay::HasNodeField
|
||||
include GraphQL::Types::Relay::HasNodesField
|
||||
include RansackSupport
|
||||
|
||||
field :current_user, UserType, null: true
|
||||
def current_user
|
||||
@@ -29,9 +30,16 @@ module Types
|
||||
Pundit.policy_scope(current_user, BuyCryptoOrder)
|
||||
end
|
||||
|
||||
field :stake_orders, StakeOrderType.connection_type, null: false
|
||||
def stake_orders
|
||||
Pundit.policy_scope(current_user, StakeOrder)
|
||||
field :stake_orders, StakeOrderType.connection_type, null: false do
|
||||
argument :filter, Inputs::StakeOrderFilterInput, required: false
|
||||
end
|
||||
|
||||
def stake_orders(filter: nil)
|
||||
scope = Pundit.policy_scope(current_user, StakeOrder)
|
||||
|
||||
scope = scope.where(status: filter.status) if filter&.status
|
||||
|
||||
ransack(scope, filter)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
20
app/javascript/__generated__/schema.graphql
generated
20
app/javascript/__generated__/schema.graphql
generated
@@ -149,7 +149,6 @@ input CreateStakeOrderAttributesInput {
|
||||
Amount to be paid
|
||||
"""
|
||||
amount: String!
|
||||
currencyId: ID!
|
||||
poolName: String!
|
||||
}
|
||||
|
||||
@@ -315,6 +314,18 @@ type PageInfo {
|
||||
startCursor: String
|
||||
}
|
||||
|
||||
input PredicateInput {
|
||||
"""
|
||||
Equal
|
||||
"""
|
||||
eq: String
|
||||
|
||||
"""
|
||||
Less than
|
||||
"""
|
||||
lt: Float
|
||||
}
|
||||
|
||||
enum ProcessStatus {
|
||||
CANCELED
|
||||
COMPLETED
|
||||
@@ -437,6 +448,7 @@ type Query {
|
||||
Returns the elements in the list that come before the specified cursor.
|
||||
"""
|
||||
before: String
|
||||
filter: StakeOrderFilterInput
|
||||
|
||||
"""
|
||||
Returns the first _n_ elements from the list.
|
||||
@@ -536,6 +548,12 @@ type StakeOrderEdge {
|
||||
node: StakeOrder!
|
||||
}
|
||||
|
||||
input StakeOrderFilterInput {
|
||||
amount: PredicateInput
|
||||
poolName: PredicateInput
|
||||
status: [ProcessStatus!]
|
||||
}
|
||||
|
||||
type User {
|
||||
email: String!
|
||||
firstName: String!
|
||||
|
||||
@@ -2,8 +2,10 @@ import BigNumber from "bignumber.js";
|
||||
import type { ChangeEvent, FC } from "react";
|
||||
import React, { useState } from "react";
|
||||
import cx from "classnames";
|
||||
import { useRelayEnvironment } from "react-relay";
|
||||
|
||||
import { Modal } from "../../../components";
|
||||
import { Modal } from "../../../../components";
|
||||
import { commitCreateStakeRemoveOrderMutation } from "./commitCreateStakeRemoveOrder";
|
||||
|
||||
const inputBaseStyles =
|
||||
"rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent mb-3";
|
||||
@@ -18,18 +20,25 @@ type RemoveStakeModal = {
|
||||
export const RemoveStakeModal: FC<RemoveStakeModal> = ({
|
||||
setIsOpen,
|
||||
isOpen,
|
||||
// stakedCake,
|
||||
poolName,
|
||||
stakedCake,
|
||||
poolName = "",
|
||||
}) => {
|
||||
const enviroment = useRelayEnvironment();
|
||||
const [amountInput, setAmountInput] = useState<string>("0");
|
||||
const stakedCake = "44.00";
|
||||
const avaliableCake = new BigNumber(stakedCake);
|
||||
const avaliableCake = BigNumber.sum(stakedCake);
|
||||
|
||||
const handleClose = () => {
|
||||
setIsOpen(false);
|
||||
};
|
||||
|
||||
const onSubmit = () => {};
|
||||
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
commitCreateStakeRemoveOrderMutation(enviroment, {
|
||||
poolName,
|
||||
amount: amountInput,
|
||||
});
|
||||
};
|
||||
|
||||
const handleInvestInput = ({
|
||||
currentTarget: { value },
|
||||
@@ -0,0 +1,136 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from "relay-runtime";
|
||||
export type commitCreateStakeRemoveOrderMutationVariables = {
|
||||
poolName: string;
|
||||
amount: string;
|
||||
};
|
||||
export type commitCreateStakeRemoveOrderMutationResponse = {
|
||||
readonly createStakeRemoveOrder: {
|
||||
readonly order: {
|
||||
readonly id: string;
|
||||
} | null;
|
||||
} | null;
|
||||
};
|
||||
export type commitCreateStakeRemoveOrderMutation = {
|
||||
readonly response: commitCreateStakeRemoveOrderMutationResponse;
|
||||
readonly variables: commitCreateStakeRemoveOrderMutationVariables;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
mutation commitCreateStakeRemoveOrderMutation(
|
||||
$poolName: String!
|
||||
$amount: String!
|
||||
) {
|
||||
createStakeRemoveOrder(input: {order: {poolName: $poolName, amount: $amount}}) {
|
||||
order {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "amount"
|
||||
},
|
||||
v1 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "poolName"
|
||||
},
|
||||
v2 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "amount",
|
||||
"variableName": "amount"
|
||||
},
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "poolName",
|
||||
"variableName": "poolName"
|
||||
}
|
||||
],
|
||||
"kind": "ObjectValue",
|
||||
"name": "order"
|
||||
}
|
||||
],
|
||||
"kind": "ObjectValue",
|
||||
"name": "input"
|
||||
}
|
||||
],
|
||||
"concreteType": "CreateStakeRemoveOrderPayload",
|
||||
"kind": "LinkedField",
|
||||
"name": "createStakeRemoveOrder",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "StakeOrder",
|
||||
"kind": "LinkedField",
|
||||
"name": "order",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
];
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "commitCreateStakeRemoveOrderMutation",
|
||||
"selections": (v2/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": [
|
||||
(v1/*: any*/),
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"kind": "Operation",
|
||||
"name": "commitCreateStakeRemoveOrderMutation",
|
||||
"selections": (v2/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "a3a646d6f52bf3ddc29e33b8fce4661b",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "commitCreateStakeRemoveOrderMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation commitCreateStakeRemoveOrderMutation(\n $poolName: String!\n $amount: String!\n) {\n createStakeRemoveOrder(input: {order: {poolName: $poolName, amount: $amount}}) {\n order {\n id\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
(node as any).hash = '561be0497e5317997815bea692b73da9';
|
||||
export default node;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { graphql } from "babel-plugin-relay/macro";
|
||||
import type { Environment } from "react-relay";
|
||||
import { commitMutation } from "react-relay";
|
||||
|
||||
import type { commitCreateStakeRemoveOrderMutationVariables } from "./__generated__/commitCreateStakeRemoveOrderMutation.graphql";
|
||||
|
||||
export const commitCreateStakeRemoveOrderMutation = (
|
||||
environment: Environment,
|
||||
variables: commitCreateStakeRemoveOrderMutationVariables
|
||||
) => {
|
||||
return commitMutation(environment, {
|
||||
mutation: graphql`
|
||||
mutation commitCreateStakeRemoveOrderMutation(
|
||||
$poolName: String!
|
||||
$amount: String!
|
||||
) {
|
||||
createStakeRemoveOrder(
|
||||
input: { order: { poolName: $poolName, amount: $amount } }
|
||||
) {
|
||||
order {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables,
|
||||
onCompleted: (_response) => {
|
||||
window.location.href = "/orders/stake";
|
||||
},
|
||||
onError: (_error) => {},
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./RemoveStakeModal";
|
||||
@@ -2,9 +2,13 @@ import type { FC } from "react";
|
||||
import React, { useState } from "react";
|
||||
import cx from "classnames";
|
||||
import { XCircleIcon } from "@heroicons/react/outline";
|
||||
import { useLazyLoadQuery } from "react-relay";
|
||||
import { graphql } from "babel-plugin-relay/macro";
|
||||
import BigNumber from "bignumber.js";
|
||||
|
||||
import type { Vault as VaultType } from "../../../types/yieldwatch";
|
||||
import { RemoveStakeModal } from "./RemoveStakeModal";
|
||||
import type { VaultQuery } from "./__generated__/VaultQuery.graphql";
|
||||
|
||||
type VaultProps = {
|
||||
vault: Partial<VaultType>;
|
||||
@@ -12,26 +16,71 @@ type VaultProps = {
|
||||
};
|
||||
|
||||
export const Vault: FC<VaultProps> = ({ vault, isLoading }) => {
|
||||
const { stakeOrders } = useLazyLoadQuery<VaultQuery>(
|
||||
graphql`
|
||||
query VaultQuery(
|
||||
$status: ProcessStatus!
|
||||
$poolName: String!
|
||||
$amount: Float!
|
||||
) {
|
||||
stakeOrders(
|
||||
filter: {
|
||||
status: [$status]
|
||||
poolName: { eq: $poolName }
|
||||
amount: { lt: $amount }
|
||||
}
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
amount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`,
|
||||
{
|
||||
status: "PROCESSING",
|
||||
poolName: vault.name ?? "",
|
||||
amount: 0,
|
||||
}
|
||||
);
|
||||
|
||||
const [removeStakeModalIsOpen, setRemoveStakeModalIsOpen] =
|
||||
useState<boolean>(false);
|
||||
|
||||
const totalDepositedAndRewarded = (
|
||||
(vault.depositedTokens ?? 0) + (vault.totalRewards ?? 0)
|
||||
).toFixed(4);
|
||||
|
||||
const totalDeposited = vault.depositedTokens?.toFixed(4);
|
||||
const totalRewarded = vault.totalRewards?.toFixed(4);
|
||||
|
||||
const handleRemoveStakeModal = () => {
|
||||
setRemoveStakeModalIsOpen(true);
|
||||
};
|
||||
|
||||
const alreadyOnUnstakeOrder = stakeOrders.edges.reduce((acc, current) => {
|
||||
return BigNumber.sum(acc, current.node.amount);
|
||||
}, new BigNumber(0));
|
||||
|
||||
const totalDepositedAndRewarded =
|
||||
(vault.depositedTokens ?? 0) + (vault.totalRewards ?? 0);
|
||||
|
||||
let totalStaked = BigNumber.sum(
|
||||
alreadyOnUnstakeOrder,
|
||||
totalDepositedAndRewarded
|
||||
);
|
||||
|
||||
totalStaked = totalStaked.isLessThan(0.0001) ? new BigNumber(0) : totalStaked;
|
||||
|
||||
const totalStakedFixed = totalStaked.toFixed(4);
|
||||
const totalDeposited = (
|
||||
totalStaked.isEqualTo(0) ? 0 : vault.depositedTokens
|
||||
)?.toFixed(4);
|
||||
|
||||
const totalRewarded = (
|
||||
totalStaked.isEqualTo(0) ? 0 : vault.totalRewards
|
||||
)?.toFixed(4);
|
||||
|
||||
return (
|
||||
<>
|
||||
<RemoveStakeModal
|
||||
isOpen={removeStakeModalIsOpen}
|
||||
setIsOpen={setRemoveStakeModalIsOpen}
|
||||
stakedCake={totalDepositedAndRewarded}
|
||||
stakedCake={totalStakedFixed}
|
||||
poolName={vault.name}
|
||||
/>
|
||||
<div className="shadow-lg px-4 py-6 w-full bg-white dark:bg-gray-800 rounded-lg">
|
||||
@@ -53,7 +102,7 @@ export const Vault: FC<VaultProps> = ({ vault, isLoading }) => {
|
||||
: ""
|
||||
)}
|
||||
>
|
||||
{!isLoading && totalDepositedAndRewarded}
|
||||
{!isLoading && totalStakedFixed}
|
||||
</p>
|
||||
</div>
|
||||
<div className="dark:text-white">
|
||||
|
||||
222
app/javascript/src/pages/Dashboard/Vault/__generated__/VaultQuery.graphql.ts
generated
Normal file
222
app/javascript/src/pages/Dashboard/Vault/__generated__/VaultQuery.graphql.ts
generated
Normal file
@@ -0,0 +1,222 @@
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
// @ts-nocheck
|
||||
|
||||
import { ConcreteRequest } from "relay-runtime";
|
||||
export type ProcessStatus = "CANCELED" | "COMPLETED" | "PROCESSING" | "%future added value";
|
||||
export type VaultQueryVariables = {
|
||||
status: ProcessStatus;
|
||||
poolName: string;
|
||||
amount: number;
|
||||
};
|
||||
export type VaultQueryResponse = {
|
||||
readonly stakeOrders: {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly amount: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
};
|
||||
export type VaultQuery = {
|
||||
readonly response: VaultQueryResponse;
|
||||
readonly variables: VaultQueryVariables;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
query VaultQuery(
|
||||
$status: ProcessStatus!
|
||||
$poolName: String!
|
||||
$amount: Float!
|
||||
) {
|
||||
stakeOrders(filter: {status: [$status], poolName: {eq: $poolName}, amount: {lt: $amount}}) {
|
||||
edges {
|
||||
node {
|
||||
amount
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
const node: ConcreteRequest = (function(){
|
||||
var v0 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "amount"
|
||||
},
|
||||
v1 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "poolName"
|
||||
},
|
||||
v2 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "status"
|
||||
},
|
||||
v3 = [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "lt",
|
||||
"variableName": "amount"
|
||||
}
|
||||
],
|
||||
"kind": "ObjectValue",
|
||||
"name": "amount"
|
||||
},
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "eq",
|
||||
"variableName": "poolName"
|
||||
}
|
||||
],
|
||||
"kind": "ObjectValue",
|
||||
"name": "poolName"
|
||||
},
|
||||
{
|
||||
"items": [
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "status.0",
|
||||
"variableName": "status"
|
||||
}
|
||||
],
|
||||
"kind": "ListValue",
|
||||
"name": "status"
|
||||
}
|
||||
],
|
||||
"kind": "ObjectValue",
|
||||
"name": "filter"
|
||||
}
|
||||
],
|
||||
v4 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "amount",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/),
|
||||
(v2/*: any*/)
|
||||
],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "VaultQuery",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v3/*: any*/),
|
||||
"concreteType": "StakeOrderConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "stakeOrders",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "StakeOrderEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "StakeOrder",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v4/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"type": "Query",
|
||||
"abstractKey": null
|
||||
},
|
||||
"kind": "Request",
|
||||
"operation": {
|
||||
"argumentDefinitions": [
|
||||
(v2/*: any*/),
|
||||
(v1/*: any*/),
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"kind": "Operation",
|
||||
"name": "VaultQuery",
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": (v3/*: any*/),
|
||||
"concreteType": "StakeOrderConnection",
|
||||
"kind": "LinkedField",
|
||||
"name": "stakeOrders",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "StakeOrderEdge",
|
||||
"kind": "LinkedField",
|
||||
"name": "edges",
|
||||
"plural": true,
|
||||
"selections": [
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "StakeOrder",
|
||||
"kind": "LinkedField",
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v4/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "6565697f7f43e955abee8a8a1eeb8e9b",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "VaultQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query VaultQuery(\n $status: ProcessStatus!\n $poolName: String!\n $amount: Float!\n) {\n stakeOrders(filter: {status: [$status], poolName: {eq: $poolName}, amount: {lt: $amount}}) {\n edges {\n node {\n amount\n id\n }\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
(node as any).hash = 'e5dced4589579717b408bc2f555b98ab';
|
||||
export default node;
|
||||
@@ -11,10 +11,9 @@ import { StakeOrderModal } from "./StakeOrderModal";
|
||||
type PoolProps = {
|
||||
pool: PoolConfig;
|
||||
balance: string;
|
||||
currencyId: string;
|
||||
};
|
||||
|
||||
export const Pool: FC<PoolProps> = ({ pool, balance, currencyId }) => {
|
||||
export const Pool: FC<PoolProps> = ({ pool, balance }) => {
|
||||
const {
|
||||
provider,
|
||||
pancake: { router },
|
||||
@@ -36,7 +35,7 @@ export const Pool: FC<PoolProps> = ({ pool, balance, currencyId }) => {
|
||||
const totalStaked = await getTotalStaked(provider, pool);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
console.info(
|
||||
`Total Staked for ${pool.stakingToken.symbol} - ${
|
||||
pool.earningToken.symbol
|
||||
}: ${JSON.stringify(totalStaked)}`
|
||||
@@ -94,7 +93,6 @@ export const Pool: FC<PoolProps> = ({ pool, balance, currencyId }) => {
|
||||
<StakeOrderModal
|
||||
poolName={pool.earningToken.symbol}
|
||||
balance={balance}
|
||||
currencyId={currencyId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -14,7 +14,6 @@ export const PoolListing = () => {
|
||||
edges {
|
||||
node {
|
||||
currency {
|
||||
id
|
||||
name
|
||||
}
|
||||
amount
|
||||
@@ -31,7 +30,6 @@ export const PoolListing = () => {
|
||||
)?.node;
|
||||
|
||||
const balance = cakeBalance?.amount ?? "0";
|
||||
const currencyId = cakeBalance?.currency.id ?? "????";
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 place-items-center w-full gap-8 py-4 -mt-16 overflow-x-hidden">
|
||||
@@ -39,12 +37,7 @@ export const PoolListing = () => {
|
||||
.filter((pool) => !pool.isFinished)
|
||||
.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0))
|
||||
.map((pool) => (
|
||||
<Pool
|
||||
key={pool.sousId}
|
||||
pool={pool}
|
||||
balance={balance}
|
||||
currencyId={currencyId}
|
||||
/>
|
||||
<Pool key={pool.sousId} pool={pool} balance={balance} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -10,17 +10,12 @@ import { commitCreateStakeOrderMutation } from "./createStakeOrder";
|
||||
type Props = {
|
||||
poolName: string;
|
||||
balance: string;
|
||||
currencyId: string;
|
||||
};
|
||||
|
||||
const inputBaseStyles =
|
||||
"rounded-lg border-transparent flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-gray-700 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-600 focus:border-transparent mb-3";
|
||||
|
||||
export const StakeOrderModal: FC<Props> = ({
|
||||
poolName,
|
||||
balance,
|
||||
currencyId,
|
||||
}) => {
|
||||
export const StakeOrderModal: FC<Props> = ({ poolName, balance }) => {
|
||||
const environment = useRelayEnvironment();
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [investAmountInput, setInvestAmountInput] = useState("0");
|
||||
@@ -34,7 +29,6 @@ export const StakeOrderModal: FC<Props> = ({
|
||||
|
||||
const onSubmit = () => {
|
||||
commitCreateStakeOrderMutation(environment, {
|
||||
currencyId,
|
||||
amount: investAmountInput,
|
||||
poolName,
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
import { ConcreteRequest } from "relay-runtime";
|
||||
export type createStakeOrderMutationVariables = {
|
||||
currencyId: string;
|
||||
poolName: string;
|
||||
amount: string;
|
||||
};
|
||||
@@ -24,11 +23,10 @@ export type createStakeOrderMutation = {
|
||||
|
||||
/*
|
||||
mutation createStakeOrderMutation(
|
||||
$currencyId: ID!
|
||||
$poolName: String!
|
||||
$amount: String!
|
||||
) {
|
||||
createStakeOrder(input: {order: {currencyId: $currencyId, poolName: $poolName, amount: $amount}}) {
|
||||
createStakeOrder(input: {order: {poolName: $poolName, amount: $amount}}) {
|
||||
order {
|
||||
id
|
||||
}
|
||||
@@ -43,16 +41,11 @@ var v0 = {
|
||||
"name": "amount"
|
||||
},
|
||||
v1 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "currencyId"
|
||||
},
|
||||
v2 = {
|
||||
"defaultValue": null,
|
||||
"kind": "LocalArgument",
|
||||
"name": "poolName"
|
||||
},
|
||||
v3 = [
|
||||
v2 = [
|
||||
{
|
||||
"alias": null,
|
||||
"args": [
|
||||
@@ -65,11 +58,6 @@ v3 = [
|
||||
"name": "amount",
|
||||
"variableName": "amount"
|
||||
},
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "currencyId",
|
||||
"variableName": "currencyId"
|
||||
},
|
||||
{
|
||||
"kind": "Variable",
|
||||
"name": "poolName",
|
||||
@@ -115,13 +103,12 @@ return {
|
||||
"fragment": {
|
||||
"argumentDefinitions": [
|
||||
(v0/*: any*/),
|
||||
(v1/*: any*/),
|
||||
(v2/*: any*/)
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"kind": "Fragment",
|
||||
"metadata": null,
|
||||
"name": "createStakeOrderMutation",
|
||||
"selections": (v3/*: any*/),
|
||||
"selections": (v2/*: any*/),
|
||||
"type": "Mutation",
|
||||
"abstractKey": null
|
||||
},
|
||||
@@ -129,22 +116,21 @@ return {
|
||||
"operation": {
|
||||
"argumentDefinitions": [
|
||||
(v1/*: any*/),
|
||||
(v2/*: any*/),
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"kind": "Operation",
|
||||
"name": "createStakeOrderMutation",
|
||||
"selections": (v3/*: any*/)
|
||||
"selections": (v2/*: any*/)
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "bfe4935c593947810fbb8d7a52421483",
|
||||
"cacheID": "e845ef953b2de9dd797930c0838f30f8",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "createStakeOrderMutation",
|
||||
"operationKind": "mutation",
|
||||
"text": "mutation createStakeOrderMutation(\n $currencyId: ID!\n $poolName: String!\n $amount: String!\n) {\n createStakeOrder(input: {order: {currencyId: $currencyId, poolName: $poolName, amount: $amount}}) {\n order {\n id\n }\n }\n}\n"
|
||||
"text": "mutation createStakeOrderMutation(\n $poolName: String!\n $amount: String!\n) {\n createStakeOrder(input: {order: {poolName: $poolName, amount: $amount}}) {\n order {\n id\n }\n }\n}\n"
|
||||
}
|
||||
};
|
||||
})();
|
||||
(node as any).hash = '036f321e28fcb4bd3e274498cd3f116a';
|
||||
(node as any).hash = '36f248efe00b47bc1b27f597c5ab45c3';
|
||||
export default node;
|
||||
|
||||
@@ -10,19 +10,9 @@ export const commitCreateStakeOrderMutation = (
|
||||
) => {
|
||||
return commitMutation(environment, {
|
||||
mutation: graphql`
|
||||
mutation createStakeOrderMutation(
|
||||
$currencyId: ID!
|
||||
$poolName: String!
|
||||
$amount: String!
|
||||
) {
|
||||
mutation createStakeOrderMutation($poolName: String!, $amount: String!) {
|
||||
createStakeOrder(
|
||||
input: {
|
||||
order: {
|
||||
currencyId: $currencyId
|
||||
poolName: $poolName
|
||||
amount: $amount
|
||||
}
|
||||
}
|
||||
input: { order: { poolName: $poolName, amount: $amount } }
|
||||
) {
|
||||
order {
|
||||
id
|
||||
@@ -30,7 +20,7 @@ export const commitCreateStakeOrderMutation = (
|
||||
}
|
||||
}
|
||||
`,
|
||||
variables: { ...variables },
|
||||
variables,
|
||||
onCompleted: (_response) => {
|
||||
window.location.reload();
|
||||
},
|
||||
|
||||
@@ -9,7 +9,6 @@ export type PoolListingQueryResponse = {
|
||||
readonly edges: ReadonlyArray<{
|
||||
readonly node: {
|
||||
readonly currency: {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
};
|
||||
readonly amount: string;
|
||||
@@ -30,8 +29,8 @@ query PoolListingQuery {
|
||||
edges {
|
||||
node {
|
||||
currency {
|
||||
id
|
||||
name
|
||||
id
|
||||
}
|
||||
amount
|
||||
id
|
||||
@@ -46,33 +45,21 @@ var v0 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "id",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
},
|
||||
v1 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Currency",
|
||||
"kind": "LinkedField",
|
||||
"name": "currency",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/),
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "name",
|
||||
"storageKey": null
|
||||
}
|
||||
],
|
||||
"name": "amount",
|
||||
"storageKey": null
|
||||
},
|
||||
v2 = {
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"kind": "ScalarField",
|
||||
"name": "amount",
|
||||
"name": "id",
|
||||
"storageKey": null
|
||||
};
|
||||
return {
|
||||
@@ -106,8 +93,19 @@ return {
|
||||
"name": "node",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v1/*: any*/),
|
||||
(v2/*: any*/)
|
||||
{
|
||||
"alias": null,
|
||||
"args": null,
|
||||
"concreteType": "Currency",
|
||||
"kind": "LinkedField",
|
||||
"name": "currency",
|
||||
"plural": false,
|
||||
"selections": [
|
||||
(v0/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
},
|
||||
(v1/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -151,9 +149,21 @@ return {
|
||||
"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*/),
|
||||
(v0/*: any*/)
|
||||
(v2/*: any*/)
|
||||
],
|
||||
"storageKey": null
|
||||
}
|
||||
@@ -166,14 +176,14 @@ return {
|
||||
]
|
||||
},
|
||||
"params": {
|
||||
"cacheID": "06c9467183eb0e89329ec630a8cc4880",
|
||||
"cacheID": "6abf5e963429e49993af50df156f8e1c",
|
||||
"id": null,
|
||||
"metadata": {},
|
||||
"name": "PoolListingQuery",
|
||||
"operationKind": "query",
|
||||
"text": "query PoolListingQuery {\n balances {\n edges {\n node {\n currency {\n id\n name\n }\n amount\n id\n }\n }\n }\n}\n"
|
||||
"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"
|
||||
}
|
||||
};
|
||||
})();
|
||||
(node as any).hash = '570efc1d3b5dac09303b8692d6830bb2';
|
||||
(node as any).hash = '4fefb238e24b79198799686599255e6c';
|
||||
export default node;
|
||||
|
||||
@@ -33,6 +33,10 @@ class StakeOrder < ApplicationRecord
|
||||
validates :pool_name, presence: true
|
||||
validates :amount, presence: true
|
||||
|
||||
def self.ransackable_attributes(auth_object = nil)
|
||||
super & ["pool_name", "amount"]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notification_message
|
||||
|
||||
@@ -6,13 +6,11 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do
|
||||
let(:query_string) do
|
||||
<<~GQL
|
||||
mutation(
|
||||
$currencyId: ID!,
|
||||
$amount: String!,
|
||||
$poolName: String!,
|
||||
) {
|
||||
createStakeOrder(input: {
|
||||
order: {
|
||||
currencyId: $currencyId,
|
||||
amount: $amount,
|
||||
poolName: $poolName,
|
||||
}
|
||||
@@ -43,10 +41,7 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do
|
||||
]
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amount": "0.80",
|
||||
"poolName": "CAKE/BNB",
|
||||
"status": "PROCESSING",
|
||||
@@ -87,10 +82,7 @@ RSpec.describe(Mutations::CreateStakeOrder, type: :mutation) do
|
||||
]
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amount": "0.80",
|
||||
"poolName": "CAKE/BNB",
|
||||
}
|
||||
|
||||
@@ -6,13 +6,11 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do
|
||||
let(:query_string) do
|
||||
<<~GQL
|
||||
mutation(
|
||||
$currencyId: ID!,
|
||||
$amount: String!,
|
||||
$poolName: String!,
|
||||
) {
|
||||
createStakeRemoveOrder(input: {
|
||||
order: {
|
||||
currencyId: $currencyId,
|
||||
amount: $amount,
|
||||
poolName: $poolName,
|
||||
}
|
||||
@@ -43,11 +41,8 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do
|
||||
]
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amount": "-200.80",
|
||||
"amount": "200.80",
|
||||
"poolName": "CAKE/BNB",
|
||||
"status": "PROCESSING",
|
||||
}
|
||||
@@ -85,13 +80,10 @@ RSpec.describe(Mutations::CreateStakeRemoveOrder, type: :mutation) do
|
||||
]
|
||||
)
|
||||
|
||||
currency_global_id = GraphQL::Schema::UniqueWithinType.encode("Currency", currency.id)
|
||||
|
||||
create(:stake_order, amount: -200.8, user: user, pool_name: "CAKE/BNB", currency: currency)
|
||||
|
||||
variables = {
|
||||
"currencyId": currency_global_id,
|
||||
"amount": "-200.80",
|
||||
"amount": "200.80",
|
||||
"poolName": "CAKE/BNB",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user