@coin-voyage/paykit 2.2.7-beta.3 → 2.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Pages/PayToAddress/index.js +2 -2
- package/dist/components/pay-modal/index.js +1 -1
- package/dist/hooks/useDepositAddressQuery.d.ts +1 -1
- package/dist/hooks/useDepositAddressQuery.js +14 -8
- package/dist/hooks/usePayToAddressChainOptions.js +20 -16
- package/dist/hooks/usePayToAddressTokens.js +25 -22
- package/dist/hooks/usePaymentState.d.ts +5 -6
- package/dist/hooks/usePaymentState.js +3 -3
- package/dist/lib/config/wallet.js +1 -1
- package/dist/providers/paykit-provider.js +2 -7
- package/dist/types/route-config.d.ts +5 -5
- package/package.json +3 -3
|
@@ -21,7 +21,7 @@ export default function PayToAddress() {
|
|
|
21
21
|
}
|
|
22
22
|
function PayToAddressView() {
|
|
23
23
|
const { paymentState, triggerResize } = usePayContext();
|
|
24
|
-
const { payToAddressChain, payToAddressCurrency } = paymentState;
|
|
24
|
+
const { payToAddressChainId: payToAddressChain, payToAddressCurrency } = paymentState;
|
|
25
25
|
const { data: paymentDetails, isLoading, isError, } = useDepositAddressQuery({
|
|
26
26
|
enabled: payToAddressCurrency != undefined,
|
|
27
27
|
});
|
|
@@ -62,7 +62,7 @@ function DepositAddressView({ isExpired, isDeposit, depositAddress, logoElement,
|
|
|
62
62
|
function DepositFailed() {
|
|
63
63
|
const locales = useLocales();
|
|
64
64
|
const { setRoute, paymentState } = usePayContext();
|
|
65
|
-
const { setPayToAddressChain, setPayToAddressCurrency } = paymentState;
|
|
65
|
+
const { setPayToAddressChainId: setPayToAddressChain, setPayToAddressCurrency } = paymentState;
|
|
66
66
|
const onSelectAnotherMethod = useCallback(() => {
|
|
67
67
|
setPayToAddressChain(undefined);
|
|
68
68
|
setPayToAddressCurrency(undefined);
|
|
@@ -11,7 +11,7 @@ import Modal from "../ui/Modal";
|
|
|
11
11
|
const pages = Object.fromEntries(Object.entries(routeConfig).map(([key, cfg]) => [key, cfg.component]));
|
|
12
12
|
export function PayModal() {
|
|
13
13
|
const { route, setOpen, setRoute, paymentState, mode, theme, customTheme } = usePayContext();
|
|
14
|
-
const { setConnectorChainType, clearUserSelection, setPayToAddressChain, setPayToAddressCurrency, setSelectedCurrencyOption, selectedWallet, selectedCurrencyOption, connectorChainType, } = paymentState;
|
|
14
|
+
const { setConnectorChainType, clearUserSelection, setPayToAddressChainId: setPayToAddressChain, setPayToAddressCurrency, setSelectedCurrencyOption, selectedWallet, selectedCurrencyOption, connectorChainType, } = paymentState;
|
|
15
15
|
const locales = useLocales({
|
|
16
16
|
CONNECTORNAME: selectedWallet?.name,
|
|
17
17
|
CHAIN_TYPE: getChainTypeName(connectorChainType),
|
|
@@ -2,5 +2,5 @@ import type { PaymentDetails as DepositAddressDetails } from "../types/payment-d
|
|
|
2
2
|
type Params = {
|
|
3
3
|
enabled?: boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare function useDepositAddressQuery({ enabled }: Params): import("@tanstack/react-query").UseQueryResult<DepositAddressDetails
|
|
5
|
+
export declare function useDepositAddressQuery({ enabled }: Params): import("@tanstack/react-query").UseQueryResult<DepositAddressDetails, Error>;
|
|
6
6
|
export {};
|
|
@@ -3,14 +3,21 @@ import usePayContext from "../components/contexts/pay";
|
|
|
3
3
|
export function useDepositAddressQuery({ enabled }) {
|
|
4
4
|
const { paymentState } = usePayContext();
|
|
5
5
|
const { payOrder, payToAddressCurrency: currency, payToAddress } = paymentState;
|
|
6
|
+
const orderId = payOrder?.id;
|
|
7
|
+
const chainId = currency?.chain_id;
|
|
8
|
+
const tokenAddress = currency?.address;
|
|
9
|
+
const isEnabled = enabled && Boolean(orderId && chainId && currency);
|
|
6
10
|
return useQuery({
|
|
7
|
-
queryKey: ["paymentDetails",
|
|
11
|
+
queryKey: ["paymentDetails", orderId, chainId, tokenAddress],
|
|
12
|
+
enabled: isEnabled,
|
|
13
|
+
retry: false,
|
|
8
14
|
queryFn: async () => {
|
|
9
|
-
if (!
|
|
10
|
-
|
|
15
|
+
if (!orderId || !chainId || !currency) {
|
|
16
|
+
throw new Error("Missing required deposit parameters");
|
|
17
|
+
}
|
|
11
18
|
const response = await payToAddress({
|
|
12
|
-
chain_id:
|
|
13
|
-
address:
|
|
19
|
+
chain_id: chainId,
|
|
20
|
+
address: tokenAddress,
|
|
14
21
|
});
|
|
15
22
|
if (!response)
|
|
16
23
|
throw new Error("no-response");
|
|
@@ -20,10 +27,9 @@ export function useDepositAddressQuery({ enabled }) {
|
|
|
20
27
|
amount: response.data.src.total.ui_amount.toString(),
|
|
21
28
|
ticker: response.data.src.ticker,
|
|
22
29
|
expirationS: Math.floor(new Date(response.data.expires_at).getTime() / 1000),
|
|
23
|
-
chainId
|
|
30
|
+
chainId,
|
|
31
|
+
logoURI: currency.image_uri ?? "", // TODO: add fallback image
|
|
24
32
|
};
|
|
25
33
|
},
|
|
26
|
-
enabled,
|
|
27
|
-
retry: false,
|
|
28
34
|
});
|
|
29
35
|
}
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { getChains } from "@coin-voyage/shared/common";
|
|
2
|
+
import { fetchTokenList, getChains } from "@coin-voyage/shared/common";
|
|
3
3
|
import { ChainId } from "@coin-voyage/shared/types";
|
|
4
4
|
import { useQuery } from "@tanstack/react-query";
|
|
5
|
+
import { useMemo } from "react";
|
|
5
6
|
import usePayContext from "../components/contexts/pay";
|
|
6
7
|
import { SquircleIcon } from "../components/ui/Icon";
|
|
7
8
|
import { ROUTES } from "../types/routes";
|
|
9
|
+
const BTC_MIN_USD_AMOUNT = 15;
|
|
10
|
+
const TOKEN_LIST_QUERY_KEY = ["token-list"];
|
|
8
11
|
export function usePayToAddressChainOptions({ fiatAmount }) {
|
|
9
12
|
const { setRoute, paymentState } = usePayContext();
|
|
10
|
-
const { setPayToAddressChain } = paymentState;
|
|
11
|
-
const { data:
|
|
12
|
-
queryKey:
|
|
13
|
-
queryFn:
|
|
14
|
-
|
|
15
|
-
id: chain.chainId.toString(),
|
|
16
|
-
title: chain.name,
|
|
17
|
-
icons: [_jsx(SquircleIcon, { icon: chain.logoURI, alt: chain.name }, chain.chainId)],
|
|
18
|
-
onClick: () => {
|
|
19
|
-
setPayToAddressChain(chain);
|
|
20
|
-
setRoute(ROUTES.SELECT_PAY_TO_ADDRESS_TOKEN);
|
|
21
|
-
},
|
|
22
|
-
disabled: chain.chainId === ChainId.BTC && fiatAmount != null && fiatAmount < 15,
|
|
23
|
-
})),
|
|
24
|
-
staleTime: 1000 * 60 * 5, // cache for 5 minutes
|
|
13
|
+
const { setPayToAddressChainId: setPayToAddressChain } = paymentState;
|
|
14
|
+
const { data: tokenList, isLoading } = useQuery({
|
|
15
|
+
queryKey: TOKEN_LIST_QUERY_KEY,
|
|
16
|
+
queryFn: fetchTokenList,
|
|
17
|
+
staleTime: 1000 * 60 * 5,
|
|
25
18
|
});
|
|
19
|
+
const chains = useMemo(() => getChains(tokenList?.chains ?? []), [tokenList]);
|
|
20
|
+
const options = useMemo(() => chains.map((chain) => ({
|
|
21
|
+
id: chain.chainId.toString(),
|
|
22
|
+
title: chain.name,
|
|
23
|
+
icons: [_jsx(SquircleIcon, { icon: chain.logoURI, alt: chain.name }, chain.chainId)],
|
|
24
|
+
onClick: () => {
|
|
25
|
+
setPayToAddressChain(chain.chainId);
|
|
26
|
+
setRoute(ROUTES.SELECT_PAY_TO_ADDRESS_TOKEN);
|
|
27
|
+
},
|
|
28
|
+
disabled: chain.chainId === ChainId.BTC && typeof fiatAmount === "number" && fiatAmount < BTC_MIN_USD_AMOUNT,
|
|
29
|
+
})), [chains, fiatAmount, setPayToAddressChain, setRoute]);
|
|
26
30
|
return { options, isLoading };
|
|
27
31
|
}
|
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { tokensByChainId } from "@coin-voyage/shared/common";
|
|
2
|
+
import { fetchTokenList, tokensByChainId, tokenToCurrency } from "@coin-voyage/shared/common";
|
|
3
3
|
import { useQuery } from "@tanstack/react-query";
|
|
4
|
+
import { useMemo } from "react";
|
|
4
5
|
import usePayContext from "../components/contexts/pay";
|
|
5
6
|
import { SquircleIcon } from "../components/ui/Icon";
|
|
6
7
|
import { ROUTES } from "../types/routes";
|
|
8
|
+
const TOKEN_LIST_QUERY_KEY = ["token-list"];
|
|
7
9
|
export function usePayToAddressTokens() {
|
|
8
10
|
const { paymentState, setRoute } = usePayContext();
|
|
9
|
-
const { payToAddressChain, setPayToAddressCurrency } = paymentState;
|
|
10
|
-
const chainId = payToAddressChain
|
|
11
|
-
const { data:
|
|
12
|
-
queryKey:
|
|
13
|
-
queryFn:
|
|
14
|
-
if (chainId == null)
|
|
15
|
-
return [];
|
|
16
|
-
return await tokensByChainId(chainId);
|
|
17
|
-
},
|
|
18
|
-
enabled: Boolean(chainId),
|
|
19
|
-
select: (tokens) => tokens.map((token) => ({
|
|
20
|
-
id: token.address ?? token.ticker,
|
|
21
|
-
title: token.name,
|
|
22
|
-
icons: token.logoURI
|
|
23
|
-
? [_jsx(SquircleIcon, { icon: token.logoURI, alt: token.name }, token.address ?? token.ticker)]
|
|
24
|
-
: [],
|
|
25
|
-
onClick: () => {
|
|
26
|
-
setPayToAddressCurrency(token);
|
|
27
|
-
setRoute(ROUTES.PAY_TO_ADDRESS);
|
|
28
|
-
},
|
|
29
|
-
})),
|
|
11
|
+
const { payToAddressChainId: payToAddressChain, setPayToAddressCurrency } = paymentState;
|
|
12
|
+
const chainId = payToAddressChain;
|
|
13
|
+
const { data: tokenList, isLoading } = useQuery({
|
|
14
|
+
queryKey: TOKEN_LIST_QUERY_KEY,
|
|
15
|
+
queryFn: fetchTokenList,
|
|
30
16
|
staleTime: 1000 * 60 * 5,
|
|
31
17
|
});
|
|
18
|
+
const tokens = useMemo(() => {
|
|
19
|
+
if (!tokenList || !chainId)
|
|
20
|
+
return [];
|
|
21
|
+
return tokensByChainId(tokenList.chains, chainId);
|
|
22
|
+
}, [tokenList, chainId]);
|
|
23
|
+
const options = useMemo(() => tokens.map((token) => ({
|
|
24
|
+
id: token.address ?? token.ticker,
|
|
25
|
+
title: token.name,
|
|
26
|
+
icons: token.logoURI
|
|
27
|
+
? [_jsx(SquircleIcon, { icon: token.logoURI, alt: token.name }, token.address ?? token.ticker)]
|
|
28
|
+
: [],
|
|
29
|
+
onClick: () => {
|
|
30
|
+
const currency = tokenToCurrency(token);
|
|
31
|
+
setPayToAddressCurrency(currency);
|
|
32
|
+
setRoute(ROUTES.PAY_TO_ADDRESS);
|
|
33
|
+
},
|
|
34
|
+
})), [tokens, setPayToAddressCurrency, setRoute]);
|
|
32
35
|
return { options, isLoading };
|
|
33
36
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WalletProps } from "@coin-voyage/crypto/types/wallet";
|
|
2
|
-
import {
|
|
3
|
-
import { ChainType, CurrencyBase, type PayOrder } from "@coin-voyage/shared/types";
|
|
2
|
+
import { ChainId, ChainType, Currency, CurrencyBase, type PayOrder } from "@coin-voyage/shared/types";
|
|
4
3
|
import { PaymentDetails, PayOrderParams } from "@coin-voyage/shared/types/api";
|
|
5
4
|
import { PaymentMethod } from "../types/enums";
|
|
6
5
|
import { ROUTES } from "../types/routes";
|
|
@@ -26,10 +25,10 @@ export interface PaymentState {
|
|
|
26
25
|
payToAddress: (currency: CurrencyBase) => Promise<PaymentDetails | undefined>;
|
|
27
26
|
refreshOrder: () => Promise<void>;
|
|
28
27
|
senderEnsName: string | undefined;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
payToAddressCurrency:
|
|
32
|
-
setPayToAddressCurrency: React.Dispatch<React.SetStateAction<
|
|
28
|
+
payToAddressChainId: ChainId | undefined;
|
|
29
|
+
setPayToAddressChainId: React.Dispatch<React.SetStateAction<ChainId | undefined>>;
|
|
30
|
+
payToAddressCurrency: Currency | undefined;
|
|
31
|
+
setPayToAddressCurrency: React.Dispatch<React.SetStateAction<Currency | undefined>>;
|
|
33
32
|
}
|
|
34
33
|
export declare function usePaymentState({ payOrder, setPayOrder, setRoute, log, }: {
|
|
35
34
|
payOrder: PayOrder | undefined;
|
|
@@ -35,7 +35,7 @@ export function usePaymentState({ payOrder, setPayOrder, setRoute, log, }) {
|
|
|
35
35
|
});
|
|
36
36
|
const [selectedCurrencyOption, setSelectedCurrencyOption] = useState();
|
|
37
37
|
const [paymentMethod, setPaymentMethod] = useState();
|
|
38
|
-
const [
|
|
38
|
+
const [payToAddressChainId, setPayToAddressChainId] = useState();
|
|
39
39
|
const [payToAddressCurrency, setPayToAddressCurrency] = useState();
|
|
40
40
|
const { payFromWallet } = usePayFromWallet({
|
|
41
41
|
senderAddr: senderAccount.address,
|
|
@@ -151,8 +151,8 @@ export function usePaymentState({ payOrder, setPayOrder, setRoute, log, }) {
|
|
|
151
151
|
payToAddress,
|
|
152
152
|
refreshOrder,
|
|
153
153
|
senderEnsName: evmEnsName ?? suiEnsName ?? undefined,
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
payToAddressChainId,
|
|
155
|
+
setPayToAddressChainId,
|
|
156
156
|
payToAddressCurrency,
|
|
157
157
|
setPayToAddressCurrency,
|
|
158
158
|
};
|
|
@@ -86,7 +86,7 @@ export const walletConfigs = {
|
|
|
86
86
|
},
|
|
87
87
|
chainTypes: [ChainType.EVM, ChainType.SOL],
|
|
88
88
|
},
|
|
89
|
-
"phantom, app.phantom": {
|
|
89
|
+
"phantom, app.phantom, app.phantom.bitcoin, app.phantom.sui, app.phantom.ethereum": {
|
|
90
90
|
name: "Phantom",
|
|
91
91
|
iconShape: "squircle",
|
|
92
92
|
icon: _jsx(Logos.Phantom, {}),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useInWagmiContext } from "@coin-voyage/crypto/evm/provider/provider";
|
|
3
3
|
import { useAccount, useConnectCallback } from "@coin-voyage/crypto/hooks";
|
|
4
|
-
import { getChainMetadata, getToken } from "@coin-voyage/shared/common";
|
|
5
4
|
import { PayOrderMode, PayOrderStatus } from "@coin-voyage/shared/types";
|
|
6
5
|
import { Buffer } from "buffer";
|
|
7
6
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
@@ -197,12 +196,8 @@ function PayKitProviderInternal({ theme = "auto", mode = "auto", customTheme, op
|
|
|
197
196
|
else if (paymentMethod === PaymentMethod.DepositAddress &&
|
|
198
197
|
payOrder?.status === PayOrderStatus.AWAITING_PAYMENT &&
|
|
199
198
|
payOrder.payment?.src) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (chainMetadata)
|
|
203
|
-
paymentState.setPayToAddressChain(chainMetadata);
|
|
204
|
-
if (token)
|
|
205
|
-
paymentState.setPayToAddressCurrency(token);
|
|
199
|
+
paymentState.setPayToAddressChainId(payOrder.payment.src.chain_id);
|
|
200
|
+
paymentState.setPayToAddressCurrency(payOrder.payment.src);
|
|
206
201
|
setRoute(ROUTES.PAY_TO_ADDRESS);
|
|
207
202
|
}
|
|
208
203
|
else {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Currency } from "@coin-voyage/shared/types";
|
|
1
2
|
import type React from "react";
|
|
2
|
-
import type { ROUTES } from "./routes";
|
|
3
3
|
import { Dispatch, SetStateAction } from "react";
|
|
4
|
-
import { ChainType } from "../server";
|
|
4
|
+
import { ChainId, ChainType } from "../server";
|
|
5
|
+
import type { ROUTES } from "./routes";
|
|
5
6
|
import { CurrencyAndQuoteID } from "./state";
|
|
6
|
-
import { ChainMetadata, Token } from "@coin-voyage/shared/common";
|
|
7
7
|
export interface RouteConfig {
|
|
8
8
|
component: React.ReactNode;
|
|
9
9
|
heading: string | ((ctx: HeadingContext) => string | undefined);
|
|
@@ -25,8 +25,8 @@ export interface HeadingContext {
|
|
|
25
25
|
export interface BackNavigationActions {
|
|
26
26
|
setRoute: Dispatch<SetStateAction<ROUTES>>;
|
|
27
27
|
setConnectorChainType: Dispatch<SetStateAction<ChainType | undefined>>;
|
|
28
|
-
setPayToAddressChain: Dispatch<SetStateAction<
|
|
29
|
-
setPayToAddressCurrency: Dispatch<SetStateAction<
|
|
28
|
+
setPayToAddressChain: Dispatch<SetStateAction<ChainId | undefined>>;
|
|
29
|
+
setPayToAddressCurrency: Dispatch<SetStateAction<Currency | undefined>>;
|
|
30
30
|
setSelectedCurrencyOption: (option: CurrencyAndQuoteID | undefined) => void;
|
|
31
31
|
clearUserSelection: () => void;
|
|
32
32
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coin-voyage/paykit",
|
|
3
3
|
"description": "Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.",
|
|
4
|
-
"version": "2.2.7
|
|
4
|
+
"version": "2.2.7",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"author": "Lars <lars@coinvoyage.io>",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"react-use-measure": "^2.1.1",
|
|
62
62
|
"styled-components": "^5.3.11",
|
|
63
63
|
"uuid": "13.0.0",
|
|
64
|
-
"@coin-voyage/crypto": "2.2.
|
|
65
|
-
"@coin-voyage/shared": "2.2.5
|
|
64
|
+
"@coin-voyage/crypto": "2.2.3",
|
|
65
|
+
"@coin-voyage/shared": "2.2.5"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/qrcode": "1.5.5",
|