mirror of
https://github.com/haveno-dex/haveno-ui.git
synced 2025-04-19 23:26:02 -04:00
chore(MarketOffers): Add submit hooks.
This commit is contained in:
parent
35376ef16f
commit
c30d753a52
@ -16,6 +16,7 @@
|
||||
|
||||
import { createStyles } from "@mantine/core";
|
||||
import { createTable } from "@tanstack/react-table";
|
||||
import { useIntl } from "react-intl";
|
||||
import { Table } from "@molecules/Table";
|
||||
import type { MarketTransaction } from "./_types";
|
||||
import {
|
||||
@ -26,7 +27,6 @@ import {
|
||||
MarketTransactionsAccountAgeCell,
|
||||
MarketTransactionsPaymentCell,
|
||||
} from "./MarketTransactionsTableCell";
|
||||
import { useIntl } from "react-intl";
|
||||
import { LangKeys } from "@constants/lang";
|
||||
|
||||
const table = createTable().setRowType<MarketTransaction>();
|
||||
|
@ -14,13 +14,13 @@
|
||||
// limitations under the License.
|
||||
// =============================================================================
|
||||
|
||||
import { useIntl } from "react-intl";
|
||||
import { Group } from "@mantine/core";
|
||||
import { Currency } from "@atoms/Currency";
|
||||
import { BodyText } from "@atoms/Typography";
|
||||
import { Group, Text } from "@mantine/core";
|
||||
import type { MarketTransaction } from "./_types";
|
||||
import { MarketTransactionPaymentMethod } from "./_types";
|
||||
import { ReactComponent as CheckCircle } from "@assets/check-circle.svg";
|
||||
import { useIntl } from "react-intl";
|
||||
import { LangKeys } from "@constants/lang";
|
||||
|
||||
export function MarketTransactionsAccountAgeCell({
|
||||
@ -29,7 +29,7 @@ export function MarketTransactionsAccountAgeCell({
|
||||
row?: MarketTransaction;
|
||||
}) {
|
||||
return (
|
||||
<Group>
|
||||
<Group spacing="sm">
|
||||
<CheckCircle width={15} height={15} />
|
||||
<BodyText heavy>65 Days</BodyText>
|
||||
</Group>
|
||||
@ -42,7 +42,7 @@ export function MarketTransactionsPriceCell({
|
||||
row?: MarketTransaction;
|
||||
}) {
|
||||
return (
|
||||
<Group>
|
||||
<Group spacing="sm">
|
||||
<BodyText heavy>
|
||||
<Currency
|
||||
currencyCode={row?.priceCurrency}
|
||||
|
@ -0,0 +1,54 @@
|
||||
// =============================================================================
|
||||
// Copyright 2022 Haveno
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// =============================================================================
|
||||
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import { showNotification } from "@mantine/notifications";
|
||||
import { QueryKeys } from "@constants/query-keys";
|
||||
import { useHavenoClient } from "./useHavenoClient";
|
||||
|
||||
interface SetCryptoPaymentAccount {
|
||||
accountName: string;
|
||||
assetCode: string;
|
||||
address: string;
|
||||
}
|
||||
|
||||
export function useSetCryptoPaymentAccount() {
|
||||
const client = useHavenoClient();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
async (variables: SetCryptoPaymentAccount) => {
|
||||
return client.createCryptoPaymentAccount(
|
||||
variables.accountName,
|
||||
variables.assetCode,
|
||||
variables.address
|
||||
);
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(QueryKeys.PaymentAccounts);
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
console.dir(err);
|
||||
showNotification({
|
||||
color: "red",
|
||||
message: err.message || "",
|
||||
title: "Something went wrong",
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
67
packages/renderer/src/hooks/haveno/useSetOffer.ts
Normal file
67
packages/renderer/src/hooks/haveno/useSetOffer.ts
Normal file
@ -0,0 +1,67 @@
|
||||
// =============================================================================
|
||||
// Copyright 2022 Haveno
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// =============================================================================
|
||||
|
||||
import { useMutation, useQueryClient } from "react-query";
|
||||
import { showNotification } from "@mantine/notifications";
|
||||
import { QueryKeys } from "@constants/query-keys";
|
||||
import { useHavenoClient } from "./useHavenoClient";
|
||||
|
||||
interface SetOfferVariables {
|
||||
direction: string;
|
||||
amount: bigint;
|
||||
assetCode: string;
|
||||
paymentAccountId: string;
|
||||
buyerSecurityDeposit: number;
|
||||
price?: number;
|
||||
marketPriceMargin?: number;
|
||||
triggerPrice?: number;
|
||||
minAmount?: bigint;
|
||||
}
|
||||
|
||||
export function useSetOffer() {
|
||||
const client = useHavenoClient();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
async (variables: SetOfferVariables) => {
|
||||
return client.postOffer(
|
||||
variables.direction,
|
||||
variables.amount,
|
||||
variables.assetCode,
|
||||
variables.paymentAccountId,
|
||||
variables.buyerSecurityDeposit,
|
||||
variables.price,
|
||||
variables.marketPriceMargin,
|
||||
variables.triggerPrice,
|
||||
variables.minAmount
|
||||
);
|
||||
},
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries(QueryKeys.MarketsOffers);
|
||||
queryClient.invalidateQueries(QueryKeys.MyOffers);
|
||||
},
|
||||
onError: (err: Error) => {
|
||||
console.dir(err);
|
||||
showNotification({
|
||||
color: "red",
|
||||
message: err.message || "",
|
||||
title: "Something went wrong",
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user