mirror of
https://github.com/haveno-dex/haveno-ui.git
synced 2025-11-26 01:16:47 -05:00
chore(MarketOffers): Add submit hooks.
This commit is contained in:
parent
35376ef16f
commit
c30d753a52
4 changed files with 126 additions and 5 deletions
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
import { createStyles } from "@mantine/core";
|
import { createStyles } from "@mantine/core";
|
||||||
import { createTable } from "@tanstack/react-table";
|
import { createTable } from "@tanstack/react-table";
|
||||||
|
import { useIntl } from "react-intl";
|
||||||
import { Table } from "@molecules/Table";
|
import { Table } from "@molecules/Table";
|
||||||
import type { MarketTransaction } from "./_types";
|
import type { MarketTransaction } from "./_types";
|
||||||
import {
|
import {
|
||||||
|
|
@ -26,7 +27,6 @@ import {
|
||||||
MarketTransactionsAccountAgeCell,
|
MarketTransactionsAccountAgeCell,
|
||||||
MarketTransactionsPaymentCell,
|
MarketTransactionsPaymentCell,
|
||||||
} from "./MarketTransactionsTableCell";
|
} from "./MarketTransactionsTableCell";
|
||||||
import { useIntl } from "react-intl";
|
|
||||||
import { LangKeys } from "@constants/lang";
|
import { LangKeys } from "@constants/lang";
|
||||||
|
|
||||||
const table = createTable().setRowType<MarketTransaction>();
|
const table = createTable().setRowType<MarketTransaction>();
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
// =============================================================================
|
// =============================================================================
|
||||||
|
|
||||||
|
import { useIntl } from "react-intl";
|
||||||
|
import { Group } from "@mantine/core";
|
||||||
import { Currency } from "@atoms/Currency";
|
import { Currency } from "@atoms/Currency";
|
||||||
import { BodyText } from "@atoms/Typography";
|
import { BodyText } from "@atoms/Typography";
|
||||||
import { Group, Text } from "@mantine/core";
|
|
||||||
import type { MarketTransaction } from "./_types";
|
import type { MarketTransaction } from "./_types";
|
||||||
import { MarketTransactionPaymentMethod } from "./_types";
|
import { MarketTransactionPaymentMethod } from "./_types";
|
||||||
import { ReactComponent as CheckCircle } from "@assets/check-circle.svg";
|
import { ReactComponent as CheckCircle } from "@assets/check-circle.svg";
|
||||||
import { useIntl } from "react-intl";
|
|
||||||
import { LangKeys } from "@constants/lang";
|
import { LangKeys } from "@constants/lang";
|
||||||
|
|
||||||
export function MarketTransactionsAccountAgeCell({
|
export function MarketTransactionsAccountAgeCell({
|
||||||
|
|
@ -29,7 +29,7 @@ export function MarketTransactionsAccountAgeCell({
|
||||||
row?: MarketTransaction;
|
row?: MarketTransaction;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Group>
|
<Group spacing="sm">
|
||||||
<CheckCircle width={15} height={15} />
|
<CheckCircle width={15} height={15} />
|
||||||
<BodyText heavy>65 Days</BodyText>
|
<BodyText heavy>65 Days</BodyText>
|
||||||
</Group>
|
</Group>
|
||||||
|
|
@ -42,7 +42,7 @@ export function MarketTransactionsPriceCell({
|
||||||
row?: MarketTransaction;
|
row?: MarketTransaction;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Group>
|
<Group spacing="sm">
|
||||||
<BodyText heavy>
|
<BodyText heavy>
|
||||||
<Currency
|
<Currency
|
||||||
currencyCode={row?.priceCurrency}
|
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…
Add table
Add a link
Reference in a new issue