multicoyn-sdk 0.1.5 → 0.1.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/README.md +34 -6
- package/dist/{ccip-BSPn6ibI.cjs → ccip-DKvRoXP4.cjs} +1 -1
- package/dist/{ccip-DIYBSu9T.js → ccip-Piyq8VMB.js} +1 -1
- package/dist/components/MulticoynButton.d.ts +2 -14
- package/dist/components/PaymentModal.d.ts +2 -1
- package/dist/components/PaymentSummary.d.ts +2 -1
- package/dist/components/TokenSlider.d.ts +4 -1
- package/dist/components/types.d.ts +7 -3
- package/dist/config/contracts.d.ts +7 -7
- package/dist/hooks/usePaymentRouter.d.ts +3 -1
- package/dist/index-54Nnnds1.cjs +34 -0
- package/dist/{index-CzsOkJ6p.js → index-w8B8C2nn.js} +1489 -1402
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/tokens.d.ts +4 -1
- package/package.json +5 -1
- package/dist/index-CZikbn9q.cjs +0 -34
package/README.md
CHANGED
|
@@ -44,21 +44,49 @@ function App() {
|
|
|
44
44
|
### 2. Use the Payment Button
|
|
45
45
|
|
|
46
46
|
```tsx
|
|
47
|
-
import { MulticoynButton } from 'multicoyn-sdk';
|
|
47
|
+
import { MulticoynButton, type PaymentConfig } from 'multicoyn-sdk';
|
|
48
48
|
|
|
49
49
|
function YourComponent() {
|
|
50
|
+
const handlePaymentComplete = (result) => {
|
|
51
|
+
console.log('Payment success:', result.transactionId);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handlePaymentError = (error) => {
|
|
55
|
+
console.error('Payment error:', error.message);
|
|
56
|
+
};
|
|
57
|
+
|
|
50
58
|
return (
|
|
51
59
|
<MulticoynButton
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
totalAmount={100}
|
|
61
|
+
merchantAddress="0x..."
|
|
62
|
+
items={[
|
|
63
|
+
{ name: "Product 1", price: 50 },
|
|
64
|
+
{ name: "Product 2", price: 50 }
|
|
65
|
+
]}
|
|
66
|
+
currency="USD" // or "IDR" - automatically determines settlement currency
|
|
67
|
+
onPaymentComplete={handlePaymentComplete}
|
|
68
|
+
onPaymentError={handlePaymentError}
|
|
57
69
|
/>
|
|
58
70
|
);
|
|
59
71
|
}
|
|
60
72
|
```
|
|
61
73
|
|
|
74
|
+
#### Advanced Usage with Smart Contract Interaction
|
|
75
|
+
|
|
76
|
+
```tsx
|
|
77
|
+
<MulticoynButton
|
|
78
|
+
totalAmount={100}
|
|
79
|
+
merchantAddress="0x..."
|
|
80
|
+
items={[{ name: "NFT Mint", price: 100 }]}
|
|
81
|
+
currency="USD" // or "IDR" - automatically determines settlement currency
|
|
82
|
+
// Optional: Execute custom contract call after payment
|
|
83
|
+
target="0xNFTContractAddress"
|
|
84
|
+
callData="0x..." // encoded function call
|
|
85
|
+
onPaymentComplete={handlePaymentComplete}
|
|
86
|
+
onPaymentError={handlePaymentError}
|
|
87
|
+
/>
|
|
88
|
+
```
|
|
89
|
+
|
|
62
90
|
### 3. Access Payment Configuration
|
|
63
91
|
|
|
64
92
|
```tsx
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-54Nnnds1.cjs");function k(r){const{abi:n,data:a}=r,o=e.slice(a,0,4),t=n.find(s=>s.type==="function"&&o===e.toFunctionSelector(e.formatAbiItem(s)));if(!t)throw new e.AbiFunctionSignatureNotFoundError(o,{docsPath:"/docs/contract/decodeFunctionData"});return{functionName:t.name,args:"inputs"in t&&t.inputs&&t.inputs.length>0?e.decodeAbiParameters(t.inputs,e.slice(a,4)):void 0}}const h="/docs/contract/encodeErrorResult";function y(r){const{abi:n,errorName:a,args:o}=r;let t=n[0];if(a){const f=e.getAbiItem({abi:n,args:o,name:a});if(!f)throw new e.AbiErrorNotFoundError(a,{docsPath:h});t=f}if(t.type!=="error")throw new e.AbiErrorNotFoundError(void 0,{docsPath:h});const s=e.formatAbiItem(t),c=e.toFunctionSelector(s);let i="0x";if(o&&o.length>0){if(!t.inputs)throw new e.AbiErrorInputsNotFoundError(t.name,{docsPath:h});i=e.encodeAbiParameters(t.inputs,o)}return e.concatHex([c,i])}const m="/docs/contract/encodeFunctionResult";function L(r){const{abi:n,functionName:a,result:o}=r;let t=n[0];if(a){const c=e.getAbiItem({abi:n,name:a});if(!c)throw new e.AbiFunctionNotFoundError(a,{docsPath:m});t=c}if(t.type!=="function")throw new e.AbiFunctionNotFoundError(void 0,{docsPath:m});if(!t.outputs)throw new e.AbiFunctionOutputsNotFoundError(t.name,{docsPath:m});const s=(()=>{if(t.outputs.length===0)return[];if(t.outputs.length===1)return[o];if(Array.isArray(o))return o;throw new e.InvalidArrayError(o)})();return e.encodeAbiParameters(t.outputs,s)}const b="x-batch-gateway:true";async function g(r){const{data:n,ccipRequest:a}=r,{args:[o]}=k({abi:e.batchGatewayAbi,data:n}),t=[],s=[];return await Promise.all(o.map(async(c,i)=>{try{s[i]=c.urls.includes(b)?await g({data:c.data,ccipRequest:a}):await a(c),t[i]=!1}catch(f){t[i]=!0,s[i]=F(f)}})),L({abi:e.batchGatewayAbi,functionName:"query",result:[t,s]})}function F(r){return r.name==="HttpRequestError"&&r.status?y({abi:e.batchGatewayAbi,errorName:"HttpError",args:[r.status,r.shortMessage]}):y({abi:[e.solidityError],errorName:"Error",args:["shortMessage"in r?r.shortMessage:r.message]})}function O(r,n){if(!e.isAddress(r,{strict:!1}))throw new e.InvalidAddressError({address:r});if(!e.isAddress(n,{strict:!1}))throw new e.InvalidAddressError({address:n});return r.toLowerCase()===n.toLowerCase()}class P extends e.BaseError{constructor({callbackSelector:n,cause:a,data:o,extraData:t,sender:s,urls:c}){super(a.shortMessage||"An error occurred while fetching for an offchain result.",{cause:a,metaMessages:[...a.metaMessages||[],a.metaMessages?.length?"":[],"Offchain Gateway Call:",c&&[" Gateway URL(s):",...c.map(i=>` ${e.getUrl(i)}`)],` Sender: ${s}`,` Data: ${o}`,` Callback selector: ${n}`,` Extra data: ${t}`].flat(),name:"OffchainLookupError"})}}class S extends e.BaseError{constructor({result:n,url:a}){super("Offchain gateway response is malformed. Response data must be a hex value.",{metaMessages:[`Gateway URL: ${e.getUrl(a)}`,`Response: ${e.stringify(n)}`],name:"OffchainLookupResponseMalformedError"})}}class x extends e.BaseError{constructor({sender:n,to:a}){super("Reverted sender address does not match target contract address (`to`).",{metaMessages:[`Contract address: ${a}`,`OffchainLookup sender address: ${n}`],name:"OffchainLookupSenderMismatchError"})}}const M="0x556f1830",E={name:"OffchainLookup",type:"error",inputs:[{name:"sender",type:"address"},{name:"urls",type:"string[]"},{name:"callData",type:"bytes"},{name:"callbackFunction",type:"bytes4"},{name:"extraData",type:"bytes"}]};async function N(r,{blockNumber:n,blockTag:a,data:o,to:t}){const{args:s}=e.decodeErrorResult({data:o,abi:[E]}),[c,i,f,u,d]=s,{ccipRead:l}=r,w=l&&typeof l?.request=="function"?l.request:A;try{if(!O(t,c))throw new x({sender:c,to:t});const p=i.includes(b)?await g({data:f,ccipRequest:w}):await w({data:f,sender:c,urls:i}),{data:R}=await e.call(r,{blockNumber:n,blockTag:a,data:e.concat([u,e.encodeAbiParameters([{type:"bytes"},{type:"bytes"}],[p,d])]),to:t});return R}catch(p){throw new P({callbackSelector:u,cause:p,data:o,extraData:d,sender:c,urls:i})}}async function A({data:r,sender:n,urls:a}){let o=new Error("An unknown error occurred.");for(let t=0;t<a.length;t++){const s=a[t],c=s.includes("{data}")?"GET":"POST",i=c==="POST"?{data:r,sender:n}:void 0,f=c==="POST"?{"Content-Type":"application/json"}:{};try{const u=await fetch(s.replace("{sender}",n.toLowerCase()).replace("{data}",r),{body:JSON.stringify(i),headers:f,method:c});let d;if(u.headers.get("Content-Type")?.startsWith("application/json")?d=(await u.json()).data:d=await u.text(),!u.ok){o=new e.HttpRequestError({body:i,details:d?.error?e.stringify(d.error):u.statusText,headers:u.headers,status:u.status,url:s});continue}if(!e.isHex(d)){o=new S({result:d,url:s});continue}return d}catch(u){o=new e.HttpRequestError({body:i,details:u.message,url:s})}}throw o}exports.ccipRequest=A;exports.offchainLookup=N;exports.offchainLookupAbiItem=E;exports.offchainLookupSignature=M;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { s as b, t as x, f as F, A as I, d as C, g as M, a as E, b as D, e as w, c as G, h as A, i as T, I as H, j as m, k as v, l as R, m as k, B as y, n as N, o as P, p as j, q as B, r as U, H as L, u as _ } from "./index-
|
|
1
|
+
import { s as b, t as x, f as F, A as I, d as C, g as M, a as E, b as D, e as w, c as G, h as A, i as T, I as H, j as m, k as v, l as R, m as k, B as y, n as N, o as P, p as j, q as B, r as U, H as L, u as _ } from "./index-w8B8C2nn.js";
|
|
2
2
|
function J(e) {
|
|
3
3
|
const { abi: s, data: a } = e, r = b(a, 0, 4), t = s.find((n) => n.type === "function" && r === x(F(n)));
|
|
4
4
|
if (!t)
|
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
totalAmount: number;
|
|
4
|
-
merchantAddress: `0x${string}`;
|
|
5
|
-
currency?: string;
|
|
6
|
-
items: PaymentItem[];
|
|
7
|
-
settleInIDR?: boolean;
|
|
8
|
-
onPaymentComplete?: (result: PaymentResult) => void;
|
|
9
|
-
onPaymentError?: (error: Error) => void;
|
|
10
|
-
className?: string;
|
|
11
|
-
children?: React.ReactNode;
|
|
12
|
-
}
|
|
13
|
-
export declare function MulticoynButton({ totalAmount, merchantAddress, currency, items, settleInIDR, onPaymentComplete, onPaymentError, className, children, }: MulticoynButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
-
export {};
|
|
1
|
+
import type { MulticoynButtonProps } from "./types";
|
|
2
|
+
export declare function MulticoynButton({ merchantAddress, items, config, onPaymentComplete, onPaymentError, className, children, }: MulticoynButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -11,6 +11,7 @@ interface PaymentModalProps {
|
|
|
11
11
|
transactionHash?: string;
|
|
12
12
|
isProcessing?: boolean;
|
|
13
13
|
isSuccess?: boolean;
|
|
14
|
+
conversionRate?: number;
|
|
14
15
|
}
|
|
15
|
-
export declare function PaymentModal({ isOpen, onClose, totalAmount, currency, items, tokens: initialTokens, onPaymentSubmit, fee, transactionHash, isProcessing: externalIsProcessing, isSuccess: externalIsSuccess, }: PaymentModalProps): import("react").ReactPortal | null;
|
|
16
|
+
export declare function PaymentModal({ isOpen, onClose, totalAmount, currency, items, tokens: initialTokens, onPaymentSubmit, fee, transactionHash, isProcessing: externalIsProcessing, isSuccess: externalIsSuccess, conversionRate, }: PaymentModalProps): import("react").ReactPortal | null;
|
|
16
17
|
export {};
|
|
@@ -2,6 +2,7 @@ import type { PaymentItem } from "./types";
|
|
|
2
2
|
interface PaymentSummaryProps {
|
|
3
3
|
items: PaymentItem[];
|
|
4
4
|
fee?: number;
|
|
5
|
+
currency?: string;
|
|
5
6
|
}
|
|
6
|
-
export declare function PaymentSummary({ items, fee }: PaymentSummaryProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function PaymentSummary({ items, fee, currency }: PaymentSummaryProps): import("react/jsx-runtime").JSX.Element;
|
|
7
8
|
export {};
|
|
@@ -3,6 +3,9 @@ interface TokenSliderProps {
|
|
|
3
3
|
token: Token;
|
|
4
4
|
onChange: (percentage: number) => void;
|
|
5
5
|
totalAmount: number;
|
|
6
|
+
displayAmount?: number;
|
|
7
|
+
currency?: string;
|
|
8
|
+
disabled?: boolean;
|
|
6
9
|
}
|
|
7
|
-
export declare function TokenSlider({ token, onChange, totalAmount, }: TokenSliderProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare function TokenSlider({ token, onChange, totalAmount, displayAmount, currency, disabled, }: TokenSliderProps): import("react/jsx-runtime").JSX.Element;
|
|
8
11
|
export {};
|
|
@@ -16,11 +16,15 @@ export interface PaymentItem {
|
|
|
16
16
|
name: string;
|
|
17
17
|
price: number;
|
|
18
18
|
}
|
|
19
|
+
export interface PaymentConfig {
|
|
20
|
+
currency?: "USD" | "IDR";
|
|
21
|
+
target?: `0x${string}`;
|
|
22
|
+
callData?: `0x${string}`;
|
|
23
|
+
}
|
|
19
24
|
export interface MulticoynButtonProps {
|
|
20
|
-
|
|
21
|
-
currency?: string;
|
|
25
|
+
merchantAddress: `0x${string}`;
|
|
22
26
|
items: PaymentItem[];
|
|
23
|
-
|
|
27
|
+
config?: PaymentConfig;
|
|
24
28
|
onPaymentComplete?: (result: PaymentResult) => void;
|
|
25
29
|
onPaymentError?: (error: Error) => void;
|
|
26
30
|
className?: string;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export declare const CONTRACTS: {
|
|
2
|
-
readonly PAYMENT_ROUTER: "
|
|
3
|
-
readonly TOKEN_REGISTRY: "
|
|
2
|
+
readonly PAYMENT_ROUTER: "0x73Dbc7447E3B097cFc8b08ee7896a9D27D67e2B4";
|
|
3
|
+
readonly TOKEN_REGISTRY: "0x1d2C6dfB2f127d6F3c14859c9E54cbc27bd7FcCE";
|
|
4
4
|
};
|
|
5
5
|
export declare const TOKENS: {
|
|
6
6
|
readonly NATIVE: "0x0000000000000000000000000000000000000000";
|
|
7
|
-
readonly USDC: "
|
|
8
|
-
readonly USDT: "
|
|
9
|
-
readonly DAI: "
|
|
10
|
-
readonly WBTC: "
|
|
11
|
-
readonly IDRX: "
|
|
7
|
+
readonly USDC: "0x0Ff0aED4862e168086FD8BC38a4c27cE1830228b";
|
|
8
|
+
readonly USDT: "0xBc63b0cf19b757c2a6Ef646027f8CeA7Af2c3e7F";
|
|
9
|
+
readonly DAI: "0xd2aAa24D5C305B7968e955A89F0bf4E7776E7078";
|
|
10
|
+
readonly WBTC: "0x1BEC7ec7F995B9bcd93F411B2cE7d289C6b05f03";
|
|
11
|
+
readonly IDRX: "0x39B9205cDC53114c0B0F22F04C1215A13197b4d9";
|
|
12
12
|
};
|
|
@@ -11,9 +11,11 @@ interface PaymentParams {
|
|
|
11
11
|
tokens: Token[];
|
|
12
12
|
totalAmountUSD: number;
|
|
13
13
|
settleInIDR: boolean;
|
|
14
|
+
target?: `0x${string}`;
|
|
15
|
+
callData?: `0x${string}`;
|
|
14
16
|
}
|
|
15
17
|
export declare function usePaymentRouter(): {
|
|
16
|
-
executePayment: ({ merchantAddress, tokens, totalAmountUSD, settleInIDR, }: PaymentParams) => Promise<`0x${string}`>;
|
|
18
|
+
executePayment: ({ merchantAddress, tokens, totalAmountUSD, settleInIDR, target, callData, }: PaymentParams) => Promise<`0x${string}`>;
|
|
17
19
|
useTokenRegistry: () => import("wagmi").UseReadContractReturnType<({
|
|
18
20
|
inputs: {
|
|
19
21
|
internalType: string;
|