@daimo/pay 1.3.2 → 1.3.4
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/build/index.d.ts +15 -5
- package/build/package.json.js +3 -3
- package/build/src/components/Common/AmountInput/AmountInputField.js +1 -1
- package/build/src/components/Common/PaymentBreakdown/index.js +2 -2
- package/build/src/components/DaimoPayButton/index.js +1 -0
- package/build/src/components/DaimoPayButton/index.js.map +1 -1
- package/build/src/components/DaimoPayModal/index.js +1 -1
- package/build/src/components/Pages/PayWithToken/index.js +2 -2
- package/build/src/components/Pages/SelectMethod/index.js +40 -26
- package/build/src/components/Pages/SelectMethod/index.js.map +1 -1
- package/build/src/components/Pages/WaitingExternal/index.js +1 -1
- package/build/src/hooks/useExternalPaymentOptions.js +1 -0
- package/build/src/hooks/useExternalPaymentOptions.js.map +1 -1
- package/build/src/hooks/usePayWithSolanaToken.js +1 -2
- package/build/src/hooks/usePayWithSolanaToken.js.map +1 -1
- package/build/src/hooks/usePayWithToken.js +15 -13
- package/build/src/hooks/usePayWithToken.js.map +1 -1
- package/build/src/hooks/usePaymentState.js +2 -2
- package/build/src/hooks/useWalletPaymentOptions.js +2 -1
- package/build/src/hooks/useWalletPaymentOptions.js.map +1 -1
- package/package.json +3 -3
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React$1, { ReactNode } from 'react';
|
|
2
2
|
export { version } from '../package.json';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
-
import { DaimoPayOrderMode, DepositAddressPaymentOptionMetadata, PlatformType, ExternalPaymentOptionMetadata, WalletPaymentOption, DaimoPayOrder,
|
|
4
|
+
import { DaimoPayOrderMode, DepositAddressPaymentOptionMetadata, PlatformType, ExternalPaymentOptionMetadata, WalletPaymentOption, DaimoPayOrder, ExternalPaymentOptions, DepositAddressPaymentOptions, DepositAddressPaymentOptionData, SolanaPublicKey, DaimoPayUserMetadata, PaymentStartedEvent, PaymentCompletedEvent, PaymentBouncedEvent, DaimoPayIntentStatus, DaimoPayOrderView } from '@daimo/common';
|
|
5
5
|
import { Address, Hex } from 'viem';
|
|
6
6
|
import { AppRouter } from '@daimo/pay-api';
|
|
7
7
|
import { CreateTRPCClient } from '@trpc/client';
|
|
@@ -70,7 +70,7 @@ type DaimoPayModalOptions = {
|
|
|
70
70
|
closeOnSuccess?: boolean;
|
|
71
71
|
};
|
|
72
72
|
/** Additional payment options. Onchain payments are always enabled. */
|
|
73
|
-
type PaymentOption = "Daimo" | "Coinbase" | "Binance" | "RampNetwork";
|
|
73
|
+
type PaymentOption = "Daimo" | "Coinbase" | "Binance" | "RampNetwork" | "Solana" | "ExternalChains";
|
|
74
74
|
|
|
75
75
|
type types_d_All = All;
|
|
76
76
|
type types_d_CustomAvatarProps = CustomAvatarProps;
|
|
@@ -127,7 +127,7 @@ declare function useSolanaPaymentOptions({ trpc, address, usdRequired, isDeposit
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
/** Wallet payment options. User picks one. */
|
|
130
|
-
declare function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, preferredChains, preferredTokens, isDepositFlow, log, }: {
|
|
130
|
+
declare function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, preferredChains, preferredTokens, evmChains, isDepositFlow, log, }: {
|
|
131
131
|
trpc: TrpcClient;
|
|
132
132
|
address: string | undefined;
|
|
133
133
|
usdRequired: number | undefined;
|
|
@@ -137,6 +137,7 @@ declare function useWalletPaymentOptions({ trpc, address, usdRequired, destChain
|
|
|
137
137
|
chain: number;
|
|
138
138
|
address: string;
|
|
139
139
|
}[] | undefined;
|
|
140
|
+
evmChains: number[] | undefined;
|
|
140
141
|
isDepositFlow: boolean;
|
|
141
142
|
log: (msg: string) => void;
|
|
142
143
|
}): {
|
|
@@ -172,6 +173,8 @@ interface PayParams {
|
|
|
172
173
|
chain: number;
|
|
173
174
|
address: Address;
|
|
174
175
|
}[];
|
|
176
|
+
/** Only allow payments on these EVM chains. */
|
|
177
|
+
evmChains?: number[];
|
|
175
178
|
/** External ID. E.g. a correlation ID. */
|
|
176
179
|
externalId?: string;
|
|
177
180
|
/** Developer metadata. E.g. correlation ID. */
|
|
@@ -203,7 +206,7 @@ interface PaymentState {
|
|
|
203
206
|
setSelectedSolanaTokenOption: (option: WalletPaymentOption | undefined) => void;
|
|
204
207
|
setSelectedDepositAddressOption: (option: DepositAddressPaymentOptionMetadata | undefined) => void;
|
|
205
208
|
setChosenUsd: (usd: number) => void;
|
|
206
|
-
payWithToken: (
|
|
209
|
+
payWithToken: (walletOption: WalletPaymentOption) => Promise<void>;
|
|
207
210
|
payWithExternal: (option: ExternalPaymentOptions) => Promise<string>;
|
|
208
211
|
payWithDepositAddress: (option: DepositAddressPaymentOptions) => Promise<DepositAddressPaymentOptionData | null>;
|
|
209
212
|
payWithSolanaToken: (inputToken: SolanaPublicKey) => Promise<string | undefined>;
|
|
@@ -372,6 +375,10 @@ type PayButtonPaymentProps = {
|
|
|
372
375
|
chain: number;
|
|
373
376
|
address: Address;
|
|
374
377
|
}[];
|
|
378
|
+
/**
|
|
379
|
+
* Only allow payments on these EVM chains.
|
|
380
|
+
*/
|
|
381
|
+
evmChains?: number[];
|
|
375
382
|
/**
|
|
376
383
|
* External ID. E.g. a correlation ID.
|
|
377
384
|
*/
|
|
@@ -461,4 +468,7 @@ declare const daimoPayVersion: string;
|
|
|
461
468
|
/** Chain ids supported by Daimo Pay. */
|
|
462
469
|
declare const supportedChainIds: Set<number>;
|
|
463
470
|
|
|
464
|
-
|
|
471
|
+
type DaimoPayment = DaimoPayOrderView;
|
|
472
|
+
type DaimoPayEvent = PaymentStartedEvent | PaymentCompletedEvent | PaymentBouncedEvent;
|
|
473
|
+
|
|
474
|
+
export { Avatar, Chain as ChainIcon, DaimoPayButton, type DaimoPayButtonCustomProps, type DaimoPayButtonProps, Context as DaimoPayContext, type DaimoPayEvent, DaimoPayProvider, type DaimoPayment, types_d as Types, daimoPayVersion, defaultConfig as getDefaultConfig, supportedChainIds, useDaimoPayStatus, usePayContext, wallets };
|
package/build/package.json.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var name = "@daimo/pay";
|
|
2
|
-
var version = "1.3.
|
|
2
|
+
var version = "1.3.4";
|
|
3
3
|
var author = "Daimo";
|
|
4
4
|
var homepage = "https://pay.daimo.com";
|
|
5
5
|
var license = "BSD-2-Clause license";
|
|
@@ -38,8 +38,8 @@ var keywords = [
|
|
|
38
38
|
"crypto"
|
|
39
39
|
];
|
|
40
40
|
var dependencies = {
|
|
41
|
-
"@daimo/common": "1.3.
|
|
42
|
-
"@daimo/contract": "1.3.
|
|
41
|
+
"@daimo/common": "1.3.4",
|
|
42
|
+
"@daimo/contract": "1.3.4",
|
|
43
43
|
"@solana/wallet-adapter-base": "^0.9.23",
|
|
44
44
|
"@solana/wallet-adapter-react": "^0.15.35",
|
|
45
45
|
"@solana/web3.js": "^1.95.4",
|
|
@@ -52,7 +52,7 @@ const AmountInputField = ({ value, onChange, currency = "$", onKeyDown }) => {
|
|
|
52
52
|
useEffect(() => {
|
|
53
53
|
inputRef.current?.focus();
|
|
54
54
|
}, [value]);
|
|
55
|
-
return (jsxs(Container, { children: [currency === "$" && jsx(AnimatedCurrency, { children: currency }), jsx(InputField, { ref: inputRef, type: "text", value: value, onChange: onChange, placeholder: "0.00", onKeyDown: onKeyDown }), currency !== "$" && (jsx(AnimatedCurrency, { "$small": true, children: currency }))] }));
|
|
55
|
+
return (jsxs(Container, { children: [currency === "$" && jsx(AnimatedCurrency, { children: currency }), jsx(InputField, { ref: inputRef, type: "text", inputMode: "decimal", value: value, onChange: onChange, placeholder: "0.00", onKeyDown: onKeyDown }), currency !== "$" && (jsx(AnimatedCurrency, { "$small": true, children: currency }))] }));
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
export { AmountInputField as default };
|
|
@@ -4,9 +4,9 @@ import styled from '../../../styles/styled/index.js';
|
|
|
4
4
|
import { ModalBody } from '../Modal/styles.js';
|
|
5
5
|
|
|
6
6
|
const PaymentBreakdown = ({ paymentOption }) => {
|
|
7
|
-
const
|
|
7
|
+
const subtotalUsd = paymentOption.required.usd;
|
|
8
8
|
const feesUsd = paymentOption.fees.usd;
|
|
9
|
-
const
|
|
9
|
+
const totalUsd = subtotalUsd + feesUsd;
|
|
10
10
|
return (jsxs(FeesContainer, { children: [feesUsd > 0 && (jsxs(FeeRow, { children: [jsx(ModalBody, { children: "Subtotal" }), jsxs(ModalBody, { children: ["$", subtotalUsd.toFixed(2)] })] })), jsxs(FeeRow, { children: [jsx(ModalBody, { children: "Fees" }), feesUsd === 0 ? (jsx(Badge, { children: "Free" })) : (jsxs(ModalBody, { children: ["$", feesUsd.toFixed(2)] }))] }), jsxs(FeeRow, { style: { marginTop: 8 }, children: [jsx(ModalBody, { style: { fontWeight: 600 }, children: "Total" }), jsxs(ModalBody, { style: { fontWeight: 600 }, children: ["$", totalUsd.toFixed(2)] })] })] }));
|
|
11
11
|
};
|
|
12
12
|
const FeesContainer = styled.div `
|
|
@@ -34,6 +34,7 @@ function DaimoPayButtonCustom(props) {
|
|
|
34
34
|
paymentOptions: props.paymentOptions,
|
|
35
35
|
preferredChains: props.preferredChains,
|
|
36
36
|
preferredTokens: props.preferredTokens,
|
|
37
|
+
evmChains: props.evmChains,
|
|
37
38
|
externalId: props.externalId,
|
|
38
39
|
metadata: props.metadata,
|
|
39
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -10,7 +10,7 @@ import MobileConnectors from '../Pages/MobileConnectors/index.js';
|
|
|
10
10
|
import Introduction from '../Pages/Onboarding/index.js';
|
|
11
11
|
import SwitchNetworks from '../Pages/SwitchNetworks/index.js';
|
|
12
12
|
import ConnectUsing from './ConnectUsing.js';
|
|
13
|
-
import assert from '
|
|
13
|
+
import { assert } from '@daimo/common';
|
|
14
14
|
import { getAppName } from '../../defaultConfig.js';
|
|
15
15
|
import { useChainIsSupported } from '../../hooks/useChainIsSupported.js';
|
|
16
16
|
import { DaimoPayThemeProvider } from '../DaimoPayThemeProvider/DaimoPayThemeProvider.js';
|
|
@@ -50,7 +50,7 @@ const PayWithToken = () => {
|
|
|
50
50
|
}
|
|
51
51
|
setPayState(PayState.RequestingPayment);
|
|
52
52
|
try {
|
|
53
|
-
await payWithToken(option
|
|
53
|
+
await payWithToken(option);
|
|
54
54
|
setPayState(PayState.RequestSuccessful);
|
|
55
55
|
setTimeout(() => {
|
|
56
56
|
setRoute(ROUTES.CONFIRMATION, { event: "wait-pay-with-token" });
|
|
@@ -64,7 +64,7 @@ const PayWithToken = () => {
|
|
|
64
64
|
const switchSuccessful = await trySwitchingChain(option, true);
|
|
65
65
|
if (switchSuccessful) {
|
|
66
66
|
try {
|
|
67
|
-
await payWithToken(option
|
|
67
|
+
await payWithToken(option);
|
|
68
68
|
return; // Payment successful after switching chain
|
|
69
69
|
}
|
|
70
70
|
catch (retryError) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { usePayContext, ROUTES } from '../../DaimoPay.js';
|
|
3
3
|
import { PageContent } from '../../Common/Modal/styles.js';
|
|
4
|
-
import { getAddressContraction } from '@daimo/common';
|
|
4
|
+
import { getAddressContraction, ExternalPaymentOptions } from '@daimo/common';
|
|
5
5
|
import { useWallet } from '@solana/wallet-adapter-react';
|
|
6
6
|
import { useAccount, useDisconnect } from 'wagmi';
|
|
7
7
|
import { Solana, Bitcoin, Tron, Zcash } from '../../../assets/chains.js';
|
|
@@ -67,8 +67,9 @@ const SelectMethod = () => {
|
|
|
67
67
|
const { address, chain, isConnected, connector } = useAccount();
|
|
68
68
|
const { disconnectAsync } = useDisconnect();
|
|
69
69
|
const { setRoute, paymentState, log } = usePayContext();
|
|
70
|
-
const { setSelectedExternalOption, externalPaymentOptions, depositAddressOptions, senderEnsName, } = paymentState;
|
|
70
|
+
const { daimoPayOrder, setSelectedExternalOption, externalPaymentOptions, depositAddressOptions, senderEnsName, } = paymentState;
|
|
71
71
|
const displayName = senderEnsName ?? (address ? getAddressContraction(address) : "wallet");
|
|
72
|
+
const paymentOptions = daimoPayOrder?.metadata.payer?.paymentOptions;
|
|
72
73
|
const connectedWalletOption = isConnected
|
|
73
74
|
? {
|
|
74
75
|
id: "connectedWallet",
|
|
@@ -97,30 +98,43 @@ const SelectMethod = () => {
|
|
|
97
98
|
? [connectedWalletOption, unconnectedWalletOption]
|
|
98
99
|
: [unconnectedWalletOption];
|
|
99
100
|
log(`[SELECT_METHOD] loading: ${externalPaymentOptions.loading}, options: ${JSON.stringify(externalPaymentOptions.options)}`);
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
const options = [...walletOptions];
|
|
102
|
+
// Solana payment option
|
|
103
|
+
// Include by default if paymentOptions not provided
|
|
104
|
+
const includeSolana = paymentOptions == null ||
|
|
105
|
+
paymentOptions.includes(ExternalPaymentOptions.Solana);
|
|
106
|
+
if (includeSolana) {
|
|
107
|
+
const solanaOption = getSolanaOption();
|
|
108
|
+
if (solanaOption) {
|
|
109
|
+
options.push(solanaOption);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// External payment options, e.g. Binance, Coinbase, etc.
|
|
113
|
+
options.push(...(externalPaymentOptions.options ?? []).map((option) => ({
|
|
114
|
+
id: option.id,
|
|
115
|
+
title: option.cta,
|
|
116
|
+
icons: [option.logoURI],
|
|
117
|
+
onClick: () => {
|
|
118
|
+
setSelectedExternalOption(option);
|
|
119
|
+
const meta = { event: "click-option", option: option.id };
|
|
120
|
+
if (paymentState.isDepositFlow) {
|
|
121
|
+
setRoute(ROUTES.SELECT_EXTERNAL_AMOUNT, meta);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
setRoute(ROUTES.WAITING_EXTERNAL, meta);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
disabled: option.disabled,
|
|
128
|
+
subtitle: option.message,
|
|
129
|
+
})));
|
|
130
|
+
// Deposit address options, e.g. Bitcoin, Tron, Zcash, etc.
|
|
131
|
+
// Include by default if paymentOptions not provided
|
|
132
|
+
const includeDepositAddressOption = paymentOptions == null ||
|
|
133
|
+
paymentOptions.includes(ExternalPaymentOptions.ExternalChains);
|
|
134
|
+
if (includeDepositAddressOption) {
|
|
135
|
+
const depositAddressOption = getDepositAddressOption(depositAddressOptions);
|
|
136
|
+
options.push(depositAddressOption);
|
|
137
|
+
}
|
|
124
138
|
return (jsxs(PageContent, { children: [jsx(OrderHeader, {}), jsx(OptionsList, { requiredSkeletons: isMobile ? 4 : 3, isLoading: externalPaymentOptions.loading, options: externalPaymentOptions.loading ? [] : options }), jsx(PoweredByFooter, {})] }));
|
|
125
139
|
};
|
|
126
140
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -46,7 +46,7 @@ const WaitingExternal = () => {
|
|
|
46
46
|
return (jsxs(PageContent, { children: [jsx(ExternalPaymentSpinner, { logoURI: selectedExternalOption.logoURI, logoShape: selectedExternalOption.logoShape }), jsxs(ModalContent, { style: { marginLeft: 24, marginRight: 24 }, children: [jsx(ModalH1, { children: "Waiting for Payment" }), paymentWaitingMessage && (jsx(ModalBody, { style: { marginTop: 12, marginBottom: 12 }, children: paymentWaitingMessage }))] }), jsx(Button, { icon: jsx(ExternalLinkIcon, {}), onClick: () => {
|
|
47
47
|
if (externalURL)
|
|
48
48
|
window.open(externalURL, "_blank");
|
|
49
|
-
}, children:
|
|
49
|
+
}, children: selectedExternalOption.cta })] }));
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
export { WaitingExternal as default };
|
|
@@ -6,6 +6,7 @@ const DEFAULT_EXTERNAL_PAYMENT_OPTIONS = [
|
|
|
6
6
|
ExternalPaymentOptions.Binance,
|
|
7
7
|
ExternalPaymentOptions.Daimo,
|
|
8
8
|
ExternalPaymentOptions.RampNetwork,
|
|
9
|
+
// Solana and ExternalChains are handled in the SelectMethod component.
|
|
9
10
|
];
|
|
10
11
|
function useExternalPaymentOptions({ trpc, filterIds, platform, usdRequired, mode, }) {
|
|
11
12
|
const [options, setOptions] = useState([]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useExternalPaymentOptions.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useExternalPaymentOptions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,13 +3,12 @@ import { useConnection, useWallet } from '@solana/wallet-adapter-react';
|
|
|
3
3
|
import { VersionedTransaction } from '@solana/web3.js';
|
|
4
4
|
import { hexToBytes } from 'viem';
|
|
5
5
|
|
|
6
|
-
function usePayWithSolanaToken({ trpc, daimoPayOrder, setDaimoPayOrder, createOrHydrate,
|
|
6
|
+
function usePayWithSolanaToken({ trpc, daimoPayOrder, setDaimoPayOrder, createOrHydrate, log, }) {
|
|
7
7
|
const { connection } = useConnection();
|
|
8
8
|
const wallet = useWallet();
|
|
9
9
|
const payWithSolanaToken = async (inputToken) => {
|
|
10
10
|
assert(!!wallet.publicKey, "[PAY SOLANA] No wallet connected");
|
|
11
11
|
assert(!!daimoPayOrder, "[PAY SOLANA] daimoPayOrder cannot be null");
|
|
12
|
-
assert(!!platform, "[PAY SOLANA] platform cannot be null");
|
|
13
12
|
const orderId = daimoPayOrder.id;
|
|
14
13
|
const { hydratedOrder } = await createOrHydrate({
|
|
15
14
|
order: daimoPayOrder,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayWithSolanaToken.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePayWithSolanaToken.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import { assert, assertNotNull } from '@daimo/common';
|
|
1
|
+
import { assert, debugJson, assertNotNull } from '@daimo/common';
|
|
2
2
|
import { zeroAddress, erc20Abi, getAddress } from 'viem';
|
|
3
3
|
import { useWriteContract, useSendTransaction } from 'wagmi';
|
|
4
4
|
|
|
5
|
-
function usePayWithToken({ trpc, senderAddr, daimoPayOrder, setDaimoPayOrder, createOrHydrate,
|
|
5
|
+
function usePayWithToken({ trpc, senderAddr, daimoPayOrder, setDaimoPayOrder, createOrHydrate, log, }) {
|
|
6
6
|
const { writeContractAsync } = useWriteContract();
|
|
7
7
|
const { sendTransactionAsync } = useSendTransaction();
|
|
8
8
|
/** Commit to a token + amount = initiate payment. */
|
|
9
|
-
const payWithToken = async (
|
|
9
|
+
const payWithToken = async (walletOption) => {
|
|
10
10
|
assert(!!daimoPayOrder, "[PAY TOKEN] daimoPayOrder cannot be null");
|
|
11
|
-
|
|
11
|
+
const { required, fees } = walletOption;
|
|
12
|
+
assert(required.token.token === fees.token.token, `[PAY TOKEN] required token ${debugJson(required)} does not match fees token ${debugJson(fees)}`);
|
|
13
|
+
const paymentAmount = BigInt(required.amount) + BigInt(fees.amount);
|
|
12
14
|
const { hydratedOrder } = await createOrHydrate({
|
|
13
15
|
order: daimoPayOrder,
|
|
14
16
|
refundAddress: senderAddr,
|
|
15
17
|
});
|
|
16
|
-
log(`[
|
|
18
|
+
log(`[PAY TOKEN] hydrated order: ${JSON.stringify(hydratedOrder)}, paying ${paymentAmount} of token ${required.token.token}`);
|
|
17
19
|
setDaimoPayOrder(hydratedOrder);
|
|
18
20
|
const txHash = await (async () => {
|
|
19
21
|
try {
|
|
20
|
-
if (
|
|
22
|
+
if (required.token.token === zeroAddress) {
|
|
21
23
|
return await sendTransactionAsync({
|
|
22
24
|
to: hydratedOrder.intentAddr,
|
|
23
|
-
value:
|
|
25
|
+
value: paymentAmount,
|
|
24
26
|
});
|
|
25
27
|
}
|
|
26
28
|
else {
|
|
27
29
|
return await writeContractAsync({
|
|
28
30
|
abi: erc20Abi,
|
|
29
|
-
address: getAddress(
|
|
31
|
+
address: getAddress(required.token.token),
|
|
30
32
|
functionName: "transfer",
|
|
31
|
-
args: [hydratedOrder.intentAddr,
|
|
33
|
+
args: [hydratedOrder.intentAddr, paymentAmount],
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
catch (e) {
|
|
36
|
-
console.error(`[
|
|
38
|
+
console.error(`[PAY TOKEN] error sending token: ${e}`);
|
|
37
39
|
throw e;
|
|
38
40
|
}
|
|
39
41
|
})();
|
|
@@ -41,10 +43,10 @@ function usePayWithToken({ trpc, senderAddr, daimoPayOrder, setDaimoPayOrder, cr
|
|
|
41
43
|
await trpc.processSourcePayment.mutate({
|
|
42
44
|
orderId: daimoPayOrder.id.toString(),
|
|
43
45
|
sourceInitiateTxHash: txHash,
|
|
44
|
-
sourceChainId:
|
|
46
|
+
sourceChainId: required.token.chainId,
|
|
45
47
|
sourceFulfillerAddr: assertNotNull(senderAddr, `[PAY TOKEN] senderAddr cannot be null on order ${daimoPayOrder.id}`),
|
|
46
|
-
sourceToken:
|
|
47
|
-
sourceAmount:
|
|
48
|
+
sourceToken: required.token.token,
|
|
49
|
+
sourceAmount: paymentAmount.toString(),
|
|
48
50
|
});
|
|
49
51
|
// TODO: update order immediately, do not wait for polling.
|
|
50
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePayWithToken.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePayWithToken.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -49,6 +49,7 @@ function usePaymentState({ trpc, daimoPayOrder, setDaimoPayOrder, setOpen, log,
|
|
|
49
49
|
destChainId: daimoPayOrder?.destFinalCallTokenAmount.token.chainId,
|
|
50
50
|
preferredChains: daimoPayOrder?.metadata.payer?.preferredChains,
|
|
51
51
|
preferredTokens: daimoPayOrder?.metadata.payer?.preferredTokens,
|
|
52
|
+
evmChains: daimoPayOrder?.metadata.payer?.evmChains,
|
|
52
53
|
isDepositFlow,
|
|
53
54
|
log,
|
|
54
55
|
});
|
|
@@ -101,7 +102,6 @@ function usePaymentState({ trpc, daimoPayOrder, setDaimoPayOrder, setOpen, log,
|
|
|
101
102
|
daimoPayOrder,
|
|
102
103
|
setDaimoPayOrder,
|
|
103
104
|
createOrHydrate,
|
|
104
|
-
platform,
|
|
105
105
|
log,
|
|
106
106
|
});
|
|
107
107
|
const { payWithSolanaToken } = usePayWithSolanaToken({
|
|
@@ -109,7 +109,6 @@ function usePaymentState({ trpc, daimoPayOrder, setDaimoPayOrder, setOpen, log,
|
|
|
109
109
|
daimoPayOrder,
|
|
110
110
|
setDaimoPayOrder,
|
|
111
111
|
createOrHydrate,
|
|
112
|
-
platform,
|
|
113
112
|
log,
|
|
114
113
|
});
|
|
115
114
|
const [selectedExternalOption, setSelectedExternalOption] = useState();
|
|
@@ -229,6 +228,7 @@ function usePaymentState({ trpc, daimoPayOrder, setDaimoPayOrder, setOpen, log,
|
|
|
229
228
|
paymentOptions: payParams.paymentOptions,
|
|
230
229
|
preferredChains: payParams.preferredChains,
|
|
231
230
|
preferredTokens: payParams.preferredTokens,
|
|
231
|
+
evmChains: payParams.evmChains,
|
|
232
232
|
},
|
|
233
233
|
},
|
|
234
234
|
externalId: payParams.externalId,
|
|
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
|
|
2
2
|
import { supportedChainIds } from '../utils/exports.js';
|
|
3
3
|
|
|
4
4
|
/** Wallet payment options. User picks one. */
|
|
5
|
-
function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, preferredChains, preferredTokens, isDepositFlow, log, }) {
|
|
5
|
+
function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, preferredChains, preferredTokens, evmChains, isDepositFlow, log, }) {
|
|
6
6
|
const [options, setOptions] = useState(null);
|
|
7
7
|
const [isLoading, setIsLoading] = useState(false);
|
|
8
8
|
useEffect(() => {
|
|
@@ -19,6 +19,7 @@ function useWalletPaymentOptions({ trpc, address, usdRequired, destChainId, pref
|
|
|
19
19
|
destChainId,
|
|
20
20
|
preferredChains,
|
|
21
21
|
preferredTokens,
|
|
22
|
+
evmChains,
|
|
22
23
|
});
|
|
23
24
|
// Filter out chains we don't support yet.
|
|
24
25
|
const isSupported = (o) => supportedChainIds.has(o.balance.token.chainId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWalletPaymentOptions.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useWalletPaymentOptions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daimo/pay",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.4",
|
|
5
5
|
"author": "Daimo",
|
|
6
6
|
"homepage": "https://pay.daimo.com",
|
|
7
7
|
"license": "BSD-2-Clause license",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"crypto"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@daimo/common": "1.3.
|
|
44
|
-
"@daimo/contract": "1.3.
|
|
43
|
+
"@daimo/common": "1.3.4",
|
|
44
|
+
"@daimo/contract": "1.3.4",
|
|
45
45
|
"@solana/wallet-adapter-base": "^0.9.23",
|
|
46
46
|
"@solana/wallet-adapter-react": "^0.15.35",
|
|
47
47
|
"@solana/web3.js": "^1.95.4",
|