@yodlpay/react-native 0.2.0 → 0.4.0
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 +58 -8
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +33 -5
- package/dist/index.d.mts +33 -5
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ The provider interface is always plain **EIP-1193**. Transaction **batching and
|
|
|
18
18
|
import { createSdk, YodlProvider, YodlPayment } from '@yodlpay/react-native';
|
|
19
19
|
|
|
20
20
|
const sdk = createSdk({
|
|
21
|
-
|
|
21
|
+
integrationAddress: '0x000000000000000000000000000000000000dEaD',
|
|
22
22
|
supportedChainIds: [1, 8453],
|
|
23
23
|
});
|
|
24
24
|
|
|
@@ -37,6 +37,7 @@ const sdk = createSdk({
|
|
|
37
37
|
- [Features](#features)
|
|
38
38
|
- [Platform Notes](#platform-notes)
|
|
39
39
|
- [Usage](#usage)
|
|
40
|
+
- [Signup flow](#signup-flow)
|
|
40
41
|
- [Full example](#full-example)
|
|
41
42
|
- [Optional EIP-7702 fallback](#optional-eip-7702-fallback)
|
|
42
43
|
- [API Reference](#api-reference)
|
|
@@ -83,7 +84,7 @@ import { createSdk, isPaymentQr, YodlProvider, YodlPayment } from '@yodlpay/reac
|
|
|
83
84
|
|
|
84
85
|
// 1. Create the SDK once, app-wide.
|
|
85
86
|
const sdk = createSdk({
|
|
86
|
-
|
|
87
|
+
integrationAddress: '0x000000000000000000000000000000000000dEaD', // your integration wallet address
|
|
87
88
|
supportedChainIds: [1, 8453],
|
|
88
89
|
});
|
|
89
90
|
|
|
@@ -121,7 +122,7 @@ export function PaymentScreen({ qrData, provider, address, chainId }) {
|
|
|
121
122
|
## Features
|
|
122
123
|
|
|
123
124
|
- **Wallet-agnostic** — any EIP-1193 provider (Privy, MetaMask, Coinbase Wallet, Rainbow, WalletConnect).
|
|
124
|
-
- **
|
|
125
|
+
- **Three drop-in components** — `<YodlSignup>` for onboarding, `<YodlPayment>` for QR payments, `<YodlDashboard>` for the account view.
|
|
125
126
|
- **Hardened by default** — UI locked to the Yodl origin, off-origin navigation blocked. No config.
|
|
126
127
|
- **Batching & paymasters** — bridges [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792) (`wallet_sendCalls`); native support passes through, or add the [EIP-7702 provider](#optional-eip-7702-fallback) for atomic batching + gas sponsorship.
|
|
127
128
|
- **Multi-chain** — Ethereum, Arbitrum, Base, Polygon, Optimism, BNB Chain, Gnosis.
|
|
@@ -138,6 +139,43 @@ Most apps just need the install above and a native rebuild. Edge cases:
|
|
|
138
139
|
|
|
139
140
|
Create the SDK once with `createSdk(config)` and supply wallet state at runtime via `<YodlProvider>`. Stateless helpers like `isPaymentQr(qrData)` are standalone exports — no SDK instance required to call them.
|
|
140
141
|
|
|
142
|
+
### Signup flow
|
|
143
|
+
|
|
144
|
+
Render `<YodlSignup />` when you need the hosted onboarding flow. The hosted Yodl UI owns the status check, SIWE, email capture, verification code entry, and the final signed-up screen.
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
import { useState } from 'react';
|
|
148
|
+
import { Text } from 'react-native';
|
|
149
|
+
import { YodlProvider, YodlSignup } from '@yodlpay/react-native';
|
|
150
|
+
import { sdk } from './sdk';
|
|
151
|
+
import { useWallet } from './wallet';
|
|
152
|
+
|
|
153
|
+
export function SignupScreen() {
|
|
154
|
+
const { provider, address, chainId, isConnected } = useWallet();
|
|
155
|
+
const [showSignup, setShowSignup] = useState(true);
|
|
156
|
+
|
|
157
|
+
if (!isConnected) return <Text>Connect a wallet first.</Text>;
|
|
158
|
+
if (!showSignup) return null;
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<YodlProvider sdk={sdk} provider={provider} address={address} chainId={chainId}>
|
|
162
|
+
<YodlSignup
|
|
163
|
+
onStatusChange={(status) => console.log('signup status:', status)}
|
|
164
|
+
onSignedUp={() => {
|
|
165
|
+
// Store completion however your app tracks user state.
|
|
166
|
+
console.log('signed up');
|
|
167
|
+
setShowSignup(false);
|
|
168
|
+
}}
|
|
169
|
+
onDismiss={() => setShowSignup(false)}
|
|
170
|
+
onError={console.error}
|
|
171
|
+
/>
|
|
172
|
+
</YodlProvider>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`<YodlSignup />` shows the Yodl signup flow and calls `onSignedUp` when the user is finished. The SDK does not expose account details from the hosted flow. If you need to remember that the user signed up, save completion in your own app state, storage, or backend.
|
|
178
|
+
|
|
141
179
|
### Full example
|
|
142
180
|
|
|
143
181
|
**`sdk.ts`** — create the instance once, app-wide:
|
|
@@ -146,7 +184,7 @@ Create the SDK once with `createSdk(config)` and supply wallet state at runtime
|
|
|
146
184
|
import { createSdk } from '@yodlpay/react-native';
|
|
147
185
|
|
|
148
186
|
export const sdk = createSdk({
|
|
149
|
-
|
|
187
|
+
integrationAddress: '0x000000000000000000000000000000000000dEaD',
|
|
150
188
|
// yodlUiBaseUrl defaults to https://sdk-webview.yodl.me
|
|
151
189
|
supportedChainIds: [1, 42161, 8453, 137, 10, 56, 100],
|
|
152
190
|
});
|
|
@@ -257,14 +295,14 @@ Returns a `Yodl` instance.
|
|
|
257
295
|
|
|
258
296
|
| Option | Type | Required | Default | Description |
|
|
259
297
|
| ------------------- | ----------------------------- | -------- | ----------------------------- | -------------------------------------------------------------------------- |
|
|
260
|
-
| `
|
|
298
|
+
| `integrationAddress` | `string` | Yes | — | Your integration wallet address. Identifies you to Yodl and attributes payments on chain |
|
|
261
299
|
| `supportedChainIds` | `number[]` | Yes | — | Chain IDs the wallet can switch to |
|
|
262
300
|
| `yodlUiBaseUrl` | `string` | No | `https://sdk-webview.yodl.me` | Base URL for the Yodl UI |
|
|
263
301
|
|
|
264
|
-
`
|
|
302
|
+
`integrationAddress` must be a non-empty `0x` address. The SDK sends it with package metadata on Yodl-owned requests:
|
|
265
303
|
|
|
266
304
|
```txt
|
|
267
|
-
X-Yodl-Integration-Id:
|
|
305
|
+
X-Yodl-Integration-Id: 0x000000000000000000000000000000000000dEaD
|
|
268
306
|
X-Yodl-SDK-Name: @yodlpay/react-native
|
|
269
307
|
X-Yodl-SDK-Version: <installed package version>
|
|
270
308
|
```
|
|
@@ -296,6 +334,18 @@ Supplies the SDK instance and wallet state to the components. Render it once, hi
|
|
|
296
334
|
|
|
297
335
|
`address` and `chainId` are the wallet's **live** account and chain — pass them straight from your wallet SDK's hooks (e.g. `useWallets()`, `useAccount()`), not as fixed values. They tell the embedded Yodl UI who is connected and on which chain, and the SDK pushes `accountsChanged` / `chainChanged` into the UI whenever they change — so keep them updated when the user switches account or network. (The `provider` is used only as the RPC/signing transport.)
|
|
298
336
|
|
|
337
|
+
### `<YodlSignup />`
|
|
338
|
+
|
|
339
|
+
Renders the hosted signup flow. Use this as a full-screen component inside `<YodlProvider>`.
|
|
340
|
+
|
|
341
|
+
| Prop | Type | Required | Description |
|
|
342
|
+
| ---------------- | ---------------------------------------------------------------------------- | -------- | ----------------------------------------------------- |
|
|
343
|
+
| `onStatusChange` | `(status: 'checking' \| 'signed_out' \| 'signing_up' \| 'signed_up') => void` | No | Called when the hosted flow reports signup status |
|
|
344
|
+
| `onSignedUp` | `() => void` | No | Called when signup completes |
|
|
345
|
+
| `onDismiss` | `() => void` | No | Called when the hosted success screen is dismissed |
|
|
346
|
+
| `onError` | `(error: Error) => void` | No | Called on SIWE, registration, verification, or RPC errors |
|
|
347
|
+
| `style` | `ViewStyle` | No | Container style |
|
|
348
|
+
|
|
299
349
|
### `<YodlPayment />`
|
|
300
350
|
|
|
301
351
|
Renders the payment flow for a scanned QR code. Renders nothing if `qrData` is empty or unsupported.
|
|
@@ -327,7 +377,7 @@ The Yodl UI emits generalized payment lifecycle details once it has payment stat
|
|
|
327
377
|
|
|
328
378
|
## Security
|
|
329
379
|
|
|
330
|
-
`<YodlPayment
|
|
380
|
+
`<YodlSignup>`, `<YodlPayment>`, and `<YodlDashboard>` inject an EIP-1193 provider bound to the user's wallet, so the underlying Yodl UI is **locked to the configured Yodl origin** and off-origin navigation is blocked (`onShouldStartLoadWithRequest`). This prevents origin spoofing and mid-request navigation that could intercept signed responses. The injected provider also enforces a 30 s pending-request timeout.
|
|
331
381
|
|
|
332
382
|
The bridge forwards EIP-5792 (`wallet_sendCalls`, `wallet_getCallsStatus`, `wallet_showCallsStatus`, `wallet_getCapabilities`) and all signing methods straight to the supplied wallet provider — it owns no smart-account stack and makes no RPC calls of its own (the embedded UI reads chain state through its own provider). For wallets without native EIP-5792, add `@yodlpay/react-native-eip-7702-provider` for atomic batching.
|
|
333
383
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("react-native"),r=require("react-native-webview");const i=(0,e.createContext)(null);function a({sdk:n,provider:r,address:a,chainId:o,children:s}){let c=(0,e.useMemo)(()=>({sdk:n,provider:r,address:a,chainId:o,supportedChainIds:n.config.supportedChainIds}),[n,r,a,o]);return(0,t.jsx)(i.Provider,{value:c,children:s})}function o(){let t=(0,e.useContext)(i);if(!t)throw Error(`Yodl components must be rendered inside <YodlProvider>.`);return t}function s(e){if(e.code===4001)return!0;let t=e.message.toLowerCase();return t.includes(`rejected`)||t.includes(`denied`)}function c(e,t){if(e instanceof Error)return e;if(typeof e==`object`&&e){let t=e;if(typeof t.message==`string`){let e=Error(t.message);return typeof t.code==`number`&&(e.code=t.code),e}}return Error(t)}function l(e,t=-32603){let n=e.code;return{code:typeof n==`number`?n:t,message:e.message}}function u(e){if(typeof e!=`string`||!/^0x(?:0|[1-9a-f][0-9a-f]*)$/i.test(e))return;let t=Number.parseInt(e,16);return Number.isSafeInteger(t)?t:void 0}function d(e){let t=e.code;if(t===4200||t===-32601)return!0;let n=e.message.toLowerCase();return n.includes(`method not found`)||n.includes(`method not supported`)||n.includes(`unsupported method`)||n.includes(`unsupported wc_ method`)||n.includes(`not supported`)||n.includes(`does not exist`)||n.includes(`not available`)}function f(e){return e.match(/^(https?:\/\/[^/?#]+)/i)?.[1]??null}function p(e,t){if(!e.startsWith(t))return!1;let n=e.charAt(t.length);return n===``||n===`/`||n===`?`||n===`#`}function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("react"),t=require("react/jsx-runtime"),n=require("react-native"),r=require("react-native-webview");const i=(0,e.createContext)(null);function a({sdk:n,provider:r,address:a,chainId:o,children:s}){let c=(0,e.useMemo)(()=>({sdk:n,provider:r,address:a,chainId:o,supportedChainIds:n.config.supportedChainIds}),[n,r,a,o]);return(0,t.jsx)(i.Provider,{value:c,children:s})}function o(){let t=(0,e.useContext)(i);if(!t)throw Error(`Yodl components must be rendered inside <YodlProvider>.`);return t}function s(e){if(e.code===4001)return!0;let t=e.message.toLowerCase();return t.includes(`rejected`)||t.includes(`denied`)}function c(e,t){if(e instanceof Error)return e;if(typeof e==`object`&&e){let t=e;if(typeof t.message==`string`){let e=Error(t.message);return typeof t.code==`number`&&(e.code=t.code),e}}return Error(t)}function l(e,t=-32603){let n=e.code;return{code:typeof n==`number`?n:t,message:e.message}}function u(e){if(typeof e!=`string`||!/^0x(?:0|[1-9a-f][0-9a-f]*)$/i.test(e))return;let t=Number.parseInt(e,16);return Number.isSafeInteger(t)?t:void 0}function d(e){let t=e.code;if(t===4200||t===-32601)return!0;let n=e.message.toLowerCase();return n.includes(`method not found`)||n.includes(`method not supported`)||n.includes(`unsupported method`)||n.includes(`unsupported wc_ method`)||n.includes(`not supported`)||n.includes(`does not exist`)||n.includes(`not available`)}function f(e){return e.match(/^(https?:\/\/[^/?#]+)/i)?.[1]??null}function p(e,t){if(!e.startsWith(t))return!1;let n=e.charAt(t.length);return n===``||n===`/`||n===`?`||n===`#`}const m=/^0x[a-fA-F0-9]{40}$/;function h(e){let t=e?.integrationAddress?.trim();if(!t)throw Error(`Yodl integrationAddress is required`);if(!m.test(t))throw Error(`Yodl integrationAddress is not a valid address: ${t}`);return t}function g(e){return{"X-Yodl-Integration-Id":h(e),"X-Yodl-SDK-Name":`@yodlpay/react-native`,"X-Yodl-SDK-Version":`0.4.0`}}function _(e,t){let n=e.yodlUiBaseUrl?f(e.yodlUiBaseUrl):null;if(!(!n||!p(t,n)))return g(e)}function v(e){return`0x${e.toString(16)}`}function y(e,t=`unsupported`){let n={};for(let r of e)n[v(r)]={atomic:{status:t}};return n}const b=[`wallet_addEthereumChain`,`wallet_switchEthereumChain`];function x(e){return b.some(t=>t===e)}function S(e,t,n){if(!x(e))return{error:{code:4200,message:`Unsupported chain method: ${e}`}};let r=u((t[0]??{}).chainId);if(typeof r!=`number`)return{error:{code:-32602,message:`Missing or invalid chainId parameter`}};if(!n.includes(r))return{error:{code:4902,message:`Chain ${r} not supported`}};let i=v(r);return{providerMethod:e,providerParams:e===`wallet_switchEthereumChain`?[{chainId:i}]:t,requestedChainId:r,chainIdHex:i,switchesActiveChain:e===`wallet_switchEthereumChain`}}function C(e,t){let n=e[1];return Array.isArray(n)?n.map(e=>u(e)).filter(e=>typeof e==`number`&&t.includes(e)):t}function w(e){return e.status===200||e.statusCode===200||e.status===`success`||e.status===`CONFIRMED`}function T(e){return e.status===`0x0`||e.status===`reverted`||e.status===`failure`||e.status===0}function E(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(!w(t))return;let n=t.receipts;if(n?.length&&!n.some(T))return n[n.length-1]?.transactionHash}function D(e){let t=v(e.chainId);return`(function() {
|
|
2
2
|
if (window.ethereum) return;
|
|
3
3
|
|
|
4
4
|
var _address = ${JSON.stringify(e.address.toLowerCase())};
|
|
@@ -225,4 +225,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
225
225
|
announceProvider();
|
|
226
226
|
window.addEventListener("eip6963:requestProvider", announceProvider);
|
|
227
227
|
})();
|
|
228
|
-
true;`}function D(e){return e.toLowerCase()}function O(e,t){let n=D(t.address),r=e.address!==n,i=e.propChainId!==t.chainId;if(!r&&!i)return null;let a=i&&e.activeChainId!==t.chainId;return{nextAddress:n,nextPropChainId:t.chainId,nextActiveChainId:a?t.chainId:e.activeChainId,...r?{accountsChanged:[n]}:{},...a?{chainChanged:{chainId:t.chainId,chainIdHex:_(t.chainId)}}:{}}}function k(e,t,n,r){let i=r?{id:t,error:r}:{id:t,result:n};e.current?.injectJavaScript(`window.ethereum._handleResponse(${JSON.stringify(i)});true;`)}function A(e,t,n){e.current?.injectJavaScript(`window.ethereum._emitEvent(${JSON.stringify(t)},${JSON.stringify(n)});true;`)}function j(t){let{provider:n,address:r,chainId:i,supportedChainIds:a,onTransactionSent:o,onPaymentDetails:u,onError:f,onReady:p}=t,m=(0,e.useRef)(null),h=(0,e.useRef)(D(r)),g=(0,e.useRef)(i),y=(0,e.useRef)(i),C=(0,e.useRef)(new Set),w=(0,e.useCallback)(e=>{C.current.has(e)||(C.current.add(e),o?.(e))},[o]);(0,e.useEffect)(()=>{let e=O({address:h.current,propChainId:g.current,activeChainId:y.current},{address:r,chainId:i});e&&(h.current=e.nextAddress,g.current=e.nextPropChainId,y.current=e.nextActiveChainId,e.accountsChanged&&A(m,`accountsChanged`,e.accountsChanged),e.chainChanged&&A(m,`chainChanged`,e.chainChanged.chainIdHex))},[r,i]);let j=(0,e.useMemo)(()=>E({address:r,chainId:i}),[r,i]),M=(0,e.useCallback)(async(e,t,r)=>{try{let i=x(t,r,a);if(`error`in i){k(m,e,void 0,i.error);return}await n.request({method:i.providerMethod,params:i.providerParams}),k(m,e,null),i.switchesActiveChain&&(y.current=i.requestedChainId,A(m,`chainChanged`,i.chainIdHex))}catch(t){let n=c(t,`Chain request failed`);k(m,e,void 0,l(n)),f?.(n)}},[n,a,f]),N=(0,e.useCallback)(async(e,t)=>{try{let i=t.length>0?t:[r,a.map(e=>_(e))];k(m,e,await n.request({method:`wallet_getCapabilities`,params:i}))}catch(n){let r=c(n,`Capabilities unavailable`);if(!d(r)){k(m,e,void 0,l(r));return}k(m,e,v(S(t,a),`unsupported`))}},[n,r,a]),P=(0,e.useCallback)(async(e,t)=>{try{let r=await n.request({method:`wallet_getCallsStatus`,params:t}),i=T(r);i&&w(i),k(m,e,r)}catch(t){k(m,e,void 0,l(c(t,`Failed to get call status`)))}},[n,w]),F=(0,e.useCallback)(async(e,t,r)=>{try{let i=await n.request({method:t,params:r});t===`eth_sendTransaction`&&typeof i==`string`&&w(i),k(m,e,i)}catch(t){let n=c(t,`Request failed`),r=s(n);k(m,e,void 0,r?{code:4001,message:n.message}:l(n)),r||f?.(n)}},[n,w,f]);return{uiRef:m,injectedJavaScript:j,onMessage:(0,e.useCallback)(e=>{let t;try{t=JSON.parse(e.nativeEvent.data)}catch{return}if(t.type===`yodl_ready`){p?.();return}if(t.type===`yodl_payment_details`){u?.(t.details);return}if(t.type===`yodl_payment_error`){let e=t.error?.message??`Payment details error`,n=Error(e);t.error?.code!==void 0&&(n.code=t.error.code),f?.(n);return}if(t.type!==`ethereum_rpc_request`)return;let{id:n,method:r,params:i}=t;b(r)?M(n,r,i):r===`wallet_getCapabilities`?N(n,i):r===`wallet_getCallsStatus`?P(n,i):F(n,r,i)},[M,N,P,F,u,f,p])}}function M({uri:i,sdkConfig:a,provider:o,address:s,chainId:c,supportedChainIds:l,onTransactionSent:u,onPaymentDetails:d,onError:m,style:h,backgroundColor:_=`#18181b`,sharedCookiesEnabled:v=!0,thirdPartyCookiesEnabled:y=!0,...b}){let[x,S]=(0,e.useState)(!1),C=(0,e.useCallback)(()=>S(!0),[]),{uiRef:w,injectedJavaScript:T,onMessage:E}=j({provider:o,address:s,chainId:c,supportedChainIds:l,onReady:C,...u!==void 0&&{onTransactionSent:u},...d!==void 0&&{onPaymentDetails:d},...m!==void 0&&{onError:m}});(0,e.useEffect)(()=>{if(x)return;let e=setTimeout(C,8e3);return()=>clearTimeout(e)},[x,C]);let D=(0,e.useMemo)(()=>f(i),[i]),O=(0,e.useMemo)(()=>{let e=g(a,i);return e?{uri:i,headers:e}:{uri:i}},[a,i]),k=(0,e.useMemo)(()=>e=>D?p(e.url,D)||e.url.startsWith(`about:`):!1,[D]);return(0,t.jsxs)(n.View,{style:[N.container,{backgroundColor:_},h],children:[(0,t.jsx)(r.WebView,{ref:w,source:O,originWhitelist:D?[D]:[],onShouldStartLoadWithRequest:k,javaScriptEnabled:!0,sharedCookiesEnabled:v,thirdPartyCookiesEnabled:y,injectedJavaScriptBeforeContentLoaded:T,onMessage:E,onLoadEnd:C,style:[N.ui,{backgroundColor:_}],...b}),x?null:(0,t.jsx)(n.View,{style:[N.overlay,{backgroundColor:_}],children:(0,t.jsx)(n.ActivityIndicator,{color:`#a1a1aa`})})]})}const N=n.StyleSheet.create({container:{flex:1},ui:{flex:1},overlay:{...n.StyleSheet.absoluteFillObject,alignItems:`center`,justifyContent:`center`}});function P({onTransactionSent:n,onPaymentDetails:r,onError:i,style:a,backgroundColor:s}){let{provider:c,address:l,chainId:u,supportedChainIds:d,sdk:f}=o();return(0,t.jsx)(M,{uri:(0,e.useMemo)(()=>f.config.yodlUiBaseUrl.replace(/\/$/,``),[f.config.yodlUiBaseUrl]),sdkConfig:f.config,provider:c,address:l,chainId:u,supportedChainIds:d,...n!==void 0&&{onTransactionSent:n},...r!==void 0&&{onPaymentDetails:r},...i!==void 0&&{onError:i},...a!==void 0&&{style:a},...s!==void 0&&{backgroundColor:s}})}function F(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ee(e){if(Array.isArray(e))return e}function te(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function I(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ne(e,t,n){return t&&I(e.prototype,t),n&&I(e,n),e}function re(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function ie(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function ae(e,t){return ee(e)||re(e,t)||se(e,t)||ie()}function oe(e){"@swc/helpers - typeof";return e&&typeof Symbol<`u`&&e.constructor===Symbol?`symbol`:typeof e}function se(e,t){if(e){if(typeof e==`string`)return F(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return F(e,t)}}var L=Object.defineProperty,ce=function(e,t,n){return t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},R=function(e,t){for(var n in t)L(e,n,{get:t[n],enumerable:!0})},z=function(e,t,n){return ce(e,(t===void 0?`undefined`:oe(t))===`symbol`?t:t+``,n)},le=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];function ue(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0)t=le[(o.value.charCodeAt(0)^t>>8)&255]^t<<8}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return(t^0)&65535}function B(e){for(var t=[],n=0;n<e.length;){var r=e.substring(n),i=r.substring(0,2),a=parseInt(r.substring(2,4)),o=r.substring(4,4+a);t.push({id:i,length:a,value:o}),n+=a+4}return t}function V(e){var t=``,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0){var s=o.value;if(t+=s.id,t+=(`00`+s.length).slice(-2),s.subTags){t+=V(s.subTags);continue}t+=s.value}}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return t}function H(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,n=ue(e,65535).toString(16);return n=t?n.toUpperCase():n.toLowerCase(),n=(`0000`+n).slice(-4),n}function U(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;return e+=(`00`+t).slice(-2),e+=`04`,e+=H(e,n),e}function de(e,t,n){var r=e.find(function(e){return e.id==t});return n?r?.subTags?.find(function(e){return e.id==n}):r}function W(e,t){return{id:e,length:t.length,value:t}}function G(e){var t=e.billerId,n=e.amount,r=e.ref1,i=e.ref2,a=e.ref3,o=[W(`00`,`A000000677010112`),W(`01`,t),W(`02`,r)];i&&o.push(W(`03`,i));var s=[W(`00`,`01`),W(`01`,n?`12`:`11`),W(`30`,V(o)),W(`53`,`764`),W(`58`,`TH`)];return n&&s.push(W(`54`,Number(n).toFixed(2))),a&&s.push(W(`62`,V([W(`07`,a)]))),U(V(s),`63`)}var fe=function(){"use strict";function e(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:null;te(this,e),z(this,`billerId`),z(this,`ref1`),z(this,`ref2`),z(this,`amount`),this.billerId=t,this.ref1=n,this.ref2=r,this.amount=i}return ne(e,[{key:`toString`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount,a=i?String(Number(i.toFixed(2))*100):`0`;return`|${t}\r${n}\r${r??``}\r${a}`}},{key:`toQrTag30`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return G({billerId:t,ref1:n,ref2:r??void 0,amount:i??void 0})}}],[{key:`fromString`,value:function(t){if(!t.startsWith(`|`))return null;var n=t.slice(1).split(`\r`,4);if(n.length!=4)return null;var r=ae(n,4),i=r[0],a=r[1],o=r[2],s=r[3];return new e(i,a,o.length>0?o:null,s==`0`?null:Number((parseInt(s)/100).toFixed(2)))}}]),e}(),K=function(e){return e.MSISDN=`01`,e.NATID=`02`,e.EWALLETID=`03`,e.BANKACC=`04`,e}(K||{});function pe(e){var t=e.type,n=e.target,r=e.amount;t==`MSISDN`&&(n=(`0000000000000`+n.replace(/^0/,`66`)).slice(-13));var i=V([W(`00`,`A000000677010111`),W(K[t],n)]),a=[W(`00`,`01`),W(`01`,r?`12`:`11`),W(`29`,i),W(`53`,`764`),W(`58`,`TH`)];return r&&a.push(W(`54`,Number(r).toFixed(2))),U(V(a),`63`)}R({},{ProxyType:function(){return K},anyId:function(){return pe},billPayment:function(){return G},botBarcode:function(){return me},slipVerify:function(){return he},trueMoney:function(){return _e},trueMoneySlipVerify:function(){return ve}});function me(e){var t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return new fe(t,n,r,i).toString()}function he(e){var t=e.sendingBank,n=e.transRef;return U(V([W(`00`,V([W(`00`,`000001`),W(`01`,t),W(`02`,n)])),W(`51`,`TH`)]),`91`)}function ge(e){return e.split(``).map(function(e){return e.charCodeAt(0).toString(16).padStart(4,`0`)}).join(``).toUpperCase()}function _e(e){var t=e.mobileNo,n=e.amount,r=e.message,i=V([W(`00`,`A000000677010111`),W(`03`,`14000${t}`)]),a=[W(`00`,`01`),W(`01`,n?`12`:`11`),W(`29`,i),W(`53`,`764`),W(`58`,`TH`)];return n&&a.push(W(`54`,Number(n).toFixed(2))),r&&a.push(W(`81`,ge(r))),U(V(a),`63`)}function ve(e){var t=e.eventType,n=e.transactionId,r=e.date;return U(V([W(`00`,V([W(`00`,`01`),W(`01`,`01`),W(`02`,t),W(`03`,n),W(`04`,r)]))]),`91`,!1)}function q(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function ye(e){if(Array.isArray(e))return e}function be(e){if(Array.isArray(e))return q(e)}function xe(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function J(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Se(e,t,n){return t&&J(e.prototype,t),n&&J(e,n),e}function Ce(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function we(e){if(typeof Symbol<`u`&&e[Symbol.iterator]!=null||e[`@@iterator`]!=null)return Array.from(e)}function Te(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function Ee(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function De(){throw TypeError(`Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Y(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){Ce(e,t,n[t])})}return e}function X(e,t){return ye(e)||Te(e,t)||Z(e,t)||Ee()}function Oe(e){return be(e)||we(e)||Z(e)||De()}function Z(e,t){if(e){if(typeof e==`string`)return q(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return q(e,t)}}R({},{anyId:function(){return je},bcelOneProof:function(){return Ae},billPayment:function(){return Me},slipVerify:function(){return Ne},trueMoneySlipVerify:function(){return Pe}});var ke=function(){"use strict";function e(t,n){xe(this,e),z(this,`payload`),z(this,`tags`),this.payload=t,this.tags=n}return Se(e,[{key:`getTag`,value:function(e,t){return de(this.tags,e,t)}},{key:`getTagValue`,value:function(e,t){return this.getTag(e,t)?.value}},{key:`getTags`,value:function(){return this.tags}},{key:`getPayload`,value:function(){return this.payload}},{key:`validate`,value:function(e){var t=U(V(Oe(this.tags).filter(function(t){return t.id!=e})),e);return this.payload===t}}]),e}();function Q(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;if(!e.match(/^\d{4}.+/)||t&&e.slice(-4).toUpperCase()!=H(e.slice(0,-4)))return null;var r=B(e);if(r.length==0)return null;if(n){var i=!0,a=!1,o=void 0;try{for(var s=r[Symbol.iterator](),c;!(i=(c=s.next()).done);i=!0){var l=c.value;if(!(typeof l.value!=`string`||!l.value.match(/^\d{4}.+/))){var u=B(l.value);u.every(function(e){return e.length>0&&e.length===e.value.length})&&(l.subTags=u)}}}catch(e){a=!0,o=e}finally{try{!i&&s.return!=null&&s.return()}finally{if(a)throw o}}}return new ke(e,r)}function Ae(e){var t=Q(e,!0),n=t?.getTagValue(`33`,`02`),r=t?.getTagValue(`33`,`03`),i=t?.getTagValue(`33`,`04`);return t?.getTagValue(`00`)!==`01`&&t?.getTagValue(`01`)!==`11`&&t?.getTagValue(`33`,`00`)!==`BCEL`&&t?.getTagValue(`33`,`00`)!==`ONEPROOF`?null:{type:n,ticket:r,fccref:i}}function je(e){var t=Q(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`29`,`00`);if(n!==`01`||r!==`A000000677010111`)return null;var i=Object.entries(K).find(function(e){var n=X(e,2)[1];return t?.getTagValue(`29`,n)!==void 0});if(!i)return null;var a=X(i,2),o=a[0],s=a[1],c=t.getTagValue(`29`,s);o===`MSISDN`&&c.length==13&&c.startsWith(`0066`)&&(c=`0`+c.slice(-9));var l=t?.getTagValue(`54`),u=l===void 0?void 0:parseFloat(l);return Y({type:o,target:c},u!==void 0&&{amount:u})}function Me(e){var t=Q(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`30`,`00`),i=t?.getTagValue(`30`,`01`),a=t?.getTagValue(`30`,`02`);if(n!==`01`||r!==`A000000677010112`||!i||!a)return null;var o=t?.getTagValue(`30`,`03`),s=t?.getTagValue(`62`,`07`),c=t?.getTagValue(`54`),l=c===void 0?void 0:parseFloat(c);return Y({billerId:i,ref1:a},o!==void 0&&{ref2:o},s!==void 0&&{ref3:s},l!==void 0&&{amount:l})}function Ne(e){if(!(arguments.length>1&&arguments[1]!==void 0)||arguments[1]){var t=e.lastIndexOf(`9104`);if(t!=-1){var n=e.substring(t+4);n.length>0&&n.length<4&&(e=e.substring(0,t+4)+n.padStart(4,`0`))}}var r=Q(e,!0),i=r?.getTagValue(`00`,`00`),a=r?.getTagValue(`00`,`01`),o=r?.getTagValue(`00`,`02`);return i!==`000001`||!a||!o?null:{sendingBank:a,transRef:o}}function Pe(e){var t=Q(e,!0),n=t?.getTagValue(`00`,`02`),r=t?.getTagValue(`00`,`03`),i=t?.getTagValue(`00`,`04`);return t?.getTagValue(`00`,`00`)!==`01`&&t?.getTagValue(`00`,`01`)!==`01`?null:{eventType:n,transactionId:r,date:i}}const Fe={aeon:[`PH`,`VN`,`BR`,`AR`],manteca:[`AR`,`BR`],bcpilot:[],holdstation:[`VN`]};function Ie(e){return e?e.getTagValue(`58`)??null:null}function Le(e){let t=[];for(let[n,r]of Object.entries(Fe))r.includes(e)&&t.push(n);return t}function $(e,t,n){if(!e||typeof e!=`string`||e.trim().length===0)return[];let r=e.trim(),i=[];try{let e=Ie(Q(r));if(e){let n=Le(e);for(let e of n)(!t||t.includes(e))&&i.push({provider:e,action:`resolve`});if(i.length>0)return i}}catch{}if(n){let e=n(r);e&&(!t||t.includes(`bcpilot`))&&i.push(e)}return i}function Re(e,t){return!e||typeof e!=`string`||e.trim().length===0||!$(e).find(e=>e.action===`resolve`)?null:`${t.replace(/\/$/,``)}/resolve?data=${encodeURIComponent(e)}`}function ze({qrData:n,onTransactionSent:r,onPaymentDetails:i,onError:a,style:s,backgroundColor:c}){let{provider:l,address:u,chainId:d,supportedChainIds:f,sdk:p}=o(),m=(0,e.useMemo)(()=>Re(n,p.config.yodlUiBaseUrl),[n,p.config.yodlUiBaseUrl]);return m?(0,t.jsx)(M,{uri:m,sdkConfig:p.config,provider:l,address:u,chainId:d,supportedChainIds:f,...r!==void 0&&{onTransactionSent:r},...i!==void 0&&{onPaymentDetails:i},...a!==void 0&&{onError:a},...s!==void 0&&{style:s},...c!==void 0&&{backgroundColor:c}}):null}function Be(e){return(Array.isArray(e)?e:[e]).some(e=>$(e).some(e=>e.action===`resolve`))}var Ve=class{config;constructor(e){let t=m(e),n=e.supportedChainIds;if(!Array.isArray(n)||n.length===0)throw Error(`Yodl supportedChainIds is required — provide at least one chain id`);this.config={integrationId:t,yodlUiBaseUrl:e.yodlUiBaseUrl??`https://sdk-webview.yodl.me`,supportedChainIds:[...n]}}};function He(e){return new Ve(e)}exports.Yodl=Ve,exports.YodlDashboard=P,exports.YodlPayment=ze,exports.YodlProvider=a,exports.createSdk=He,exports.isPaymentQr=Be;
|
|
228
|
+
true;`}function O(e){return e.toLowerCase()}function k(e,t){let n=O(t.address),r=e.address!==n,i=e.propChainId!==t.chainId;if(!r&&!i)return null;let a=i&&e.activeChainId!==t.chainId;return{nextAddress:n,nextPropChainId:t.chainId,nextActiveChainId:a?t.chainId:e.activeChainId,...r?{accountsChanged:[n]}:{},...a?{chainChanged:{chainId:t.chainId,chainIdHex:v(t.chainId)}}:{}}}function A(e,t,n,r){let i=r?{id:t,error:r}:{id:t,result:n};e.current?.injectJavaScript(`window.ethereum._handleResponse(${JSON.stringify(i)});true;`)}function j(e,t,n){e.current?.injectJavaScript(`window.ethereum._emitEvent(${JSON.stringify(t)},${JSON.stringify(n)});true;`)}function M(t){let{provider:n,address:r,chainId:i,supportedChainIds:a,onTransactionSent:o,onPaymentDetails:u,onSignupStatusChange:f,onSignedUp:p,onSignupDismissed:m,onError:h,onReady:g}=t,_=(0,e.useRef)(null),b=(0,e.useRef)(O(r)),w=(0,e.useRef)(i),T=(0,e.useRef)(i),M=(0,e.useRef)(new Set),N=(0,e.useCallback)(e=>{M.current.has(e)||(M.current.add(e),o?.(e))},[o]);(0,e.useEffect)(()=>{let e=k({address:b.current,propChainId:w.current,activeChainId:T.current},{address:r,chainId:i});e&&(b.current=e.nextAddress,w.current=e.nextPropChainId,T.current=e.nextActiveChainId,e.accountsChanged&&j(_,`accountsChanged`,e.accountsChanged),e.chainChanged&&j(_,`chainChanged`,e.chainChanged.chainIdHex))},[r,i]);let P=(0,e.useMemo)(()=>D({address:r,chainId:i}),[r,i]),F=(0,e.useCallback)(async(e,t,r)=>{try{let i=S(t,r,a);if(`error`in i){A(_,e,void 0,i.error);return}await n.request({method:i.providerMethod,params:i.providerParams}),A(_,e,null),i.switchesActiveChain&&(T.current=i.requestedChainId,j(_,`chainChanged`,i.chainIdHex))}catch(t){let n=c(t,`Chain request failed`);A(_,e,void 0,l(n)),h?.(n)}},[n,a,h]),I=(0,e.useCallback)(async(e,t)=>{try{let i=t.length>0?t:[r,a.map(e=>v(e))];A(_,e,await n.request({method:`wallet_getCapabilities`,params:i}))}catch(n){let r=c(n,`Capabilities unavailable`);if(!d(r)){A(_,e,void 0,l(r));return}A(_,e,y(C(t,a),`unsupported`))}},[n,r,a]),L=(0,e.useCallback)(async(e,t)=>{try{let r=await n.request({method:`wallet_getCallsStatus`,params:t}),i=E(r);i&&N(i),A(_,e,r)}catch(t){A(_,e,void 0,l(c(t,`Failed to get call status`)))}},[n,N]),R=(0,e.useCallback)(async(e,t,r)=>{try{let i=await n.request({method:t,params:r});t===`eth_sendTransaction`&&typeof i==`string`&&N(i),A(_,e,i)}catch(t){let n=c(t,`Request failed`),r=s(n);A(_,e,void 0,r?{code:4001,message:n.message}:l(n)),r||h?.(n)}},[n,N,h]);return{uiRef:_,injectedJavaScript:P,onMessage:(0,e.useCallback)(e=>{let t;try{t=JSON.parse(e.nativeEvent.data)}catch{return}if(t.type===`yodl_ready`){g?.();return}if(t.type===`yodl_payment_details`){u?.(t.details);return}if(t.type===`yodl_payment_error`){let e=t.error?.message??`Payment details error`,n=Error(e);t.error?.code!==void 0&&(n.code=t.error.code),h?.(n);return}if(t.type===`yodl_signup_status`){f?.(t.status);return}if(t.type===`yodl_signup_complete`){p?.();return}if(t.type===`yodl_signup_error`){let e=t.error?.message??`Signup error`,n=Error(e);t.error?.code!==void 0&&(n.code=t.error.code),h?.(n);return}if(t.type===`yodl_signup_dismissed`){m?.();return}if(t.type!==`ethereum_rpc_request`)return;let{id:n,method:r,params:i}=t;x(r)?F(n,r,i):r===`wallet_getCapabilities`?I(n,i):r===`wallet_getCallsStatus`?L(n,i):R(n,r,i)},[F,I,L,R,u,f,p,m,h,g])}}function N({uri:i,sdkConfig:a,provider:o,address:s,chainId:c,supportedChainIds:l,onTransactionSent:u,onPaymentDetails:d,onSignupStatusChange:m,onSignedUp:h,onSignupDismissed:g,onError:v,style:y,backgroundColor:b=`#18181b`,sharedCookiesEnabled:x=!0,thirdPartyCookiesEnabled:S=!0,...C}){let[w,T]=(0,e.useState)(!1),E=(0,e.useCallback)(()=>T(!0),[]),{uiRef:D,injectedJavaScript:O,onMessage:k}=M({provider:o,address:s,chainId:c,supportedChainIds:l,onReady:E,...u!==void 0&&{onTransactionSent:u},...d!==void 0&&{onPaymentDetails:d},...m!==void 0&&{onSignupStatusChange:m},...h!==void 0&&{onSignedUp:h},...g!==void 0&&{onSignupDismissed:g},...v!==void 0&&{onError:v}});(0,e.useEffect)(()=>{if(w)return;let e=setTimeout(E,8e3);return()=>clearTimeout(e)},[w,E]);let A=(0,e.useMemo)(()=>f(i),[i]),j=(0,e.useMemo)(()=>{let e=_(a,i);return e?{uri:i,headers:e}:{uri:i}},[a,i]),N=(0,e.useMemo)(()=>e=>A?p(e.url,A)||e.url.startsWith(`about:`):!1,[A]);return(0,t.jsxs)(n.View,{style:[P.container,{backgroundColor:b},y],children:[(0,t.jsx)(r.WebView,{ref:D,source:j,originWhitelist:A?[A]:[],onShouldStartLoadWithRequest:N,javaScriptEnabled:!0,sharedCookiesEnabled:x,thirdPartyCookiesEnabled:S,injectedJavaScriptBeforeContentLoaded:O,onMessage:k,onLoadEnd:E,style:[P.ui,{backgroundColor:b}],...C}),w?null:(0,t.jsx)(n.View,{style:[P.overlay,{backgroundColor:b}],children:(0,t.jsx)(n.ActivityIndicator,{color:`#a1a1aa`})})]})}const P=n.StyleSheet.create({container:{flex:1},ui:{flex:1},overlay:{...n.StyleSheet.absoluteFillObject,alignItems:`center`,justifyContent:`center`}});function F({onTransactionSent:n,onPaymentDetails:r,onError:i,style:a,backgroundColor:s}){let{provider:c,address:l,chainId:u,supportedChainIds:d,sdk:f}=o();return(0,t.jsx)(N,{uri:(0,e.useMemo)(()=>f.config.yodlUiBaseUrl.replace(/\/$/,``),[f.config.yodlUiBaseUrl]),sdkConfig:f.config,provider:c,address:l,chainId:u,supportedChainIds:d,...n!==void 0&&{onTransactionSent:n},...r!==void 0&&{onPaymentDetails:r},...i!==void 0&&{onError:i},...a!==void 0&&{style:a},...s!==void 0&&{backgroundColor:s}})}function I(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function L(e){if(Array.isArray(e))return e}function R(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function z(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ee(e,t,n){return t&&z(e.prototype,t),n&&z(e,n),e}function te(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function ne(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function re(e,t){return L(e)||te(e,t)||ae(e,t)||ne()}function ie(e){"@swc/helpers - typeof";return e&&typeof Symbol<`u`&&e.constructor===Symbol?`symbol`:typeof e}function ae(e,t){if(e){if(typeof e==`string`)return I(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return I(e,t)}}var B=Object.defineProperty,oe=function(e,t,n){return t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},V=function(e,t){for(var n in t)B(e,n,{get:t[n],enumerable:!0})},H=function(e,t,n){return oe(e,(t===void 0?`undefined`:ie(t))===`symbol`?t:t+``,n)},se=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];function ce(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0)t=se[(o.value.charCodeAt(0)^t>>8)&255]^t<<8}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return(t^0)&65535}function U(e){for(var t=[],n=0;n<e.length;){var r=e.substring(n),i=r.substring(0,2),a=parseInt(r.substring(2,4)),o=r.substring(4,4+a);t.push({id:i,length:a,value:o}),n+=a+4}return t}function W(e){var t=``,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0){var s=o.value;if(t+=s.id,t+=(`00`+s.length).slice(-2),s.subTags){t+=W(s.subTags);continue}t+=s.value}}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return t}function G(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,n=ce(e,65535).toString(16);return n=t?n.toUpperCase():n.toLowerCase(),n=(`0000`+n).slice(-4),n}function K(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;return e+=(`00`+t).slice(-2),e+=`04`,e+=G(e,n),e}function le(e,t,n){var r=e.find(function(e){return e.id==t});return n?r?.subTags?.find(function(e){return e.id==n}):r}function q(e,t){return{id:e,length:t.length,value:t}}function J(e){var t=e.billerId,n=e.amount,r=e.ref1,i=e.ref2,a=e.ref3,o=[q(`00`,`A000000677010112`),q(`01`,t),q(`02`,r)];i&&o.push(q(`03`,i));var s=[q(`00`,`01`),q(`01`,n?`12`:`11`),q(`30`,W(o)),q(`53`,`764`),q(`58`,`TH`)];return n&&s.push(q(`54`,Number(n).toFixed(2))),a&&s.push(q(`62`,W([q(`07`,a)]))),K(W(s),`63`)}var ue=function(){"use strict";function e(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:null;R(this,e),H(this,`billerId`),H(this,`ref1`),H(this,`ref2`),H(this,`amount`),this.billerId=t,this.ref1=n,this.ref2=r,this.amount=i}return ee(e,[{key:`toString`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount,a=i?String(Number(i.toFixed(2))*100):`0`;return`|${t}\r${n}\r${r??``}\r${a}`}},{key:`toQrTag30`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return J({billerId:t,ref1:n,ref2:r??void 0,amount:i??void 0})}}],[{key:`fromString`,value:function(t){if(!t.startsWith(`|`))return null;var n=t.slice(1).split(`\r`,4);if(n.length!=4)return null;var r=re(n,4),i=r[0],a=r[1],o=r[2],s=r[3];return new e(i,a,o.length>0?o:null,s==`0`?null:Number((parseInt(s)/100).toFixed(2)))}}]),e}(),Y=function(e){return e.MSISDN=`01`,e.NATID=`02`,e.EWALLETID=`03`,e.BANKACC=`04`,e}(Y||{});function de(e){var t=e.type,n=e.target,r=e.amount;t==`MSISDN`&&(n=(`0000000000000`+n.replace(/^0/,`66`)).slice(-13));var i=W([q(`00`,`A000000677010111`),q(Y[t],n)]),a=[q(`00`,`01`),q(`01`,r?`12`:`11`),q(`29`,i),q(`53`,`764`),q(`58`,`TH`)];return r&&a.push(q(`54`,Number(r).toFixed(2))),K(W(a),`63`)}V({},{ProxyType:function(){return Y},anyId:function(){return de},billPayment:function(){return J},botBarcode:function(){return fe},slipVerify:function(){return pe},trueMoney:function(){return he},trueMoneySlipVerify:function(){return ge}});function fe(e){var t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return new ue(t,n,r,i).toString()}function pe(e){var t=e.sendingBank,n=e.transRef;return K(W([q(`00`,W([q(`00`,`000001`),q(`01`,t),q(`02`,n)])),q(`51`,`TH`)]),`91`)}function me(e){return e.split(``).map(function(e){return e.charCodeAt(0).toString(16).padStart(4,`0`)}).join(``).toUpperCase()}function he(e){var t=e.mobileNo,n=e.amount,r=e.message,i=W([q(`00`,`A000000677010111`),q(`03`,`14000${t}`)]),a=[q(`00`,`01`),q(`01`,n?`12`:`11`),q(`29`,i),q(`53`,`764`),q(`58`,`TH`)];return n&&a.push(q(`54`,Number(n).toFixed(2))),r&&a.push(q(`81`,me(r))),K(W(a),`63`)}function ge(e){var t=e.eventType,n=e.transactionId,r=e.date;return K(W([q(`00`,W([q(`00`,`01`),q(`01`,`01`),q(`02`,t),q(`03`,n),q(`04`,r)]))]),`91`,!1)}function X(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function _e(e){if(Array.isArray(e))return e}function ve(e){if(Array.isArray(e))return X(e)}function ye(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function Z(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function be(e,t,n){return t&&Z(e.prototype,t),n&&Z(e,n),e}function xe(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Se(e){if(typeof Symbol<`u`&&e[Symbol.iterator]!=null||e[`@@iterator`]!=null)return Array.from(e)}function Ce(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function we(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Te(){throw TypeError(`Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ee(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){xe(e,t,n[t])})}return e}function De(e,t){return _e(e)||Ce(e,t)||ke(e,t)||we()}function Oe(e){return ve(e)||Se(e)||ke(e)||Te()}function ke(e,t){if(e){if(typeof e==`string`)return X(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return X(e,t)}}V({},{anyId:function(){return Me},bcelOneProof:function(){return je},billPayment:function(){return Ne},slipVerify:function(){return Pe},trueMoneySlipVerify:function(){return Fe}});var Ae=function(){"use strict";function e(t,n){ye(this,e),H(this,`payload`),H(this,`tags`),this.payload=t,this.tags=n}return be(e,[{key:`getTag`,value:function(e,t){return le(this.tags,e,t)}},{key:`getTagValue`,value:function(e,t){return this.getTag(e,t)?.value}},{key:`getTags`,value:function(){return this.tags}},{key:`getPayload`,value:function(){return this.payload}},{key:`validate`,value:function(e){var t=K(W(Oe(this.tags).filter(function(t){return t.id!=e})),e);return this.payload===t}}]),e}();function Q(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;if(!e.match(/^\d{4}.+/)||t&&e.slice(-4).toUpperCase()!=G(e.slice(0,-4)))return null;var r=U(e);if(r.length==0)return null;if(n){var i=!0,a=!1,o=void 0;try{for(var s=r[Symbol.iterator](),c;!(i=(c=s.next()).done);i=!0){var l=c.value;if(!(typeof l.value!=`string`||!l.value.match(/^\d{4}.+/))){var u=U(l.value);u.every(function(e){return e.length>0&&e.length===e.value.length})&&(l.subTags=u)}}}catch(e){a=!0,o=e}finally{try{!i&&s.return!=null&&s.return()}finally{if(a)throw o}}}return new Ae(e,r)}function je(e){var t=Q(e,!0),n=t?.getTagValue(`33`,`02`),r=t?.getTagValue(`33`,`03`),i=t?.getTagValue(`33`,`04`);return t?.getTagValue(`00`)!==`01`&&t?.getTagValue(`01`)!==`11`&&t?.getTagValue(`33`,`00`)!==`BCEL`&&t?.getTagValue(`33`,`00`)!==`ONEPROOF`?null:{type:n,ticket:r,fccref:i}}function Me(e){var t=Q(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`29`,`00`);if(n!==`01`||r!==`A000000677010111`)return null;var i=Object.entries(Y).find(function(e){var n=De(e,2)[1];return t?.getTagValue(`29`,n)!==void 0});if(!i)return null;var a=De(i,2),o=a[0],s=a[1],c=t.getTagValue(`29`,s);o===`MSISDN`&&c.length==13&&c.startsWith(`0066`)&&(c=`0`+c.slice(-9));var l=t?.getTagValue(`54`),u=l===void 0?void 0:parseFloat(l);return Ee({type:o,target:c},u!==void 0&&{amount:u})}function Ne(e){var t=Q(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`30`,`00`),i=t?.getTagValue(`30`,`01`),a=t?.getTagValue(`30`,`02`);if(n!==`01`||r!==`A000000677010112`||!i||!a)return null;var o=t?.getTagValue(`30`,`03`),s=t?.getTagValue(`62`,`07`),c=t?.getTagValue(`54`),l=c===void 0?void 0:parseFloat(c);return Ee({billerId:i,ref1:a},o!==void 0&&{ref2:o},s!==void 0&&{ref3:s},l!==void 0&&{amount:l})}function Pe(e){if(!(arguments.length>1&&arguments[1]!==void 0)||arguments[1]){var t=e.lastIndexOf(`9104`);if(t!=-1){var n=e.substring(t+4);n.length>0&&n.length<4&&(e=e.substring(0,t+4)+n.padStart(4,`0`))}}var r=Q(e,!0),i=r?.getTagValue(`00`,`00`),a=r?.getTagValue(`00`,`01`),o=r?.getTagValue(`00`,`02`);return i!==`000001`||!a||!o?null:{sendingBank:a,transRef:o}}function Fe(e){var t=Q(e,!0),n=t?.getTagValue(`00`,`02`),r=t?.getTagValue(`00`,`03`),i=t?.getTagValue(`00`,`04`);return t?.getTagValue(`00`,`00`)!==`01`&&t?.getTagValue(`00`,`01`)!==`01`?null:{eventType:n,transactionId:r,date:i}}const Ie={aeon:[`PH`,`VN`,`BR`,`AR`],manteca:[`AR`,`BR`],bcpilot:[],holdstation:[`VN`]};function Le(e){return e?e.getTagValue(`58`)??null:null}function Re(e){let t=[];for(let[n,r]of Object.entries(Ie))r.includes(e)&&t.push(n);return t}function ze(e,t,n){if(!e||typeof e!=`string`||e.trim().length===0)return[];let r=e.trim(),i=[];try{let e=Le(Q(r));if(e){let n=Re(e);for(let e of n)(!t||t.includes(e))&&i.push({provider:e,action:`resolve`});if(i.length>0)return i}}catch{}if(n){let e=n(r);e&&(!t||t.includes(`bcpilot`))&&i.push(e)}return i}function Be(e,t){return!e||typeof e!=`string`||e.trim().length===0||!ze(e).find(e=>e.action===`resolve`)?null:`${t.replace(/\/$/,``)}/resolve?data=${encodeURIComponent(e)}`}function Ve({qrData:n,onTransactionSent:r,onPaymentDetails:i,onError:a,style:s,backgroundColor:c}){let{provider:l,address:u,chainId:d,supportedChainIds:f,sdk:p}=o(),m=(0,e.useMemo)(()=>Be(n,p.config.yodlUiBaseUrl),[n,p.config.yodlUiBaseUrl]);return m?(0,t.jsx)(N,{uri:m,sdkConfig:p.config,provider:l,address:u,chainId:d,supportedChainIds:f,...r!==void 0&&{onTransactionSent:r},...i!==void 0&&{onPaymentDetails:i},...a!==void 0&&{onError:a},...s!==void 0&&{style:s},...c!==void 0&&{backgroundColor:c}}):null}function He(e){return`${e.replace(/\/$/,``)}/sdk/signup`}function Ue({onStatusChange:n,onSignedUp:r,onError:i,onDismiss:a,style:s,backgroundColor:c}){let{provider:l,address:u,chainId:d,supportedChainIds:f,sdk:p}=o();return(0,t.jsx)(N,{uri:(0,e.useMemo)(()=>He(p.config.yodlUiBaseUrl),[p.config.yodlUiBaseUrl]),sdkConfig:p.config,provider:l,address:u,chainId:d,supportedChainIds:f,...n!==void 0&&{onSignupStatusChange:n},...r!==void 0&&{onSignedUp:r},...i!==void 0&&{onError:i},...a!==void 0&&{onSignupDismissed:a},...s!==void 0&&{style:s},...c!==void 0&&{backgroundColor:c}})}function We(e){return(Array.isArray(e)?e:[e]).some(e=>ze(e).some(e=>e.action===`resolve`))}var $=class{config;constructor(e){let t=h(e),n=e.supportedChainIds;if(!Array.isArray(n)||n.length===0)throw Error(`Yodl supportedChainIds is required — provide at least one chain id`);this.config={integrationAddress:t,yodlUiBaseUrl:e.yodlUiBaseUrl??`https://sdk-webview.yodl.me`,supportedChainIds:[...n]}}};function Ge(e){return new $(e)}exports.Yodl=$,exports.YodlDashboard=F,exports.YodlPayment=Ve,exports.YodlProvider=a,exports.YodlSignup=Ue,exports.createSdk=Ge,exports.isPaymentQr=We;
|
package/dist/index.d.cts
CHANGED
|
@@ -18,6 +18,7 @@ interface EIP1193Provider {
|
|
|
18
18
|
}
|
|
19
19
|
type SupportedChainIds = number[];
|
|
20
20
|
type YodlPaymentLifecycleStatus = 'submitted' | 'processing' | 'success' | 'failure';
|
|
21
|
+
type YodlSignupStatus = 'checking' | 'signed_out' | 'signing_up' | 'signed_up';
|
|
21
22
|
interface YodlPaymentDetails {
|
|
22
23
|
status: YodlPaymentLifecycleStatus;
|
|
23
24
|
transaction: {
|
|
@@ -81,8 +82,8 @@ interface YodlEventHandlers {
|
|
|
81
82
|
/** Called on RPC / payment errors. */
|
|
82
83
|
onError?: (error: Error) => void;
|
|
83
84
|
}
|
|
84
|
-
/**
|
|
85
|
-
interface
|
|
85
|
+
/** Visual props shared by all Yodl UI components. */
|
|
86
|
+
interface YodlVisualProps {
|
|
86
87
|
style?: ViewStyle;
|
|
87
88
|
/**
|
|
88
89
|
* Color painted behind the WebView and in the loading overlay while the Yodl
|
|
@@ -91,6 +92,8 @@ interface YodlComponentProps extends YodlEventHandlers {
|
|
|
91
92
|
*/
|
|
92
93
|
backgroundColor?: string;
|
|
93
94
|
}
|
|
95
|
+
/** Props shared by the Yodl UI components (YodlPayment, YodlDashboard). */
|
|
96
|
+
interface YodlComponentProps extends YodlVisualProps, YodlEventHandlers {}
|
|
94
97
|
//#endregion
|
|
95
98
|
//#region src/components/YodlDashboard.d.ts
|
|
96
99
|
type YodlDashboardProps = YodlComponentProps;
|
|
@@ -127,6 +130,31 @@ declare function YodlPayment({
|
|
|
127
130
|
backgroundColor
|
|
128
131
|
}: YodlPaymentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
129
132
|
//#endregion
|
|
133
|
+
//#region src/components/YodlSignup.d.ts
|
|
134
|
+
interface YodlSignupProps extends YodlVisualProps {
|
|
135
|
+
/** Called when the hosted signup flow reports checking/signing/signed status. */
|
|
136
|
+
onStatusChange?: (status: YodlSignupStatus) => void;
|
|
137
|
+
/** Called when the hosted signup flow completes successfully. */
|
|
138
|
+
onSignedUp?: () => void;
|
|
139
|
+
/** Called when the hosted signup flow reports an error. */
|
|
140
|
+
onError?: (error: Error) => void;
|
|
141
|
+
/** Called when the hosted signup flow is dismissed. */
|
|
142
|
+
onDismiss?: () => void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Renders the hosted Yodl signup flow. The WebView owns SIWE, email capture,
|
|
146
|
+
* verification code entry, and the final signed-up screen, while callbacks let
|
|
147
|
+
* the native app observe status and completion.
|
|
148
|
+
*/
|
|
149
|
+
declare function YodlSignup({
|
|
150
|
+
onStatusChange,
|
|
151
|
+
onSignedUp,
|
|
152
|
+
onError,
|
|
153
|
+
onDismiss,
|
|
154
|
+
style,
|
|
155
|
+
backgroundColor
|
|
156
|
+
}: YodlSignupProps): import("react/jsx-runtime").JSX.Element;
|
|
157
|
+
//#endregion
|
|
130
158
|
//#region src/sdk/yodl.d.ts
|
|
131
159
|
/**
|
|
132
160
|
* App-host configuration for the Yodl React Native SDK.
|
|
@@ -137,8 +165,8 @@ declare function YodlPayment({
|
|
|
137
165
|
* methods to the host wallet.
|
|
138
166
|
*/
|
|
139
167
|
interface YodlConfig {
|
|
140
|
-
/**
|
|
141
|
-
|
|
168
|
+
/** Your integration wallet address. Identifies you to Yodl and attributes payments on chain. */
|
|
169
|
+
integrationAddress: `0x${string}`;
|
|
142
170
|
/** Base URL for the Yodl UI (default: https://sdk-webview.yodl.me). */
|
|
143
171
|
yodlUiBaseUrl?: string;
|
|
144
172
|
/** Chain IDs the host wallet can switch to. */
|
|
@@ -199,4 +227,4 @@ declare function YodlProvider({
|
|
|
199
227
|
*/
|
|
200
228
|
declare function isPaymentQr(qrData: string | string[]): boolean;
|
|
201
229
|
//#endregion
|
|
202
|
-
export { type EIP1193Provider, type SupportedChainIds, Yodl, type YodlConfig, YodlDashboard, type YodlDashboardProps, YodlPayment, type YodlPaymentDetails, type YodlPaymentLifecycleStatus, type YodlPaymentProps, YodlProvider, type YodlProviderProps, createSdk, isPaymentQr };
|
|
230
|
+
export { type EIP1193Provider, type SupportedChainIds, Yodl, type YodlConfig, YodlDashboard, type YodlDashboardProps, YodlPayment, type YodlPaymentDetails, type YodlPaymentLifecycleStatus, type YodlPaymentProps, YodlProvider, type YodlProviderProps, YodlSignup, type YodlSignupProps, type YodlSignupStatus, createSdk, isPaymentQr };
|
package/dist/index.d.mts
CHANGED
|
@@ -18,6 +18,7 @@ interface EIP1193Provider {
|
|
|
18
18
|
}
|
|
19
19
|
type SupportedChainIds = number[];
|
|
20
20
|
type YodlPaymentLifecycleStatus = 'submitted' | 'processing' | 'success' | 'failure';
|
|
21
|
+
type YodlSignupStatus = 'checking' | 'signed_out' | 'signing_up' | 'signed_up';
|
|
21
22
|
interface YodlPaymentDetails {
|
|
22
23
|
status: YodlPaymentLifecycleStatus;
|
|
23
24
|
transaction: {
|
|
@@ -81,8 +82,8 @@ interface YodlEventHandlers {
|
|
|
81
82
|
/** Called on RPC / payment errors. */
|
|
82
83
|
onError?: (error: Error) => void;
|
|
83
84
|
}
|
|
84
|
-
/**
|
|
85
|
-
interface
|
|
85
|
+
/** Visual props shared by all Yodl UI components. */
|
|
86
|
+
interface YodlVisualProps {
|
|
86
87
|
style?: ViewStyle;
|
|
87
88
|
/**
|
|
88
89
|
* Color painted behind the WebView and in the loading overlay while the Yodl
|
|
@@ -91,6 +92,8 @@ interface YodlComponentProps extends YodlEventHandlers {
|
|
|
91
92
|
*/
|
|
92
93
|
backgroundColor?: string;
|
|
93
94
|
}
|
|
95
|
+
/** Props shared by the Yodl UI components (YodlPayment, YodlDashboard). */
|
|
96
|
+
interface YodlComponentProps extends YodlVisualProps, YodlEventHandlers {}
|
|
94
97
|
//#endregion
|
|
95
98
|
//#region src/components/YodlDashboard.d.ts
|
|
96
99
|
type YodlDashboardProps = YodlComponentProps;
|
|
@@ -127,6 +130,31 @@ declare function YodlPayment({
|
|
|
127
130
|
backgroundColor
|
|
128
131
|
}: YodlPaymentProps): import("react/jsx-runtime").JSX.Element | null;
|
|
129
132
|
//#endregion
|
|
133
|
+
//#region src/components/YodlSignup.d.ts
|
|
134
|
+
interface YodlSignupProps extends YodlVisualProps {
|
|
135
|
+
/** Called when the hosted signup flow reports checking/signing/signed status. */
|
|
136
|
+
onStatusChange?: (status: YodlSignupStatus) => void;
|
|
137
|
+
/** Called when the hosted signup flow completes successfully. */
|
|
138
|
+
onSignedUp?: () => void;
|
|
139
|
+
/** Called when the hosted signup flow reports an error. */
|
|
140
|
+
onError?: (error: Error) => void;
|
|
141
|
+
/** Called when the hosted signup flow is dismissed. */
|
|
142
|
+
onDismiss?: () => void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Renders the hosted Yodl signup flow. The WebView owns SIWE, email capture,
|
|
146
|
+
* verification code entry, and the final signed-up screen, while callbacks let
|
|
147
|
+
* the native app observe status and completion.
|
|
148
|
+
*/
|
|
149
|
+
declare function YodlSignup({
|
|
150
|
+
onStatusChange,
|
|
151
|
+
onSignedUp,
|
|
152
|
+
onError,
|
|
153
|
+
onDismiss,
|
|
154
|
+
style,
|
|
155
|
+
backgroundColor
|
|
156
|
+
}: YodlSignupProps): import("react/jsx-runtime").JSX.Element;
|
|
157
|
+
//#endregion
|
|
130
158
|
//#region src/sdk/yodl.d.ts
|
|
131
159
|
/**
|
|
132
160
|
* App-host configuration for the Yodl React Native SDK.
|
|
@@ -137,8 +165,8 @@ declare function YodlPayment({
|
|
|
137
165
|
* methods to the host wallet.
|
|
138
166
|
*/
|
|
139
167
|
interface YodlConfig {
|
|
140
|
-
/**
|
|
141
|
-
|
|
168
|
+
/** Your integration wallet address. Identifies you to Yodl and attributes payments on chain. */
|
|
169
|
+
integrationAddress: `0x${string}`;
|
|
142
170
|
/** Base URL for the Yodl UI (default: https://sdk-webview.yodl.me). */
|
|
143
171
|
yodlUiBaseUrl?: string;
|
|
144
172
|
/** Chain IDs the host wallet can switch to. */
|
|
@@ -199,4 +227,4 @@ declare function YodlProvider({
|
|
|
199
227
|
*/
|
|
200
228
|
declare function isPaymentQr(qrData: string | string[]): boolean;
|
|
201
229
|
//#endregion
|
|
202
|
-
export { type EIP1193Provider, type SupportedChainIds, Yodl, type YodlConfig, YodlDashboard, type YodlDashboardProps, YodlPayment, type YodlPaymentDetails, type YodlPaymentLifecycleStatus, type YodlPaymentProps, YodlProvider, type YodlProviderProps, createSdk, isPaymentQr };
|
|
230
|
+
export { type EIP1193Provider, type SupportedChainIds, Yodl, type YodlConfig, YodlDashboard, type YodlDashboardProps, YodlPayment, type YodlPaymentDetails, type YodlPaymentLifecycleStatus, type YodlPaymentProps, YodlProvider, type YodlProviderProps, YodlSignup, type YodlSignupProps, type YodlSignupStatus, createSdk, isPaymentQr };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{createContext as e,useCallback as t,useContext as n,useEffect as r,useMemo as i,useRef as a,useState as o}from"react";import{jsx as s,jsxs as c}from"react/jsx-runtime";import{ActivityIndicator as l,StyleSheet as u,View as d}from"react-native";import{WebView as f}from"react-native-webview";const p=e(null);function m({sdk:e,provider:t,address:n,chainId:r,children:a}){let o=i(()=>({sdk:e,provider:t,address:n,chainId:r,supportedChainIds:e.config.supportedChainIds}),[e,t,n,r]);return s(p.Provider,{value:o,children:a})}function h(){let e=n(p);if(!e)throw Error(`Yodl components must be rendered inside <YodlProvider>.`);return e}function g(e){if(e.code===4001)return!0;let t=e.message.toLowerCase();return t.includes(`rejected`)||t.includes(`denied`)}function _(e,t){if(e instanceof Error)return e;if(typeof e==`object`&&e){let t=e;if(typeof t.message==`string`){let e=Error(t.message);return typeof t.code==`number`&&(e.code=t.code),e}}return Error(t)}function v(e,t=-32603){let n=e.code;return{code:typeof n==`number`?n:t,message:e.message}}function y(e){if(typeof e!=`string`||!/^0x(?:0|[1-9a-f][0-9a-f]*)$/i.test(e))return;let t=Number.parseInt(e,16);return Number.isSafeInteger(t)?t:void 0}function b(e){let t=e.code;if(t===4200||t===-32601)return!0;let n=e.message.toLowerCase();return n.includes(`method not found`)||n.includes(`method not supported`)||n.includes(`unsupported method`)||n.includes(`unsupported wc_ method`)||n.includes(`not supported`)||n.includes(`does not exist`)||n.includes(`not available`)}function x(e){return e.match(/^(https?:\/\/[^/?#]+)/i)?.[1]??null}function S(e,t){if(!e.startsWith(t))return!1;let n=e.charAt(t.length);return n===``||n===`/`||n===`?`||n===`#`}function
|
|
1
|
+
import{createContext as e,useCallback as t,useContext as n,useEffect as r,useMemo as i,useRef as a,useState as o}from"react";import{jsx as s,jsxs as c}from"react/jsx-runtime";import{ActivityIndicator as l,StyleSheet as u,View as d}from"react-native";import{WebView as f}from"react-native-webview";const p=e(null);function m({sdk:e,provider:t,address:n,chainId:r,children:a}){let o=i(()=>({sdk:e,provider:t,address:n,chainId:r,supportedChainIds:e.config.supportedChainIds}),[e,t,n,r]);return s(p.Provider,{value:o,children:a})}function h(){let e=n(p);if(!e)throw Error(`Yodl components must be rendered inside <YodlProvider>.`);return e}function g(e){if(e.code===4001)return!0;let t=e.message.toLowerCase();return t.includes(`rejected`)||t.includes(`denied`)}function _(e,t){if(e instanceof Error)return e;if(typeof e==`object`&&e){let t=e;if(typeof t.message==`string`){let e=Error(t.message);return typeof t.code==`number`&&(e.code=t.code),e}}return Error(t)}function v(e,t=-32603){let n=e.code;return{code:typeof n==`number`?n:t,message:e.message}}function y(e){if(typeof e!=`string`||!/^0x(?:0|[1-9a-f][0-9a-f]*)$/i.test(e))return;let t=Number.parseInt(e,16);return Number.isSafeInteger(t)?t:void 0}function b(e){let t=e.code;if(t===4200||t===-32601)return!0;let n=e.message.toLowerCase();return n.includes(`method not found`)||n.includes(`method not supported`)||n.includes(`unsupported method`)||n.includes(`unsupported wc_ method`)||n.includes(`not supported`)||n.includes(`does not exist`)||n.includes(`not available`)}function x(e){return e.match(/^(https?:\/\/[^/?#]+)/i)?.[1]??null}function S(e,t){if(!e.startsWith(t))return!1;let n=e.charAt(t.length);return n===``||n===`/`||n===`?`||n===`#`}const C=/^0x[a-fA-F0-9]{40}$/;function w(e){let t=e?.integrationAddress?.trim();if(!t)throw Error(`Yodl integrationAddress is required`);if(!C.test(t))throw Error(`Yodl integrationAddress is not a valid address: ${t}`);return t}function T(e){return{"X-Yodl-Integration-Id":w(e),"X-Yodl-SDK-Name":`@yodlpay/react-native`,"X-Yodl-SDK-Version":`0.4.0`}}function E(e,t){let n=e.yodlUiBaseUrl?x(e.yodlUiBaseUrl):null;if(!(!n||!S(t,n)))return T(e)}function D(e){return`0x${e.toString(16)}`}function O(e,t=`unsupported`){let n={};for(let r of e)n[D(r)]={atomic:{status:t}};return n}const k=[`wallet_addEthereumChain`,`wallet_switchEthereumChain`];function A(e){return k.some(t=>t===e)}function j(e,t,n){if(!A(e))return{error:{code:4200,message:`Unsupported chain method: ${e}`}};let r=y((t[0]??{}).chainId);if(typeof r!=`number`)return{error:{code:-32602,message:`Missing or invalid chainId parameter`}};if(!n.includes(r))return{error:{code:4902,message:`Chain ${r} not supported`}};let i=D(r);return{providerMethod:e,providerParams:e===`wallet_switchEthereumChain`?[{chainId:i}]:t,requestedChainId:r,chainIdHex:i,switchesActiveChain:e===`wallet_switchEthereumChain`}}function ee(e,t){let n=e[1];return Array.isArray(n)?n.map(e=>y(e)).filter(e=>typeof e==`number`&&t.includes(e)):t}function M(e){return e.status===200||e.statusCode===200||e.status===`success`||e.status===`CONFIRMED`}function N(e){return e.status===`0x0`||e.status===`reverted`||e.status===`failure`||e.status===0}function P(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e;if(!M(t))return;let n=t.receipts;if(n?.length&&!n.some(N))return n[n.length-1]?.transactionHash}function F(e){let t=D(e.chainId);return`(function() {
|
|
2
2
|
if (window.ethereum) return;
|
|
3
3
|
|
|
4
4
|
var _address = ${JSON.stringify(e.address.toLowerCase())};
|
|
@@ -225,4 +225,4 @@ import{createContext as e,useCallback as t,useContext as n,useEffect as r,useMem
|
|
|
225
225
|
announceProvider();
|
|
226
226
|
window.addEventListener("eip6963:requestProvider", announceProvider);
|
|
227
227
|
})();
|
|
228
|
-
true;`}function N(e){return e.toLowerCase()}function re(e,t){let n=N(t.address),r=e.address!==n,i=e.propChainId!==t.chainId;if(!r&&!i)return null;let a=i&&e.activeChainId!==t.chainId;return{nextAddress:n,nextPropChainId:t.chainId,nextActiveChainId:a?t.chainId:e.activeChainId,...r?{accountsChanged:[n]}:{},...a?{chainChanged:{chainId:t.chainId,chainIdHex:E(t.chainId)}}:{}}}function P(e,t,n,r){let i=r?{id:t,error:r}:{id:t,result:n};e.current?.injectJavaScript(`window.ethereum._handleResponse(${JSON.stringify(i)});true;`)}function F(e,t,n){e.current?.injectJavaScript(`window.ethereum._emitEvent(${JSON.stringify(t)},${JSON.stringify(n)});true;`)}function ie(e){let{provider:n,address:o,chainId:s,supportedChainIds:c,onTransactionSent:l,onPaymentDetails:u,onError:d,onReady:f}=e,p=a(null),m=a(N(o)),h=a(s),y=a(s),x=a(new Set),S=t(e=>{x.current.has(e)||(x.current.add(e),l?.(e))},[l]);r(()=>{let e=re({address:m.current,propChainId:h.current,activeChainId:y.current},{address:o,chainId:s});e&&(m.current=e.nextAddress,h.current=e.nextPropChainId,y.current=e.nextActiveChainId,e.accountsChanged&&F(p,`accountsChanged`,e.accountsChanged),e.chainChanged&&F(p,`chainChanged`,e.chainChanged.chainIdHex))},[o,s]);let C=i(()=>ne({address:o,chainId:s}),[o,s]),w=t(async(e,t,r)=>{try{let i=A(t,r,c);if(`error`in i){P(p,e,void 0,i.error);return}await n.request({method:i.providerMethod,params:i.providerParams}),P(p,e,null),i.switchesActiveChain&&(y.current=i.requestedChainId,F(p,`chainChanged`,i.chainIdHex))}catch(t){let n=_(t,`Chain request failed`);P(p,e,void 0,v(n)),d?.(n)}},[n,c,d]),T=t(async(e,t)=>{try{let r=t.length>0?t:[o,c.map(e=>E(e))];P(p,e,await n.request({method:`wallet_getCapabilities`,params:r}))}catch(n){let r=_(n,`Capabilities unavailable`);if(!b(r)){P(p,e,void 0,v(r));return}P(p,e,D(j(t,c),`unsupported`))}},[n,o,c]),O=t(async(e,t)=>{try{let r=await n.request({method:`wallet_getCallsStatus`,params:t}),i=te(r);i&&S(i),P(p,e,r)}catch(t){P(p,e,void 0,v(_(t,`Failed to get call status`)))}},[n,S]),M=t(async(e,t,r)=>{try{let i=await n.request({method:t,params:r});t===`eth_sendTransaction`&&typeof i==`string`&&S(i),P(p,e,i)}catch(t){let n=_(t,`Request failed`),r=g(n);P(p,e,void 0,r?{code:4001,message:n.message}:v(n)),r||d?.(n)}},[n,S,d]);return{uiRef:p,injectedJavaScript:C,onMessage:t(e=>{let t;try{t=JSON.parse(e.nativeEvent.data)}catch{return}if(t.type===`yodl_ready`){f?.();return}if(t.type===`yodl_payment_details`){u?.(t.details);return}if(t.type===`yodl_payment_error`){let e=t.error?.message??`Payment details error`,n=Error(e);t.error?.code!==void 0&&(n.code=t.error.code),d?.(n);return}if(t.type!==`ethereum_rpc_request`)return;let{id:n,method:r,params:i}=t;k(r)?w(n,r,i):r===`wallet_getCapabilities`?T(n,i):r===`wallet_getCallsStatus`?O(n,i):M(n,r,i)},[w,T,O,M,u,d,f])}}function I({uri:e,sdkConfig:n,provider:a,address:u,chainId:p,supportedChainIds:m,onTransactionSent:h,onPaymentDetails:g,onError:_,style:v,backgroundColor:y=`#18181b`,sharedCookiesEnabled:b=!0,thirdPartyCookiesEnabled:C=!0,...w}){let[E,D]=o(!1),O=t(()=>D(!0),[]),{uiRef:k,injectedJavaScript:A,onMessage:j}=ie({provider:a,address:u,chainId:p,supportedChainIds:m,onReady:O,...h!==void 0&&{onTransactionSent:h},...g!==void 0&&{onPaymentDetails:g},..._!==void 0&&{onError:_}});r(()=>{if(E)return;let e=setTimeout(O,8e3);return()=>clearTimeout(e)},[E,O]);let M=i(()=>x(e),[e]),ee=i(()=>{let t=T(n,e);return t?{uri:e,headers:t}:{uri:e}},[n,e]),te=i(()=>e=>M?S(e.url,M)||e.url.startsWith(`about:`):!1,[M]);return c(d,{style:[L.container,{backgroundColor:y},v],children:[s(f,{ref:k,source:ee,originWhitelist:M?[M]:[],onShouldStartLoadWithRequest:te,javaScriptEnabled:!0,sharedCookiesEnabled:b,thirdPartyCookiesEnabled:C,injectedJavaScriptBeforeContentLoaded:A,onMessage:j,onLoadEnd:O,style:[L.ui,{backgroundColor:y}],...w}),E?null:s(d,{style:[L.overlay,{backgroundColor:y}],children:s(l,{color:`#a1a1aa`})})]})}const L=u.create({container:{flex:1},ui:{flex:1},overlay:{...u.absoluteFillObject,alignItems:`center`,justifyContent:`center`}});function ae({onTransactionSent:e,onPaymentDetails:t,onError:n,style:r,backgroundColor:a}){let{provider:o,address:c,chainId:l,supportedChainIds:u,sdk:d}=h();return s(I,{uri:i(()=>d.config.yodlUiBaseUrl.replace(/\/$/,``),[d.config.yodlUiBaseUrl]),sdkConfig:d.config,provider:o,address:c,chainId:l,supportedChainIds:u,...e!==void 0&&{onTransactionSent:e},...t!==void 0&&{onPaymentDetails:t},...n!==void 0&&{onError:n},...r!==void 0&&{style:r},...a!==void 0&&{backgroundColor:a}})}function R(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function oe(e){if(Array.isArray(e))return e}function se(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function z(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ce(e,t,n){return t&&z(e.prototype,t),n&&z(e,n),e}function le(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function ue(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function de(e,t){return oe(e)||le(e,t)||pe(e,t)||ue()}function fe(e){"@swc/helpers - typeof";return e&&typeof Symbol<`u`&&e.constructor===Symbol?`symbol`:typeof e}function pe(e,t){if(e){if(typeof e==`string`)return R(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return R(e,t)}}var B=Object.defineProperty,me=function(e,t,n){return t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},V=function(e,t){for(var n in t)B(e,n,{get:t[n],enumerable:!0})},H=function(e,t,n){return me(e,(t===void 0?`undefined`:fe(t))===`symbol`?t:t+``,n)},he=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];function ge(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0)t=he[(o.value.charCodeAt(0)^t>>8)&255]^t<<8}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return(t^0)&65535}function U(e){for(var t=[],n=0;n<e.length;){var r=e.substring(n),i=r.substring(0,2),a=parseInt(r.substring(2,4)),o=r.substring(4,4+a);t.push({id:i,length:a,value:o}),n+=a+4}return t}function W(e){var t=``,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0){var s=o.value;if(t+=s.id,t+=(`00`+s.length).slice(-2),s.subTags){t+=W(s.subTags);continue}t+=s.value}}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return t}function G(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,n=ge(e,65535).toString(16);return n=t?n.toUpperCase():n.toLowerCase(),n=(`0000`+n).slice(-4),n}function K(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;return e+=(`00`+t).slice(-2),e+=`04`,e+=G(e,n),e}function _e(e,t,n){var r=e.find(function(e){return e.id==t});return n?r?.subTags?.find(function(e){return e.id==n}):r}function q(e,t){return{id:e,length:t.length,value:t}}function J(e){var t=e.billerId,n=e.amount,r=e.ref1,i=e.ref2,a=e.ref3,o=[q(`00`,`A000000677010112`),q(`01`,t),q(`02`,r)];i&&o.push(q(`03`,i));var s=[q(`00`,`01`),q(`01`,n?`12`:`11`),q(`30`,W(o)),q(`53`,`764`),q(`58`,`TH`)];return n&&s.push(q(`54`,Number(n).toFixed(2))),a&&s.push(q(`62`,W([q(`07`,a)]))),K(W(s),`63`)}var ve=function(){function e(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:null;se(this,e),H(this,`billerId`),H(this,`ref1`),H(this,`ref2`),H(this,`amount`),this.billerId=t,this.ref1=n,this.ref2=r,this.amount=i}return ce(e,[{key:`toString`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount,a=i?String(Number(i.toFixed(2))*100):`0`;return`|${t}\r${n}\r${r??``}\r${a}`}},{key:`toQrTag30`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return J({billerId:t,ref1:n,ref2:r??void 0,amount:i??void 0})}}],[{key:`fromString`,value:function(t){if(!t.startsWith(`|`))return null;var n=t.slice(1).split(`\r`,4);if(n.length!=4)return null;var r=de(n,4),i=r[0],a=r[1],o=r[2],s=r[3];return new e(i,a,o.length>0?o:null,s==`0`?null:Number((parseInt(s)/100).toFixed(2)))}}]),e}(),Y=function(e){return e.MSISDN=`01`,e.NATID=`02`,e.EWALLETID=`03`,e.BANKACC=`04`,e}(Y||{});function ye(e){var t=e.type,n=e.target,r=e.amount;t==`MSISDN`&&(n=(`0000000000000`+n.replace(/^0/,`66`)).slice(-13));var i=W([q(`00`,`A000000677010111`),q(Y[t],n)]),a=[q(`00`,`01`),q(`01`,r?`12`:`11`),q(`29`,i),q(`53`,`764`),q(`58`,`TH`)];return r&&a.push(q(`54`,Number(r).toFixed(2))),K(W(a),`63`)}V({},{ProxyType:function(){return Y},anyId:function(){return ye},billPayment:function(){return J},botBarcode:function(){return be},slipVerify:function(){return xe},trueMoney:function(){return Ce},trueMoneySlipVerify:function(){return we}});function be(e){var t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return new ve(t,n,r,i).toString()}function xe(e){var t=e.sendingBank,n=e.transRef;return K(W([q(`00`,W([q(`00`,`000001`),q(`01`,t),q(`02`,n)])),q(`51`,`TH`)]),`91`)}function Se(e){return e.split(``).map(function(e){return e.charCodeAt(0).toString(16).padStart(4,`0`)}).join(``).toUpperCase()}function Ce(e){var t=e.mobileNo,n=e.amount,r=e.message,i=W([q(`00`,`A000000677010111`),q(`03`,`14000${t}`)]),a=[q(`00`,`01`),q(`01`,n?`12`:`11`),q(`29`,i),q(`53`,`764`),q(`58`,`TH`)];return n&&a.push(q(`54`,Number(n).toFixed(2))),r&&a.push(q(`81`,Se(r))),K(W(a),`63`)}function we(e){var t=e.eventType,n=e.transactionId,r=e.date;return K(W([q(`00`,W([q(`00`,`01`),q(`01`,`01`),q(`02`,t),q(`03`,n),q(`04`,r)]))]),`91`,!1)}function X(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Te(e){if(Array.isArray(e))return e}function Ee(e){if(Array.isArray(e))return X(e)}function De(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function Z(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function Oe(e,t,n){return t&&Z(e.prototype,t),n&&Z(e,n),e}function ke(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ae(e){if(typeof Symbol<`u`&&e[Symbol.iterator]!=null||e[`@@iterator`]!=null)return Array.from(e)}function je(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function Me(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Ne(){throw TypeError(`Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Q(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){ke(e,t,n[t])})}return e}function Pe(e,t){return Te(e)||je(e,t)||Ie(e,t)||Me()}function Fe(e){return Ee(e)||Ae(e)||Ie(e)||Ne()}function Ie(e,t){if(e){if(typeof e==`string`)return X(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return X(e,t)}}V({},{anyId:function(){return ze},bcelOneProof:function(){return Re},billPayment:function(){return Be},slipVerify:function(){return Ve},trueMoneySlipVerify:function(){return He}});var Le=function(){function e(t,n){De(this,e),H(this,`payload`),H(this,`tags`),this.payload=t,this.tags=n}return Oe(e,[{key:`getTag`,value:function(e,t){return _e(this.tags,e,t)}},{key:`getTagValue`,value:function(e,t){return this.getTag(e,t)?.value}},{key:`getTags`,value:function(){return this.tags}},{key:`getPayload`,value:function(){return this.payload}},{key:`validate`,value:function(e){var t=K(W(Fe(this.tags).filter(function(t){return t.id!=e})),e);return this.payload===t}}]),e}();function $(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;if(!e.match(/^\d{4}.+/)||t&&e.slice(-4).toUpperCase()!=G(e.slice(0,-4)))return null;var r=U(e);if(r.length==0)return null;if(n){var i=!0,a=!1,o=void 0;try{for(var s=r[Symbol.iterator](),c;!(i=(c=s.next()).done);i=!0){var l=c.value;if(!(typeof l.value!=`string`||!l.value.match(/^\d{4}.+/))){var u=U(l.value);u.every(function(e){return e.length>0&&e.length===e.value.length})&&(l.subTags=u)}}}catch(e){a=!0,o=e}finally{try{!i&&s.return!=null&&s.return()}finally{if(a)throw o}}}return new Le(e,r)}function Re(e){var t=$(e,!0),n=t?.getTagValue(`33`,`02`),r=t?.getTagValue(`33`,`03`),i=t?.getTagValue(`33`,`04`);return t?.getTagValue(`00`)!==`01`&&t?.getTagValue(`01`)!==`11`&&t?.getTagValue(`33`,`00`)!==`BCEL`&&t?.getTagValue(`33`,`00`)!==`ONEPROOF`?null:{type:n,ticket:r,fccref:i}}function ze(e){var t=$(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`29`,`00`);if(n!==`01`||r!==`A000000677010111`)return null;var i=Object.entries(Y).find(function(e){var n=Pe(e,2)[1];return t?.getTagValue(`29`,n)!==void 0});if(!i)return null;var a=Pe(i,2),o=a[0],s=a[1],c=t.getTagValue(`29`,s);o===`MSISDN`&&c.length==13&&c.startsWith(`0066`)&&(c=`0`+c.slice(-9));var l=t?.getTagValue(`54`),u=l===void 0?void 0:parseFloat(l);return Q({type:o,target:c},u!==void 0&&{amount:u})}function Be(e){var t=$(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`30`,`00`),i=t?.getTagValue(`30`,`01`),a=t?.getTagValue(`30`,`02`);if(n!==`01`||r!==`A000000677010112`||!i||!a)return null;var o=t?.getTagValue(`30`,`03`),s=t?.getTagValue(`62`,`07`),c=t?.getTagValue(`54`),l=c===void 0?void 0:parseFloat(c);return Q({billerId:i,ref1:a},o!==void 0&&{ref2:o},s!==void 0&&{ref3:s},l!==void 0&&{amount:l})}function Ve(e){if(!(arguments.length>1&&arguments[1]!==void 0)||arguments[1]){var t=e.lastIndexOf(`9104`);if(t!=-1){var n=e.substring(t+4);n.length>0&&n.length<4&&(e=e.substring(0,t+4)+n.padStart(4,`0`))}}var r=$(e,!0),i=r?.getTagValue(`00`,`00`),a=r?.getTagValue(`00`,`01`),o=r?.getTagValue(`00`,`02`);return i!==`000001`||!a||!o?null:{sendingBank:a,transRef:o}}function He(e){var t=$(e,!0),n=t?.getTagValue(`00`,`02`),r=t?.getTagValue(`00`,`03`),i=t?.getTagValue(`00`,`04`);return t?.getTagValue(`00`,`00`)!==`01`&&t?.getTagValue(`00`,`01`)!==`01`?null:{eventType:n,transactionId:r,date:i}}const Ue={aeon:[`PH`,`VN`,`BR`,`AR`],manteca:[`AR`,`BR`],bcpilot:[],holdstation:[`VN`]};function We(e){return e?e.getTagValue(`58`)??null:null}function Ge(e){let t=[];for(let[n,r]of Object.entries(Ue))r.includes(e)&&t.push(n);return t}function Ke(e,t,n){if(!e||typeof e!=`string`||e.trim().length===0)return[];let r=e.trim(),i=[];try{let e=We($(r));if(e){let n=Ge(e);for(let e of n)(!t||t.includes(e))&&i.push({provider:e,action:`resolve`});if(i.length>0)return i}}catch{}if(n){let e=n(r);e&&(!t||t.includes(`bcpilot`))&&i.push(e)}return i}function qe(e,t){return!e||typeof e!=`string`||e.trim().length===0||!Ke(e).find(e=>e.action===`resolve`)?null:`${t.replace(/\/$/,``)}/resolve?data=${encodeURIComponent(e)}`}function Je({qrData:e,onTransactionSent:t,onPaymentDetails:n,onError:r,style:a,backgroundColor:o}){let{provider:c,address:l,chainId:u,supportedChainIds:d,sdk:f}=h(),p=i(()=>qe(e,f.config.yodlUiBaseUrl),[e,f.config.yodlUiBaseUrl]);return p?s(I,{uri:p,sdkConfig:f.config,provider:c,address:l,chainId:u,supportedChainIds:d,...t!==void 0&&{onTransactionSent:t},...n!==void 0&&{onPaymentDetails:n},...r!==void 0&&{onError:r},...a!==void 0&&{style:a},...o!==void 0&&{backgroundColor:o}}):null}function Ye(e){return(Array.isArray(e)?e:[e]).some(e=>Ke(e).some(e=>e.action===`resolve`))}var Xe=class{config;constructor(e){let t=C(e),n=e.supportedChainIds;if(!Array.isArray(n)||n.length===0)throw Error(`Yodl supportedChainIds is required — provide at least one chain id`);this.config={integrationId:t,yodlUiBaseUrl:e.yodlUiBaseUrl??`https://sdk-webview.yodl.me`,supportedChainIds:[...n]}}};function Ze(e){return new Xe(e)}export{Xe as Yodl,ae as YodlDashboard,Je as YodlPayment,m as YodlProvider,Ze as createSdk,Ye as isPaymentQr};
|
|
228
|
+
true;`}function I(e){return e.toLowerCase()}function te(e,t){let n=I(t.address),r=e.address!==n,i=e.propChainId!==t.chainId;if(!r&&!i)return null;let a=i&&e.activeChainId!==t.chainId;return{nextAddress:n,nextPropChainId:t.chainId,nextActiveChainId:a?t.chainId:e.activeChainId,...r?{accountsChanged:[n]}:{},...a?{chainChanged:{chainId:t.chainId,chainIdHex:D(t.chainId)}}:{}}}function L(e,t,n,r){let i=r?{id:t,error:r}:{id:t,result:n};e.current?.injectJavaScript(`window.ethereum._handleResponse(${JSON.stringify(i)});true;`)}function R(e,t,n){e.current?.injectJavaScript(`window.ethereum._emitEvent(${JSON.stringify(t)},${JSON.stringify(n)});true;`)}function z(e){let{provider:n,address:o,chainId:s,supportedChainIds:c,onTransactionSent:l,onPaymentDetails:u,onSignupStatusChange:d,onSignedUp:f,onSignupDismissed:p,onError:m,onReady:h}=e,y=a(null),x=a(I(o)),S=a(s),C=a(s),w=a(new Set),T=t(e=>{w.current.has(e)||(w.current.add(e),l?.(e))},[l]);r(()=>{let e=te({address:x.current,propChainId:S.current,activeChainId:C.current},{address:o,chainId:s});e&&(x.current=e.nextAddress,S.current=e.nextPropChainId,C.current=e.nextActiveChainId,e.accountsChanged&&R(y,`accountsChanged`,e.accountsChanged),e.chainChanged&&R(y,`chainChanged`,e.chainChanged.chainIdHex))},[o,s]);let E=i(()=>F({address:o,chainId:s}),[o,s]),k=t(async(e,t,r)=>{try{let i=j(t,r,c);if(`error`in i){L(y,e,void 0,i.error);return}await n.request({method:i.providerMethod,params:i.providerParams}),L(y,e,null),i.switchesActiveChain&&(C.current=i.requestedChainId,R(y,`chainChanged`,i.chainIdHex))}catch(t){let n=_(t,`Chain request failed`);L(y,e,void 0,v(n)),m?.(n)}},[n,c,m]),M=t(async(e,t)=>{try{let r=t.length>0?t:[o,c.map(e=>D(e))];L(y,e,await n.request({method:`wallet_getCapabilities`,params:r}))}catch(n){let r=_(n,`Capabilities unavailable`);if(!b(r)){L(y,e,void 0,v(r));return}L(y,e,O(ee(t,c),`unsupported`))}},[n,o,c]),N=t(async(e,t)=>{try{let r=await n.request({method:`wallet_getCallsStatus`,params:t}),i=P(r);i&&T(i),L(y,e,r)}catch(t){L(y,e,void 0,v(_(t,`Failed to get call status`)))}},[n,T]),z=t(async(e,t,r)=>{try{let i=await n.request({method:t,params:r});t===`eth_sendTransaction`&&typeof i==`string`&&T(i),L(y,e,i)}catch(t){let n=_(t,`Request failed`),r=g(n);L(y,e,void 0,r?{code:4001,message:n.message}:v(n)),r||m?.(n)}},[n,T,m]);return{uiRef:y,injectedJavaScript:E,onMessage:t(e=>{let t;try{t=JSON.parse(e.nativeEvent.data)}catch{return}if(t.type===`yodl_ready`){h?.();return}if(t.type===`yodl_payment_details`){u?.(t.details);return}if(t.type===`yodl_payment_error`){let e=t.error?.message??`Payment details error`,n=Error(e);t.error?.code!==void 0&&(n.code=t.error.code),m?.(n);return}if(t.type===`yodl_signup_status`){d?.(t.status);return}if(t.type===`yodl_signup_complete`){f?.();return}if(t.type===`yodl_signup_error`){let e=t.error?.message??`Signup error`,n=Error(e);t.error?.code!==void 0&&(n.code=t.error.code),m?.(n);return}if(t.type===`yodl_signup_dismissed`){p?.();return}if(t.type!==`ethereum_rpc_request`)return;let{id:n,method:r,params:i}=t;A(r)?k(n,r,i):r===`wallet_getCapabilities`?M(n,i):r===`wallet_getCallsStatus`?N(n,i):z(n,r,i)},[k,M,N,z,u,d,f,p,m,h])}}function B({uri:e,sdkConfig:n,provider:a,address:u,chainId:p,supportedChainIds:m,onTransactionSent:h,onPaymentDetails:g,onSignupStatusChange:_,onSignedUp:v,onSignupDismissed:y,onError:b,style:C,backgroundColor:w=`#18181b`,sharedCookiesEnabled:T=!0,thirdPartyCookiesEnabled:D=!0,...O}){let[k,A]=o(!1),j=t(()=>A(!0),[]),{uiRef:ee,injectedJavaScript:M,onMessage:N}=z({provider:a,address:u,chainId:p,supportedChainIds:m,onReady:j,...h!==void 0&&{onTransactionSent:h},...g!==void 0&&{onPaymentDetails:g},..._!==void 0&&{onSignupStatusChange:_},...v!==void 0&&{onSignedUp:v},...y!==void 0&&{onSignupDismissed:y},...b!==void 0&&{onError:b}});r(()=>{if(k)return;let e=setTimeout(j,8e3);return()=>clearTimeout(e)},[k,j]);let P=i(()=>x(e),[e]),F=i(()=>{let t=E(n,e);return t?{uri:e,headers:t}:{uri:e}},[n,e]),I=i(()=>e=>P?S(e.url,P)||e.url.startsWith(`about:`):!1,[P]);return c(d,{style:[V.container,{backgroundColor:w},C],children:[s(f,{ref:ee,source:F,originWhitelist:P?[P]:[],onShouldStartLoadWithRequest:I,javaScriptEnabled:!0,sharedCookiesEnabled:T,thirdPartyCookiesEnabled:D,injectedJavaScriptBeforeContentLoaded:M,onMessage:N,onLoadEnd:j,style:[V.ui,{backgroundColor:w}],...O}),k?null:s(d,{style:[V.overlay,{backgroundColor:w}],children:s(l,{color:`#a1a1aa`})})]})}const V=u.create({container:{flex:1},ui:{flex:1},overlay:{...u.absoluteFillObject,alignItems:`center`,justifyContent:`center`}});function ne({onTransactionSent:e,onPaymentDetails:t,onError:n,style:r,backgroundColor:a}){let{provider:o,address:c,chainId:l,supportedChainIds:u,sdk:d}=h();return s(B,{uri:i(()=>d.config.yodlUiBaseUrl.replace(/\/$/,``),[d.config.yodlUiBaseUrl]),sdkConfig:d.config,provider:o,address:c,chainId:l,supportedChainIds:u,...e!==void 0&&{onTransactionSent:e},...t!==void 0&&{onPaymentDetails:t},...n!==void 0&&{onError:n},...r!==void 0&&{style:r},...a!==void 0&&{backgroundColor:a}})}function H(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function re(e){if(Array.isArray(e))return e}function ie(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function ae(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function oe(e,t,n){return t&&ae(e.prototype,t),n&&ae(e,n),e}function se(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function ce(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function le(e,t){return re(e)||se(e,t)||de(e,t)||ce()}function ue(e){"@swc/helpers - typeof";return e&&typeof Symbol<`u`&&e.constructor===Symbol?`symbol`:typeof e}function de(e,t){if(e){if(typeof e==`string`)return H(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return H(e,t)}}var fe=Object.defineProperty,pe=function(e,t,n){return t in e?fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n},me=function(e,t){for(var n in t)fe(e,n,{get:t[n],enumerable:!0})},U=function(e,t,n){return pe(e,(t===void 0?`undefined`:ue(t))===`symbol`?t:t+``,n)},he=[0,4129,8258,12387,16516,20645,24774,28903,33032,37161,41290,45419,49548,53677,57806,61935,4657,528,12915,8786,21173,17044,29431,25302,37689,33560,45947,41818,54205,50076,62463,58334,9314,13379,1056,5121,25830,29895,17572,21637,42346,46411,34088,38153,58862,62927,50604,54669,13907,9842,5649,1584,30423,26358,22165,18100,46939,42874,38681,34616,63455,59390,55197,51132,18628,22757,26758,30887,2112,6241,10242,14371,51660,55789,59790,63919,35144,39273,43274,47403,23285,19156,31415,27286,6769,2640,14899,10770,56317,52188,64447,60318,39801,35672,47931,43802,27814,31879,19684,23749,11298,15363,3168,7233,60846,64911,52716,56781,44330,48395,36200,40265,32407,28342,24277,20212,15891,11826,7761,3696,65439,61374,57309,53244,48923,44858,40793,36728,37256,33193,45514,41451,53516,49453,61774,57711,4224,161,12482,8419,20484,16421,28742,24679,33721,37784,41979,46042,49981,54044,58239,62302,689,4752,8947,13010,16949,21012,25207,29270,46570,42443,38312,34185,62830,58703,54572,50445,13538,9411,5280,1153,29798,25671,21540,17413,42971,47098,34713,38840,59231,63358,50973,55100,9939,14066,1681,5808,26199,30326,17941,22068,55628,51565,63758,59695,39368,35305,47498,43435,22596,18533,30726,26663,6336,2273,14466,10403,52093,56156,60223,64286,35833,39896,43963,48026,19061,23124,27191,31254,2801,6864,10931,14994,64814,60687,56684,52557,48554,44427,40424,36297,31782,27655,23652,19525,15522,11395,7392,3265,61215,65342,53085,57212,44955,49082,36825,40952,28183,32310,20053,24180,11923,16050,3793,7920];function ge(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0)t=he[(o.value.charCodeAt(0)^t>>8)&255]^t<<8}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return(t^0)&65535}function W(e){for(var t=[],n=0;n<e.length;){var r=e.substring(n),i=r.substring(0,2),a=parseInt(r.substring(2,4)),o=r.substring(4,4+a);t.push({id:i,length:a,value:o}),n+=a+4}return t}function G(e){var t=``,n=!0,r=!1,i=void 0;try{for(var a=e[Symbol.iterator](),o;!(n=(o=a.next()).done);n=!0){var s=o.value;if(t+=s.id,t+=(`00`+s.length).slice(-2),s.subTags){t+=G(s.subTags);continue}t+=s.value}}catch(e){r=!0,i=e}finally{try{!n&&a.return!=null&&a.return()}finally{if(r)throw i}}return t}function K(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!0,n=ge(e,65535).toString(16);return n=t?n.toUpperCase():n.toLowerCase(),n=(`0000`+n).slice(-4),n}function q(e,t){var n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;return e+=(`00`+t).slice(-2),e+=`04`,e+=K(e,n),e}function _e(e,t,n){var r=e.find(function(e){return e.id==t});return n?r?.subTags?.find(function(e){return e.id==n}):r}function J(e,t){return{id:e,length:t.length,value:t}}function Y(e){var t=e.billerId,n=e.amount,r=e.ref1,i=e.ref2,a=e.ref3,o=[J(`00`,`A000000677010112`),J(`01`,t),J(`02`,r)];i&&o.push(J(`03`,i));var s=[J(`00`,`01`),J(`01`,n?`12`:`11`),J(`30`,G(o)),J(`53`,`764`),J(`58`,`TH`)];return n&&s.push(J(`54`,Number(n).toFixed(2))),a&&s.push(J(`62`,G([J(`07`,a)]))),q(G(s),`63`)}var ve=function(){function e(t,n){var r=arguments.length>2&&arguments[2]!==void 0?arguments[2]:null,i=arguments.length>3&&arguments[3]!==void 0?arguments[3]:null;ie(this,e),U(this,`billerId`),U(this,`ref1`),U(this,`ref2`),U(this,`amount`),this.billerId=t,this.ref1=n,this.ref2=r,this.amount=i}return oe(e,[{key:`toString`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount,a=i?String(Number(i.toFixed(2))*100):`0`;return`|${t}\r${n}\r${r??``}\r${a}`}},{key:`toQrTag30`,value:function(){var e=this,t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return Y({billerId:t,ref1:n,ref2:r??void 0,amount:i??void 0})}}],[{key:`fromString`,value:function(t){if(!t.startsWith(`|`))return null;var n=t.slice(1).split(`\r`,4);if(n.length!=4)return null;var r=le(n,4),i=r[0],a=r[1],o=r[2],s=r[3];return new e(i,a,o.length>0?o:null,s==`0`?null:Number((parseInt(s)/100).toFixed(2)))}}]),e}(),X=function(e){return e.MSISDN=`01`,e.NATID=`02`,e.EWALLETID=`03`,e.BANKACC=`04`,e}(X||{});function ye(e){var t=e.type,n=e.target,r=e.amount;t==`MSISDN`&&(n=(`0000000000000`+n.replace(/^0/,`66`)).slice(-13));var i=G([J(`00`,`A000000677010111`),J(X[t],n)]),a=[J(`00`,`01`),J(`01`,r?`12`:`11`),J(`29`,i),J(`53`,`764`),J(`58`,`TH`)];return r&&a.push(J(`54`,Number(r).toFixed(2))),q(G(a),`63`)}me({},{ProxyType:function(){return X},anyId:function(){return ye},billPayment:function(){return Y},botBarcode:function(){return be},slipVerify:function(){return xe},trueMoney:function(){return Ce},trueMoneySlipVerify:function(){return we}});function be(e){var t=e.billerId,n=e.ref1,r=e.ref2,i=e.amount;return new ve(t,n,r,i).toString()}function xe(e){var t=e.sendingBank,n=e.transRef;return q(G([J(`00`,G([J(`00`,`000001`),J(`01`,t),J(`02`,n)])),J(`51`,`TH`)]),`91`)}function Se(e){return e.split(``).map(function(e){return e.charCodeAt(0).toString(16).padStart(4,`0`)}).join(``).toUpperCase()}function Ce(e){var t=e.mobileNo,n=e.amount,r=e.message,i=G([J(`00`,`A000000677010111`),J(`03`,`14000${t}`)]),a=[J(`00`,`01`),J(`01`,n?`12`:`11`),J(`29`,i),J(`53`,`764`),J(`58`,`TH`)];return n&&a.push(J(`54`,Number(n).toFixed(2))),r&&a.push(J(`81`,Se(r))),q(G(a),`63`)}function we(e){var t=e.eventType,n=e.transactionId,r=e.date;return q(G([J(`00`,G([J(`00`,`01`),J(`01`,`01`),J(`02`,t),J(`03`,n),J(`04`,r)]))]),`91`,!1)}function Z(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Te(e){if(Array.isArray(e))return e}function Ee(e){if(Array.isArray(e))return Z(e)}function De(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function Oe(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function ke(e,t,n){return t&&Oe(e.prototype,t),n&&Oe(e,n),e}function Ae(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function je(e){if(typeof Symbol<`u`&&e[Symbol.iterator]!=null||e[`@@iterator`]!=null)return Array.from(e)}function Me(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r=[],i=!0,a=!1,o,s;try{for(n=n.call(e);!(i=(o=n.next()).done)&&(r.push(o.value),!(t&&r.length===t));i=!0);}catch(e){a=!0,s=e}finally{try{!i&&n.return!=null&&n.return()}finally{if(a)throw s}}return r}}function Ne(){throw TypeError(`Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Pe(){throw TypeError(`Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Fe(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t],r=Object.keys(n);typeof Object.getOwnPropertySymbols==`function`&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){Ae(e,t,n[t])})}return e}function Q(e,t){return Te(e)||Me(e,t)||Le(e,t)||Ne()}function Ie(e){return Ee(e)||je(e)||Le(e)||Pe()}function Le(e,t){if(e){if(typeof e==`string`)return Z(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`)return Array.from(n);if(n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Z(e,t)}}me({},{anyId:function(){return Be},bcelOneProof:function(){return ze},billPayment:function(){return Ve},slipVerify:function(){return He},trueMoneySlipVerify:function(){return Ue}});var Re=function(){function e(t,n){De(this,e),U(this,`payload`),U(this,`tags`),this.payload=t,this.tags=n}return ke(e,[{key:`getTag`,value:function(e,t){return _e(this.tags,e,t)}},{key:`getTagValue`,value:function(e,t){return this.getTag(e,t)?.value}},{key:`getTags`,value:function(){return this.tags}},{key:`getPayload`,value:function(){return this.payload}},{key:`validate`,value:function(e){var t=q(G(Ie(this.tags).filter(function(t){return t.id!=e})),e);return this.payload===t}}]),e}();function $(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;if(!e.match(/^\d{4}.+/)||t&&e.slice(-4).toUpperCase()!=K(e.slice(0,-4)))return null;var r=W(e);if(r.length==0)return null;if(n){var i=!0,a=!1,o=void 0;try{for(var s=r[Symbol.iterator](),c;!(i=(c=s.next()).done);i=!0){var l=c.value;if(!(typeof l.value!=`string`||!l.value.match(/^\d{4}.+/))){var u=W(l.value);u.every(function(e){return e.length>0&&e.length===e.value.length})&&(l.subTags=u)}}}catch(e){a=!0,o=e}finally{try{!i&&s.return!=null&&s.return()}finally{if(a)throw o}}}return new Re(e,r)}function ze(e){var t=$(e,!0),n=t?.getTagValue(`33`,`02`),r=t?.getTagValue(`33`,`03`),i=t?.getTagValue(`33`,`04`);return t?.getTagValue(`00`)!==`01`&&t?.getTagValue(`01`)!==`11`&&t?.getTagValue(`33`,`00`)!==`BCEL`&&t?.getTagValue(`33`,`00`)!==`ONEPROOF`?null:{type:n,ticket:r,fccref:i}}function Be(e){var t=$(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`29`,`00`);if(n!==`01`||r!==`A000000677010111`)return null;var i=Object.entries(X).find(function(e){var n=Q(e,2)[1];return t?.getTagValue(`29`,n)!==void 0});if(!i)return null;var a=Q(i,2),o=a[0],s=a[1],c=t.getTagValue(`29`,s);o===`MSISDN`&&c.length==13&&c.startsWith(`0066`)&&(c=`0`+c.slice(-9));var l=t?.getTagValue(`54`),u=l===void 0?void 0:parseFloat(l);return Fe({type:o,target:c},u!==void 0&&{amount:u})}function Ve(e){var t=$(e,!0),n=t?.getTagValue(`00`),r=t?.getTagValue(`30`,`00`),i=t?.getTagValue(`30`,`01`),a=t?.getTagValue(`30`,`02`);if(n!==`01`||r!==`A000000677010112`||!i||!a)return null;var o=t?.getTagValue(`30`,`03`),s=t?.getTagValue(`62`,`07`),c=t?.getTagValue(`54`),l=c===void 0?void 0:parseFloat(c);return Fe({billerId:i,ref1:a},o!==void 0&&{ref2:o},s!==void 0&&{ref3:s},l!==void 0&&{amount:l})}function He(e){if(!(arguments.length>1&&arguments[1]!==void 0)||arguments[1]){var t=e.lastIndexOf(`9104`);if(t!=-1){var n=e.substring(t+4);n.length>0&&n.length<4&&(e=e.substring(0,t+4)+n.padStart(4,`0`))}}var r=$(e,!0),i=r?.getTagValue(`00`,`00`),a=r?.getTagValue(`00`,`01`),o=r?.getTagValue(`00`,`02`);return i!==`000001`||!a||!o?null:{sendingBank:a,transRef:o}}function Ue(e){var t=$(e,!0),n=t?.getTagValue(`00`,`02`),r=t?.getTagValue(`00`,`03`),i=t?.getTagValue(`00`,`04`);return t?.getTagValue(`00`,`00`)!==`01`&&t?.getTagValue(`00`,`01`)!==`01`?null:{eventType:n,transactionId:r,date:i}}const We={aeon:[`PH`,`VN`,`BR`,`AR`],manteca:[`AR`,`BR`],bcpilot:[],holdstation:[`VN`]};function Ge(e){return e?e.getTagValue(`58`)??null:null}function Ke(e){let t=[];for(let[n,r]of Object.entries(We))r.includes(e)&&t.push(n);return t}function qe(e,t,n){if(!e||typeof e!=`string`||e.trim().length===0)return[];let r=e.trim(),i=[];try{let e=Ge($(r));if(e){let n=Ke(e);for(let e of n)(!t||t.includes(e))&&i.push({provider:e,action:`resolve`});if(i.length>0)return i}}catch{}if(n){let e=n(r);e&&(!t||t.includes(`bcpilot`))&&i.push(e)}return i}function Je(e,t){return!e||typeof e!=`string`||e.trim().length===0||!qe(e).find(e=>e.action===`resolve`)?null:`${t.replace(/\/$/,``)}/resolve?data=${encodeURIComponent(e)}`}function Ye({qrData:e,onTransactionSent:t,onPaymentDetails:n,onError:r,style:a,backgroundColor:o}){let{provider:c,address:l,chainId:u,supportedChainIds:d,sdk:f}=h(),p=i(()=>Je(e,f.config.yodlUiBaseUrl),[e,f.config.yodlUiBaseUrl]);return p?s(B,{uri:p,sdkConfig:f.config,provider:c,address:l,chainId:u,supportedChainIds:d,...t!==void 0&&{onTransactionSent:t},...n!==void 0&&{onPaymentDetails:n},...r!==void 0&&{onError:r},...a!==void 0&&{style:a},...o!==void 0&&{backgroundColor:o}}):null}function Xe(e){return`${e.replace(/\/$/,``)}/sdk/signup`}function Ze({onStatusChange:e,onSignedUp:t,onError:n,onDismiss:r,style:a,backgroundColor:o}){let{provider:c,address:l,chainId:u,supportedChainIds:d,sdk:f}=h();return s(B,{uri:i(()=>Xe(f.config.yodlUiBaseUrl),[f.config.yodlUiBaseUrl]),sdkConfig:f.config,provider:c,address:l,chainId:u,supportedChainIds:d,...e!==void 0&&{onSignupStatusChange:e},...t!==void 0&&{onSignedUp:t},...n!==void 0&&{onError:n},...r!==void 0&&{onSignupDismissed:r},...a!==void 0&&{style:a},...o!==void 0&&{backgroundColor:o}})}function Qe(e){return(Array.isArray(e)?e:[e]).some(e=>qe(e).some(e=>e.action===`resolve`))}var $e=class{config;constructor(e){let t=w(e),n=e.supportedChainIds;if(!Array.isArray(n)||n.length===0)throw Error(`Yodl supportedChainIds is required — provide at least one chain id`);this.config={integrationAddress:t,yodlUiBaseUrl:e.yodlUiBaseUrl??`https://sdk-webview.yodl.me`,supportedChainIds:[...n]}}};function et(e){return new $e(e)}export{$e as Yodl,ne as YodlDashboard,Ye as YodlPayment,m as YodlProvider,Ze as YodlSignup,et as createSdk,Qe as isPaymentQr};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yodlpay/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Yodl React Native SDK — drop-in components for EIP-1193 wallets",
|
|
6
6
|
"keywords": [
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"tsdown": "^0.22.0",
|
|
76
76
|
"typescript": "^5.7.2",
|
|
77
77
|
"vitest": "^4.1.7",
|
|
78
|
-
"@yodlpay/sdk-core": "0.
|
|
78
|
+
"@yodlpay/sdk-core": "0.4.0"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "tsdown",
|