@mezo-org/passport 0.4.0-dev.5 → 0.4.0-dev.51
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 +18 -22
- package/dist/src/api/auth.d.ts +36 -59
- package/dist/src/api/auth.d.ts.map +1 -1
- package/dist/src/api/auth.js +22 -48
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +27 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +61 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/endpoint-error.d.ts +4 -0
- package/dist/src/api/endpoint-error.d.ts.map +1 -0
- package/dist/src/api/endpoint-error.js +6 -0
- package/dist/src/api/endpoint-error.js.map +1 -0
- package/dist/src/api/fetch-error copy.d.ts +5 -0
- package/dist/src/api/fetch-error copy.d.ts.map +1 -0
- package/dist/src/api/fetch-error copy.js +8 -0
- package/dist/src/api/fetch-error copy.js.map +1 -0
- package/dist/src/api/fetch-error.d.ts +5 -0
- package/dist/src/api/fetch-error.d.ts.map +1 -0
- package/dist/src/api/fetch-error.js +8 -0
- package/dist/src/api/fetch-error.js.map +1 -0
- package/dist/src/api/index.d.ts +3 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +3 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/portal.d.ts +26 -0
- package/dist/src/api/portal.d.ts.map +1 -0
- package/dist/src/api/portal.js +26 -0
- package/dist/src/api/portal.js.map +1 -0
- package/dist/src/assets/DefaultAvatar.d.ts +5 -0
- package/dist/src/assets/DefaultAvatar.d.ts.map +1 -0
- package/dist/src/assets/DefaultAvatar.js +21 -0
- package/dist/src/assets/DefaultAvatar.js.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts +8 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js +39 -0
- package/dist/src/components/Dropdown/ConnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Content.d.ts +23 -0
- package/dist/src/components/Dropdown/Content.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Content.js +27 -0
- package/dist/src/components/Dropdown/Content.js.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts +7 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.d.ts.map +1 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js +13 -0
- package/dist/src/components/Dropdown/DisconnectedTrigger.js.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts +27 -0
- package/dist/src/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Dropdown.js +68 -0
- package/dist/src/components/Dropdown/Dropdown.js.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts +13 -0
- package/dist/src/components/Dropdown/ListingItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/ListingItem.js +34 -0
- package/dist/src/components/Dropdown/ListingItem.js.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts +7 -0
- package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js +34 -0
- package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts +7 -0
- package/dist/src/components/Dropdown/Receive/Receive.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Receive/Receive.js +53 -0
- package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts +7 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts +11 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js +9 -0
- package/dist/src/components/Dropdown/Root/AccountAssetItem.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js +15 -0
- package/dist/src/components/Dropdown/Root/AccountBalance.js.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts +9 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js +48 -0
- package/dist/src/components/Dropdown/Root/AccountOtherAssets.js.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts +23 -0
- package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/Root.js +57 -0
- package/dist/src/components/Dropdown/Root/Root.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js +64 -0
- package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts +8 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.d.ts.map +1 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js +44 -0
- package/dist/src/components/Dropdown/Root/WelcomeBlock.js.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts +3 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.d.ts.map +1 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js +14 -0
- package/dist/src/components/Dropdown/TestnetTopBanner.js.map +1 -0
- package/dist/src/components/Dropdown/index.d.ts +3 -0
- package/dist/src/components/Dropdown/index.d.ts.map +1 -0
- package/dist/src/components/Dropdown/index.js +2 -0
- package/dist/src/components/Dropdown/index.js.map +1 -0
- package/dist/src/components/index.d.ts +2 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +2 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/config.d.ts +17 -5
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +51 -14
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +11 -3
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +12 -4
- package/dist/src/constants.js.map +1 -1
- package/dist/src/hooks/constants.d.ts +1 -0
- package/dist/src/hooks/constants.d.ts.map +1 -1
- package/dist/src/hooks/constants.js +1 -0
- package/dist/src/hooks/constants.js.map +1 -1
- package/dist/src/hooks/index.d.ts +3 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +3 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +23 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +89 -0
- package/dist/src/hooks/useAssetsConversionRates.js.map +1 -0
- package/dist/src/hooks/useAuthApiClient.d.ts +1 -1
- package/dist/src/hooks/useAuthApiClient.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts +12 -102
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useAuthenticateWithWallet.js +28 -17
- package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
- package/dist/src/hooks/useBitcoinPriceConversion copy.d.ts +2 -0
- package/dist/src/hooks/useBitcoinPriceConversion copy.d.ts.map +1 -0
- package/dist/src/hooks/useBitcoinPriceConversion copy.js +43 -0
- package/dist/src/hooks/useBitcoinPriceConversion copy.js.map +1 -0
- package/dist/src/hooks/useBitcoinPriceConversion.d.ts +103 -0
- package/dist/src/hooks/useBitcoinPriceConversion.d.ts.map +1 -0
- package/dist/src/hooks/useBitcoinPriceConversion.js +50 -0
- package/dist/src/hooks/useBitcoinPriceConversion.js.map +1 -0
- package/dist/src/hooks/useBitcoinPriceFeed.d.ts +15 -0
- package/dist/src/hooks/useBitcoinPriceFeed.d.ts.map +1 -0
- package/dist/src/hooks/useBitcoinPriceFeed.js +67 -0
- package/dist/src/hooks/useBitcoinPriceFeed.js.map +1 -0
- package/dist/src/hooks/useBorrowData.d.ts +60 -0
- package/dist/src/hooks/useBorrowData.d.ts.map +1 -0
- package/dist/src/hooks/useBorrowData.js +122 -0
- package/dist/src/hooks/useBorrowData.js.map +1 -0
- package/dist/src/hooks/useCreateAccount.d.ts +23 -173
- package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
- package/dist/src/hooks/useCreateAccount.js +7 -4
- package/dist/src/hooks/useCreateAccount.js.map +1 -1
- package/dist/src/hooks/useCreateSession.d.ts +12 -101
- package/dist/src/hooks/useCreateSession.d.ts.map +1 -1
- package/dist/src/hooks/useCreateSession.js +10 -8
- package/dist/src/hooks/useCreateSession.js.map +1 -1
- package/dist/src/hooks/useDropdownData.d.ts +47 -0
- package/dist/src/hooks/useDropdownData.d.ts.map +1 -0
- package/dist/src/hooks/useDropdownData.js +99 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useGetAccountByAddress.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByAddress.d.ts.map +1 -1
- package/dist/src/hooks/useGetAccountByMezoId.d.ts +2 -2
- package/dist/src/hooks/useGetAccountByMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.d.ts +16 -2
- package/dist/src/hooks/useGetCurrentAccount.d.ts.map +1 -1
- package/dist/src/hooks/useGetCurrentAccount.js +25 -3
- package/dist/src/hooks/useGetCurrentAccount.js.map +1 -1
- package/dist/src/hooks/useGetSession.d.ts +1 -1
- package/dist/src/hooks/useGetSession.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.d.ts +15 -175
- package/dist/src/hooks/useLinkAccount.d.ts.map +1 -1
- package/dist/src/hooks/useLinkAccount.js +7 -4
- package/dist/src/hooks/useLinkAccount.js.map +1 -1
- package/dist/src/hooks/usePortalApiClient.d.ts +2 -0
- package/dist/src/hooks/usePortalApiClient.d.ts.map +1 -0
- package/dist/src/hooks/usePortalApiClient.js +6 -0
- package/dist/src/hooks/usePortalApiClient.js.map +1 -0
- package/dist/src/hooks/useRefreshPassport.d.ts +19 -0
- package/dist/src/hooks/useRefreshPassport.d.ts.map +1 -0
- package/dist/src/hooks/useRefreshPassport.js +44 -0
- package/dist/src/hooks/useRefreshPassport.js.map +1 -0
- package/dist/src/hooks/useSignInWithDiscord.d.ts +12 -100
- package/dist/src/hooks/useSignInWithDiscord.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithDiscord.js +6 -3
- package/dist/src/hooks/useSignInWithDiscord.js.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignInWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignInWithWallet.js +2 -2
- package/dist/src/hooks/useSignInWithWallet.js.map +1 -1
- package/dist/src/hooks/useSignOut.d.ts +12 -28
- package/dist/src/hooks/useSignOut.d.ts.map +1 -1
- package/dist/src/hooks/useSignOut.js +7 -4
- package/dist/src/hooks/useSignOut.js.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.d.ts +12 -100
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -1
- package/dist/src/hooks/useSignUpWithWallet.js +2 -2
- package/dist/src/hooks/useSignUpWithWallet.js.map +1 -1
- package/dist/src/hooks/useTokensBalances.d.ts +74 -0
- package/dist/src/hooks/useTokensBalances.d.ts.map +1 -0
- package/dist/src/hooks/useTokensBalances.js +140 -0
- package/dist/src/hooks/useTokensBalances.js.map +1 -0
- package/dist/src/hooks/useUpdateMezoId.d.ts +30 -136
- package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
- package/dist/src/hooks/useUpdateMezoId.js +7 -4
- package/dist/src/hooks/useUpdateMezoId.js.map +1 -1
- package/dist/src/hooks/useWalletAccount.d.ts +13 -0
- package/dist/src/hooks/useWalletAccount.d.ts.map +1 -0
- package/dist/src/hooks/useWalletAccount.js +29 -0
- package/dist/src/hooks/useWalletAccount.js.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts +5 -0
- package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -0
- package/dist/src/hooks/useWatchTransferEvents.js +63 -0
- package/dist/src/hooks/useWatchTransferEvents.js.map +1 -0
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/contracts/index.d.ts +13 -0
- package/dist/src/lib/contracts/index.d.ts.map +1 -0
- package/dist/src/lib/contracts/index.js +58 -0
- package/dist/src/lib/contracts/index.js.map +1 -0
- package/dist/src/lib/contracts/price-oracle.d.ts +43 -0
- package/dist/src/lib/contracts/price-oracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/price-oracle.js +52 -0
- package/dist/src/lib/contracts/price-oracle.js.map +1 -0
- package/dist/src/lib/contracts/priceOracle.d.ts +43 -0
- package/dist/src/lib/contracts/priceOracle.d.ts.map +1 -0
- package/dist/src/lib/contracts/priceOracle.js +52 -0
- package/dist/src/lib/contracts/priceOracle.js.map +1 -0
- package/dist/src/provider.d.ts +10 -13
- package/dist/src/provider.d.ts.map +1 -1
- package/dist/src/provider.js +11 -20
- package/dist/src/provider.js.map +1 -1
- package/dist/src/stores/dropdownStore.d.ts +12 -0
- package/dist/src/stores/dropdownStore.d.ts.map +1 -0
- package/dist/src/stores/dropdownStore.js +13 -0
- package/dist/src/stores/dropdownStore.js.map +1 -0
- package/dist/src/utils/address.d.ts +15 -0
- package/dist/src/utils/address.d.ts.map +1 -0
- package/dist/src/utils/address.js +37 -0
- package/dist/src/utils/address.js.map +1 -0
- package/dist/src/utils/address.test.d.ts +2 -0
- package/dist/src/utils/address.test.d.ts.map +1 -0
- package/dist/src/utils/address.test.js +40 -0
- package/dist/src/utils/address.test.js.map +1 -0
- package/dist/src/utils/cryptoAssets.d.ts +44 -0
- package/dist/src/utils/cryptoAssets.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.js +132 -0
- package/dist/src/utils/cryptoAssets.js.map +1 -0
- package/dist/src/utils/cryptoAssets.test.d.ts +2 -0
- package/dist/src/utils/cryptoAssets.test.d.ts.map +1 -0
- package/dist/src/utils/cryptoAssets.test.js +67 -0
- package/dist/src/utils/cryptoAssets.test.js.map +1 -0
- package/dist/src/utils/currency.d.ts +14 -0
- package/dist/src/utils/currency.d.ts.map +1 -0
- package/dist/src/utils/currency.js +27 -0
- package/dist/src/utils/currency.js.map +1 -0
- package/dist/src/utils/currency.test.d.ts +2 -0
- package/dist/src/utils/currency.test.d.ts.map +1 -0
- package/dist/src/utils/currency.test.js +34 -0
- package/dist/src/utils/currency.test.js.map +1 -0
- package/dist/src/utils/numbers.d.ts +58 -0
- package/dist/src/utils/numbers.d.ts.map +1 -0
- package/dist/src/utils/numbers.js +132 -0
- package/dist/src/utils/numbers.js.map +1 -0
- package/dist/src/utils/numbers.test.d.ts +2 -0
- package/dist/src/utils/numbers.test.d.ts.map +1 -0
- package/dist/src/utils/numbers.test.js +170 -0
- package/dist/src/utils/numbers.test.js.map +1 -0
- package/package.json +14 -8
- package/src/api/auth.ts +73 -128
- package/src/api/client.ts +87 -0
- package/src/api/fetch-error.ts +8 -0
- package/src/api/index.ts +2 -0
- package/src/api/portal.ts +53 -0
- package/src/assets/DefaultAvatar.tsx +74 -0
- package/src/components/Dropdown/ConnectedTrigger.tsx +76 -0
- package/src/components/Dropdown/Content.tsx +98 -0
- package/src/components/Dropdown/DisconnectedTrigger.tsx +36 -0
- package/src/components/Dropdown/Dropdown.tsx +148 -0
- package/src/components/Dropdown/ListingItem.tsx +80 -0
- package/src/components/Dropdown/NestedViewLayout.tsx +75 -0
- package/src/components/Dropdown/README.md +41 -0
- package/src/components/Dropdown/Receive/Receive.tsx +119 -0
- package/src/components/Dropdown/Root/AccountAddressActions.tsx +101 -0
- package/src/components/Dropdown/Root/AccountAssetItem.tsx +26 -0
- package/src/components/Dropdown/Root/AccountBalance.tsx +30 -0
- package/src/components/Dropdown/Root/AccountOtherAssets.tsx +68 -0
- package/src/components/Dropdown/Root/Root.tsx +147 -0
- package/src/components/Dropdown/Root/WalletAddress.tsx +128 -0
- package/src/components/Dropdown/Root/WelcomeBlock.tsx +91 -0
- package/src/components/Dropdown/TestnetTopBanner.tsx +32 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/index.ts +1 -0
- package/src/config.ts +77 -20
- package/src/constants.ts +12 -4
- package/src/hooks/constants.ts +1 -0
- package/src/hooks/index.ts +6 -1
- package/src/hooks/useAssetsConversionRates.ts +96 -0
- package/src/hooks/useAuthenticateWithWallet.ts +44 -23
- package/src/hooks/useBorrowData.ts +143 -0
- package/src/hooks/useCreateAccount.ts +19 -5
- package/src/hooks/useCreateSession.ts +22 -9
- package/src/hooks/useDropdownData.ts +149 -0
- package/src/hooks/useGetAccountByAddress.ts +2 -2
- package/src/hooks/useGetAccountByMezoId.ts +2 -2
- package/src/hooks/useGetCurrentAccount.ts +46 -6
- package/src/hooks/useGetSession.ts +1 -1
- package/src/hooks/useLinkAccount.ts +18 -5
- package/src/hooks/usePortalApiClient.ts +6 -0
- package/src/hooks/useRefreshPassport.ts +56 -0
- package/src/hooks/useSignInWithDiscord.ts +14 -5
- package/src/hooks/useSignInWithWallet.ts +9 -2
- package/src/hooks/useSignOut.ts +18 -4
- package/src/hooks/useSignUpWithWallet.ts +9 -2
- package/src/hooks/useTokensBalances.ts +187 -0
- package/src/hooks/useUpdateMezoId.ts +19 -4
- package/src/hooks/useWalletAccount.ts +55 -0
- package/src/hooks/useWatchTransferEvents.ts +74 -0
- package/src/index.ts +12 -1
- package/src/lib/contracts/index.ts +90 -0
- package/src/lib/contracts/priceOracle.ts +53 -0
- package/src/provider.ts +30 -37
- package/src/stores/dropdownStore.ts +20 -0
- package/src/utils/address.test.ts +48 -0
- package/src/utils/address.ts +45 -0
- package/src/utils/cryptoAssets.test.ts +79 -0
- package/src/utils/cryptoAssets.ts +173 -0
- package/src/utils/currency.test.ts +38 -0
- package/src/utils/currency.ts +32 -0
- package/src/utils/numbers.test.ts +220 -0
- package/src/utils/numbers.ts +188 -0
package/README.md
CHANGED
|
@@ -96,12 +96,12 @@ Mezo Passport provides a `getConfig` method, which returns a default
|
|
|
96
96
|
configuration for Mezo Matsnet. We just have to pass it further to
|
|
97
97
|
`WagmiProvider`:
|
|
98
98
|
|
|
99
|
-
```
|
|
99
|
+
```tsx
|
|
100
100
|
import { RainbowKitProvider } from "@rainbow-me/rainbowkit"
|
|
101
101
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
|
|
102
102
|
import { WagmiProvider } from "wagmi"
|
|
103
103
|
import "@rainbow-me/rainbowkit/styles.css"
|
|
104
|
-
import { getConfig,
|
|
104
|
+
import { getConfig, mezoTestnet } from "@mezo-org/passport"
|
|
105
105
|
|
|
106
106
|
const queryClient = new QueryClient()
|
|
107
107
|
|
|
@@ -109,7 +109,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render(
|
|
|
109
109
|
<React.StrictMode>
|
|
110
110
|
<WagmiProvider config={getConfig({ appName: "Your app name" })}>
|
|
111
111
|
<QueryClientProvider client={queryClient}>
|
|
112
|
-
<RainbowKitProvider initialChain={
|
|
112
|
+
<RainbowKitProvider initialChain={mezoTestnet}>
|
|
113
113
|
{/* Your App component */}
|
|
114
114
|
</RainbowKitProvider>
|
|
115
115
|
</QueryClientProvider>
|
|
@@ -127,7 +127,7 @@ support. By default, the lib supports Unisat, OKX and Xverse wallets. If you
|
|
|
127
127
|
want to include Unisat wallet only, you can pass it through `bitcoinWallet`
|
|
128
128
|
property to `getConfig` function:
|
|
129
129
|
|
|
130
|
-
```
|
|
130
|
+
```tsx
|
|
131
131
|
import { getConfig, unisatWallet } from "@mezo-org/passport"
|
|
132
132
|
|
|
133
133
|
const customBitcoinWallets = [
|
|
@@ -169,11 +169,8 @@ There are two ways to connect the Mezo Passport wallet:
|
|
|
169
169
|
|
|
170
170
|
We can connect to the specific wallet directly through `wagmi`:
|
|
171
171
|
|
|
172
|
-
```
|
|
173
|
-
import {
|
|
174
|
-
useChainId,
|
|
175
|
-
useConnect,
|
|
176
|
-
} from "wagmi"
|
|
172
|
+
```tsx
|
|
173
|
+
import { useChainId, useConnect } from "wagmi"
|
|
177
174
|
|
|
178
175
|
export const YourApp = () => {
|
|
179
176
|
const chainId = useChainId()
|
|
@@ -194,8 +191,7 @@ export const YourApp = () => {
|
|
|
194
191
|
))}
|
|
195
192
|
</div>
|
|
196
193
|
)
|
|
197
|
-
|
|
198
|
-
};
|
|
194
|
+
}
|
|
199
195
|
```
|
|
200
196
|
|
|
201
197
|
This will render a button for each wallet that we've added to the rainbowKit
|
|
@@ -208,12 +204,12 @@ We can also implement wallet connection through RainbowKit, where we import the
|
|
|
208
204
|
`ConnectButton` component, which will handle the connection process under the
|
|
209
205
|
hood:
|
|
210
206
|
|
|
211
|
-
```
|
|
207
|
+
```tsx
|
|
212
208
|
import { ConnectButton } from "@rainbow-me/rainbowkit"
|
|
213
209
|
|
|
214
210
|
export const YourApp = () => {
|
|
215
|
-
return <ConnectButton label="Connect wallet"
|
|
216
|
-
}
|
|
211
|
+
return <ConnectButton label="Connect wallet" />
|
|
212
|
+
}
|
|
217
213
|
```
|
|
218
214
|
|
|
219
215
|
### Getting addresses and wallet balances
|
|
@@ -224,7 +220,7 @@ For bitcoin account Mezo Passport exports a helper hook -
|
|
|
224
220
|
`useBitcoinAccount()` - which can be used to obtain address and balance of the
|
|
225
221
|
connected bitcoin account:
|
|
226
222
|
|
|
227
|
-
```
|
|
223
|
+
```ts
|
|
228
224
|
import { useBitcoinAccount } from "@mezo-org/passport"
|
|
229
225
|
|
|
230
226
|
const { btcAddress, btcBalance } = useBitcoinAccount()
|
|
@@ -237,7 +233,7 @@ useEffect(() => {
|
|
|
237
233
|
|
|
238
234
|
This hook returns the bitcoin balance in satoshis, in the following format:
|
|
239
235
|
|
|
240
|
-
```
|
|
236
|
+
```ts
|
|
241
237
|
{
|
|
242
238
|
confirmed: number,
|
|
243
239
|
unconfirmed: number,
|
|
@@ -250,7 +246,7 @@ This hook returns the bitcoin balance in satoshis, in the following format:
|
|
|
250
246
|
To get an address and a balance of the underlying Mezo Matsnet account, we can
|
|
251
247
|
use `wagmi` hooks:
|
|
252
248
|
|
|
253
|
-
```
|
|
249
|
+
```ts
|
|
254
250
|
const { address } = useAccount()
|
|
255
251
|
const { data } = useBalance({ address })
|
|
256
252
|
|
|
@@ -265,14 +261,14 @@ useEffect(() => {
|
|
|
265
261
|
The Mezo Passport wallets supports message signing from `wagmi` lib, so signing
|
|
266
262
|
functions the same way as it does in `wagmi`:
|
|
267
263
|
|
|
268
|
-
```
|
|
269
|
-
import { useSignMessage } from
|
|
264
|
+
```tsx
|
|
265
|
+
import { useSignMessage } from "wagmi"
|
|
270
266
|
|
|
271
267
|
function App() {
|
|
272
268
|
const { signMessage } = useSignMessage()
|
|
273
269
|
|
|
274
270
|
return (
|
|
275
|
-
<button onClick={() => signMessage({ message:
|
|
271
|
+
<button onClick={() => signMessage({ message: "hello world" })}>
|
|
276
272
|
Sign message
|
|
277
273
|
</button>
|
|
278
274
|
)
|
|
@@ -286,7 +282,7 @@ Contracts integrations are handled the same way as in RainbowKit and Wagmi.
|
|
|
286
282
|
To send a specific Mezo Matsnet transaction from the underlying Mezo Matsnet
|
|
287
283
|
account, we can use a `useSendTransaction` hook from `@mezo-org/passport`:
|
|
288
284
|
|
|
289
|
-
```
|
|
285
|
+
```ts
|
|
290
286
|
import { useSendTransaction } from "@mezo-org/passport"
|
|
291
287
|
|
|
292
288
|
const { sendTransaction } = useSendTransaction()
|
|
@@ -314,7 +310,7 @@ With `@mezo-org/passport` it's also possible to send BTC transactions from your
|
|
|
314
310
|
original Bitcoin account (not the underlying Mezo Matsnet account). For that, we
|
|
315
311
|
can use `useSendBitcoin` hook:
|
|
316
312
|
|
|
317
|
-
```
|
|
313
|
+
```ts
|
|
318
314
|
import { useSendBitcoin } from "@mezo-org/passport"
|
|
319
315
|
|
|
320
316
|
const { sendBitcoin } = useSendBitcoin()
|
package/dist/src/api/auth.d.ts
CHANGED
|
@@ -1,101 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
body?: Record<string, unknown>;
|
|
3
|
-
queryParams?: Record<string, string | undefined>;
|
|
4
|
-
};
|
|
5
|
-
type PassportIdentityProvider = "wallet" | "discord" | "email";
|
|
6
|
-
type AccountPublicData = {
|
|
7
|
-
mezoId?: string;
|
|
8
|
-
btcAddress: string;
|
|
9
|
-
evmAddress: string;
|
|
10
|
-
};
|
|
11
|
-
type AuthUser = {
|
|
12
|
-
id: string;
|
|
13
|
-
app_metadata: {
|
|
14
|
-
provider: PassportIdentityProvider;
|
|
15
|
-
providers: PassportIdentityProvider[];
|
|
16
|
-
};
|
|
17
|
-
user_metadata: AccountPublicData;
|
|
18
|
-
};
|
|
1
|
+
import { ApiClient } from "./client";
|
|
19
2
|
type AuthProvider = "discord";
|
|
20
|
-
export type
|
|
3
|
+
export type LinkedWalletAccount = {
|
|
21
4
|
type: "wallet";
|
|
22
5
|
btcAddress?: string;
|
|
23
6
|
evmAddress: string;
|
|
24
|
-
}
|
|
7
|
+
};
|
|
8
|
+
export type LinkedProviderAccount = {
|
|
25
9
|
type: AuthProvider;
|
|
26
10
|
name: string;
|
|
27
11
|
id: string;
|
|
28
12
|
avatarUrl: string;
|
|
29
13
|
};
|
|
14
|
+
export type LinkedAccount = LinkedWalletAccount | LinkedProviderAccount;
|
|
30
15
|
type Account = {
|
|
31
16
|
mezoId: string;
|
|
32
17
|
hasModifiedMezoId: boolean;
|
|
33
18
|
linkedAccounts: LinkedAccount[];
|
|
34
|
-
authUser: AuthUser;
|
|
35
19
|
};
|
|
36
|
-
type Session = {
|
|
20
|
+
export type Session = {
|
|
37
21
|
expiresIn: number;
|
|
38
22
|
expiresAt: number;
|
|
39
23
|
sessionLinks: {
|
|
40
24
|
_links: {
|
|
41
|
-
account:
|
|
25
|
+
account: string;
|
|
42
26
|
};
|
|
43
27
|
};
|
|
44
28
|
};
|
|
45
|
-
type AuthenticationProviderRedirectResponse = {
|
|
29
|
+
export type AuthenticationProviderRedirectResponse = {
|
|
46
30
|
redirectTo: string;
|
|
47
31
|
};
|
|
48
|
-
type
|
|
49
|
-
type: "wallet";
|
|
32
|
+
type SignatureData = {
|
|
50
33
|
message: string;
|
|
51
34
|
signature: string;
|
|
52
35
|
};
|
|
53
|
-
export type CreateSessionRequest = WalletAccountCredentials | {
|
|
54
|
-
type: "discord";
|
|
55
|
-
};
|
|
56
|
-
export type LinkAccountRequest = CreateSessionRequest;
|
|
57
|
-
export type CreateAccountRequest = WalletAccountCredentials;
|
|
58
36
|
export type GetSessionResponse = Session | {
|
|
59
37
|
nonce: string;
|
|
60
38
|
};
|
|
39
|
+
export type CreateSessionRequest = ({
|
|
40
|
+
type: "wallet";
|
|
41
|
+
} & SignatureData) | {
|
|
42
|
+
type: "discord";
|
|
43
|
+
};
|
|
44
|
+
export type CreateSessionResponse = Session | AuthenticationProviderRedirectResponse;
|
|
45
|
+
export type DeleteSessionResponse = {
|
|
46
|
+
message: string;
|
|
47
|
+
};
|
|
61
48
|
export type GetCurrentAccountResponse = Partial<Account> | null;
|
|
62
49
|
export type GetAccountByMezoIdOrAddressResponse = {
|
|
63
50
|
mezoId?: string;
|
|
64
|
-
linkedAccounts?: LinkedAccount
|
|
51
|
+
linkedAccounts?: Extract<LinkedAccount, {
|
|
52
|
+
type: "wallet";
|
|
53
|
+
}>[];
|
|
65
54
|
};
|
|
66
|
-
export
|
|
55
|
+
export type LinkAccountRequest = CreateSessionRequest;
|
|
56
|
+
export type LinkAccountResponse = Account | AuthenticationProviderRedirectResponse;
|
|
57
|
+
export type CreateAccountRequest = {
|
|
58
|
+
type: "wallet";
|
|
59
|
+
} & SignatureData;
|
|
60
|
+
export type CreateAccountResponse = Account;
|
|
61
|
+
export type UpdateMezoIdResponse = Account;
|
|
62
|
+
export declare const AUTH_API_ENDPOINTS_BY_ENV: {
|
|
67
63
|
mainnet: string;
|
|
68
64
|
testnet: string;
|
|
69
65
|
};
|
|
70
|
-
export declare class AuthApiClient {
|
|
71
|
-
|
|
72
|
-
constructor(apiUrl?: string);
|
|
73
|
-
/**
|
|
74
|
-
* The request handler for the Passport API. It accepts an API endpoint and
|
|
75
|
-
* request options.
|
|
76
|
-
* @dev Generic type `D` is a type of returned object from the function
|
|
77
|
-
* @dev WARNING: This function hardcodes `credentials: "include"`, meaning
|
|
78
|
-
* cookies and authentication headers will be sent with every request. Ensure
|
|
79
|
-
* this is safe if you plan to use it in other contexts than auth api worker.
|
|
80
|
-
* @param endpoint - The API endpoint to request. Should start with
|
|
81
|
-
* forward slash ("/")
|
|
82
|
-
* @param options - The request options, the `RequestInit` type with
|
|
83
|
-
* additional type-safe properties
|
|
84
|
-
* @returns The promise of the API response
|
|
85
|
-
*/
|
|
86
|
-
protected handleRequest<D>(endpoint: `/${string}`, options: RequestHandlerOptions): Promise<D>;
|
|
66
|
+
export declare class AuthApiClient extends ApiClient {
|
|
67
|
+
constructor(environment?: keyof typeof AUTH_API_ENDPOINTS_BY_ENV, apiUrl?: string);
|
|
87
68
|
getSession(code?: string): Promise<GetSessionResponse>;
|
|
88
|
-
createSession(createSessionRequest: CreateSessionRequest): Promise<
|
|
89
|
-
|
|
90
|
-
}>;
|
|
91
|
-
deleteSession(): Promise<{
|
|
92
|
-
message: string;
|
|
93
|
-
}>;
|
|
69
|
+
createSession(createSessionRequest: CreateSessionRequest): Promise<CreateSessionResponse>;
|
|
70
|
+
deleteSession(): Promise<DeleteSessionResponse>;
|
|
94
71
|
getCurrentAccount(): Promise<GetCurrentAccountResponse>;
|
|
95
|
-
getAccountByMezoIdOrAddress(mezoIdOrAddress: string): Promise<GetAccountByMezoIdOrAddressResponse>;
|
|
96
|
-
linkAccount(linkAccountRequest: LinkAccountRequest): Promise<
|
|
72
|
+
getAccountByMezoIdOrAddress(mezoIdOrAddress: string): Promise<GetAccountByMezoIdOrAddressResponse | null>;
|
|
73
|
+
linkAccount(linkAccountRequest: LinkAccountRequest): Promise<LinkAccountResponse>;
|
|
97
74
|
createAccount(createAccountRequest: CreateAccountRequest): Promise<Account>;
|
|
98
|
-
updateMezoId(newMezoId: string): Promise<
|
|
75
|
+
updateMezoId(newMezoId: string): Promise<Account>;
|
|
99
76
|
}
|
|
100
77
|
export {};
|
|
101
78
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/api/auth.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/api/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGpC,KAAK,YAAY,GAAG,SAAS,CAAA;AAE7B,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,QAAQ,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,YAAY,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,qBAAqB,CAAA;AAEvE,KAAK,OAAO,GAAG;IACb,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,OAAO,CAAA;IAC1B,cAAc,EAAE,aAAa,EAAE,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EA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AA;AAED,qBAAa,aAAc,SAAQ,SAAS;gBAExC,WAAW,GAAE,MAAM,OAAO,yBAAqC,EAC/D,MAAM,CAAC,EAAE,MAAM;IAOX,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM;IASxB,aAAa,CAAC,oBAAoB,EAAE,oBAAoB;IASxD,aAAa;IAQb,iBAAiB;IAWjB,2BAA2B,CAAC,eAAe,EAAE,MAAM;IAqBnD,WAAW,CAAC,kBAAkB,EAAE,kBAAkB;IAYlD,aAAa,CAAC,oBAAoB,EAAE,oBAAoB;IASxD,YAAY,CAAC,SAAS,EAAE,MAAM;CAWrC"}
|
package/dist/src/api/auth.js
CHANGED
|
@@ -1,52 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import { ApiClient } from "./client";
|
|
2
|
+
import { FetchError } from "./fetch-error";
|
|
3
|
+
export const AUTH_API_ENDPOINTS_BY_ENV = {
|
|
2
4
|
mainnet: "https://api.mezo.org",
|
|
3
5
|
testnet: "https://api.test.mezo.org",
|
|
4
6
|
};
|
|
5
|
-
export class AuthApiClient {
|
|
6
|
-
apiUrl
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* The request handler for the Passport API. It accepts an API endpoint and
|
|
12
|
-
* request options.
|
|
13
|
-
* @dev Generic type `D` is a type of returned object from the function
|
|
14
|
-
* @dev WARNING: This function hardcodes `credentials: "include"`, meaning
|
|
15
|
-
* cookies and authentication headers will be sent with every request. Ensure
|
|
16
|
-
* this is safe if you plan to use it in other contexts than auth api worker.
|
|
17
|
-
* @param endpoint - The API endpoint to request. Should start with
|
|
18
|
-
* forward slash ("/")
|
|
19
|
-
* @param options - The request options, the `RequestInit` type with
|
|
20
|
-
* additional type-safe properties
|
|
21
|
-
* @returns The promise of the API response
|
|
22
|
-
*/
|
|
23
|
-
async handleRequest(endpoint, options) {
|
|
24
|
-
const { method, headers, body, queryParams = {}, ...restOptions } = options || {};
|
|
25
|
-
// If last character in apiUrl is forward slash we are removing it
|
|
26
|
-
const authApiUrlRoute = this.apiUrl.replace(/\/$/, "");
|
|
27
|
-
const url = new URL(`${authApiUrlRoute}${endpoint}`);
|
|
28
|
-
// Removes falsy values (e.g. null, undefined etc.) from query params and
|
|
29
|
-
// appends remaining ones to the URL
|
|
30
|
-
Object.entries(queryParams)
|
|
31
|
-
.filter(([, value]) => value) // Remove falsy values
|
|
32
|
-
.forEach(([key, value]) => url.searchParams.append(key, value));
|
|
33
|
-
const response = await fetch(url, {
|
|
34
|
-
method,
|
|
35
|
-
credentials: "include",
|
|
36
|
-
headers: {
|
|
37
|
-
"Content-Type": "application/json",
|
|
38
|
-
...headers,
|
|
39
|
-
},
|
|
40
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
41
|
-
...restOptions,
|
|
7
|
+
export class AuthApiClient extends ApiClient {
|
|
8
|
+
constructor(environment = "mainnet", apiUrl) {
|
|
9
|
+
super({
|
|
10
|
+
apiUrl: apiUrl ?? AUTH_API_ENDPOINTS_BY_ENV[environment],
|
|
42
11
|
});
|
|
43
|
-
const data = await response.json();
|
|
44
|
-
if (!response.ok || data?.error) {
|
|
45
|
-
const error = data?.error ||
|
|
46
|
-
`An error occurred when handling API request: ${JSON.stringify(data)}`;
|
|
47
|
-
throw new Error(`Error [${response.status}]: ${error}`);
|
|
48
|
-
}
|
|
49
|
-
return data;
|
|
50
12
|
}
|
|
51
13
|
async getSession(code) {
|
|
52
14
|
const data = await this.handleRequest("/session", {
|
|
@@ -75,9 +37,21 @@ export class AuthApiClient {
|
|
|
75
37
|
return data;
|
|
76
38
|
}
|
|
77
39
|
async getAccountByMezoIdOrAddress(mezoIdOrAddress) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
40
|
+
let data;
|
|
41
|
+
try {
|
|
42
|
+
data = await this.handleRequest(`/accounts/${mezoIdOrAddress}`, {
|
|
43
|
+
method: "GET",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
// Return null if account is not found instead of throwing an error
|
|
48
|
+
if (error instanceof FetchError && error.status === 404) {
|
|
49
|
+
data = null;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
81
55
|
return data;
|
|
82
56
|
}
|
|
83
57
|
async linkAccount(linkAccountRequest) {
|
package/dist/src/api/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/api/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../src/api/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAyE1C,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,OAAO,EAAE,sBAAsB;IAC/B,OAAO,EAAE,2BAA2B;CACrC,CAAA;AAED,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,YACE,cAAsD,SAAS,EAC/D,MAAe;QAEf,KAAK,CAAC;YACJ,MAAM,EAAE,MAAM,IAAI,yBAAyB,CAAC,WAAW,CAAC;SACzD,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAa;QAC5B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAqB,UAAU,EAAE;YACpE,MAAM,EAAE,KAAK;YACb,WAAW,EAAE,EAAE,IAAI,EAAE;SACtB,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,oBAA0C;QAC5D,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAwB,UAAU,EAAE;YACvE,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,oBAAoB;SAC3B,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAED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,SAAiB;QAClC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CACnC,kBAAkB,EAClB;YACE,MAAM,EAAE,OAAO;YACf,IAAI,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE;SAC5B,CACF,CAAA;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
|
|
2
|
+
body?: Record<string, unknown>;
|
|
3
|
+
queryParams?: Record<string, string | undefined>;
|
|
4
|
+
};
|
|
5
|
+
export declare abstract class ApiClient {
|
|
6
|
+
private apiUrl;
|
|
7
|
+
constructor(opts: {
|
|
8
|
+
apiUrl: string;
|
|
9
|
+
removeVersioning?: boolean;
|
|
10
|
+
});
|
|
11
|
+
/**
|
|
12
|
+
* The request handler for the Passport API. It accepts an API endpoint and
|
|
13
|
+
* request options.
|
|
14
|
+
* @dev Generic type `D` is a type of returned object from the function
|
|
15
|
+
* @dev WARNING: This function hardcodes `credentials: "include"`, meaning
|
|
16
|
+
* cookies and authentication headers will be sent with every request. Ensure
|
|
17
|
+
* this is safe if you plan to use it in other contexts than auth api worker.
|
|
18
|
+
* @param endpoint - The API endpoint to request. Should start with
|
|
19
|
+
* forward slash ("/")
|
|
20
|
+
* @param options - The request options, the `RequestInit` type with
|
|
21
|
+
* additional type-safe properties
|
|
22
|
+
* @returns The promise of the API response
|
|
23
|
+
*/
|
|
24
|
+
protected handleRequest<D>(endpoint: `/${string}`, options?: RequestHandlerOptions): Promise<D>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/client.ts"],"names":[],"mappings":"AAEA,KAAK,qBAAqB,GAAG,IAAI,CAAC,WAAW,EAAE,aAAa,GAAG,MAAM,CAAC,GAAG;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;CACjD,CAAA;AAKD,8BAAsB,SAAS;IAC7B,OAAO,CAAC,MAAM,CAAQ;gBAEV,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;KAAE;IAUhE;;;;;;;;;;;;OAYG;cACa,aAAa,CAAC,CAAC,EAC7B,QAAQ,EAAE,IAAI,MAAM,EAAE,EACtB,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,CAAC,CAAC;CA+Cd"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { FetchError } from "./fetch-error";
|
|
2
|
+
const ENDS_WITH_VERSIONING_REGEX = /\/v\d+(?=\/|$)/;
|
|
3
|
+
const TRAILING_SLASH_REGEX = /\/$/;
|
|
4
|
+
export class ApiClient {
|
|
5
|
+
apiUrl;
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
const { apiUrl, removeVersioning = false } = opts;
|
|
8
|
+
if (removeVersioning) {
|
|
9
|
+
this.apiUrl = apiUrl.replace(ENDS_WITH_VERSIONING_REGEX, "");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
this.apiUrl = apiUrl;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The request handler for the Passport API. It accepts an API endpoint and
|
|
16
|
+
* request options.
|
|
17
|
+
* @dev Generic type `D` is a type of returned object from the function
|
|
18
|
+
* @dev WARNING: This function hardcodes `credentials: "include"`, meaning
|
|
19
|
+
* cookies and authentication headers will be sent with every request. Ensure
|
|
20
|
+
* this is safe if you plan to use it in other contexts than auth api worker.
|
|
21
|
+
* @param endpoint - The API endpoint to request. Should start with
|
|
22
|
+
* forward slash ("/")
|
|
23
|
+
* @param options - The request options, the `RequestInit` type with
|
|
24
|
+
* additional type-safe properties
|
|
25
|
+
* @returns The promise of the API response
|
|
26
|
+
*/
|
|
27
|
+
async handleRequest(endpoint, options = {}) {
|
|
28
|
+
try {
|
|
29
|
+
const { method, body, queryParams = {}, ...restOptions } = options;
|
|
30
|
+
// If last character in apiUrl is forward slash we are removing it
|
|
31
|
+
const authApiUrlRoute = this.apiUrl.replace(TRAILING_SLASH_REGEX, "");
|
|
32
|
+
const url = new URL(`${authApiUrlRoute}${endpoint}`);
|
|
33
|
+
// Removes falsy values (e.g. null, undefined etc.) from query params and
|
|
34
|
+
// appends remaining ones to the URL
|
|
35
|
+
Object.entries(queryParams)
|
|
36
|
+
.filter(([, value]) => value) // Remove falsy values
|
|
37
|
+
.forEach(([key, value]) => url.searchParams.append(key, value));
|
|
38
|
+
const response = await fetch(url, {
|
|
39
|
+
method,
|
|
40
|
+
credentials: "include",
|
|
41
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
42
|
+
...restOptions,
|
|
43
|
+
});
|
|
44
|
+
const data = await response.json();
|
|
45
|
+
if (!response.ok || data?.error) {
|
|
46
|
+
const error = data?.error ||
|
|
47
|
+
`An error occurred when handling API request: ${JSON.stringify(data)}`;
|
|
48
|
+
throw new FetchError(response.status, `Error [${response.status}]: ${error}`);
|
|
49
|
+
}
|
|
50
|
+
return data;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof FetchError) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
|
|
57
|
+
throw new FetchError(500, `Error [500]: An error occurred when handling API request: ${errorMessage}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CA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,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;gBAC7C,GAAG,WAAW;aACf,CAAC,CAAA;YAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,IAAI,EAAE,KAAK,EAAE,CAAC;gBAChC,MAAM,KAAK,GACT,IAAI,EAAE,KAAK;oBACX,gDAAgD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAA;gBACxE,MAAM,IAAI,UAAU,CAClB,QAAQ,CAAC,MAAM,EACf,UAAU,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CACvC,CAAA;YACH,CAAC;YAED,OAAO,IAAS,CAAA;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,UAAU,EAAE,CAAC;gBAChC,MAAM,KAAK,CAAA;YACb,CAAC;YAED,MAAM,YAAY,GAChB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YAChE,MAAM,IAAI,UAAU,CAClB,GAAG,EACH,6DAA6D,YAAY,EAAE,CAC5E,CAAA;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-error.d.ts","sourceRoot":"","sources":["../../../src/api/endpoint-error.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,CAAC,EAAE,MAAM;CAG7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-error.js","sourceRoot":"","sources":["../../../src/api/endpoint-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,OAAgB;QAC1B,KAAK,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAA;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error copy.d.ts","sourceRoot":"","sources":["../../../src/api/fetch-error copy.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;IAE1B,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,MAAM;CAInB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error copy.js","sourceRoot":"","sources":["../../../src/api/fetch-error copy.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAE1B;IADT,YACS,MAAc,EACrB,OAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,WAAM,GAAN,MAAM,CAAQ;IAIvB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error.d.ts","sourceRoot":"","sources":["../../../src/api/fetch-error.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;IAE1B,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,MAAM;CAInB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-error.js","sourceRoot":"","sources":["../../../src/api/fetch-error.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAW,SAAQ,KAAK;IAE1B;IADT,YACS,MAAc,EACrB,OAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAA;QAHP,WAAM,GAAN,MAAM,CAAQ;IAIvB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ApiClient } from "./client";
|
|
2
|
+
type PortalStatistics = {
|
|
3
|
+
hodlers: number;
|
|
4
|
+
depositedBitcoin: string;
|
|
5
|
+
tvl: number;
|
|
6
|
+
currentUsdPerBtc: string;
|
|
7
|
+
currentUsdPerEth: string;
|
|
8
|
+
currentUsdPerTToken: string;
|
|
9
|
+
usdPerBtc24hChange: string;
|
|
10
|
+
};
|
|
11
|
+
type PortalMats = {
|
|
12
|
+
totalMats: number;
|
|
13
|
+
inactiveMats: number;
|
|
14
|
+
matsActivated: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const PORTAL_API_ENDPOINTS_BY_ENV: {
|
|
17
|
+
mainnet: string;
|
|
18
|
+
testnet: string;
|
|
19
|
+
};
|
|
20
|
+
export declare class PortalApiClient extends ApiClient {
|
|
21
|
+
constructor(environment?: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV, apiUrl?: string);
|
|
22
|
+
getPortalStatistics(): Promise<PortalStatistics>;
|
|
23
|
+
getPortalMats(address: string): Promise<PortalMats>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.d.ts","sourceRoot":"","sources":["../../../src/api/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,KAAK,gBAAgB,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,KAAK,UAAU,GAAG;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,2BAA2B;;;CAGvC,CAAA;AAED,qBAAa,eAAgB,SAAQ,SAAS;gBAE1C,WAAW,GAAE,MAAM,OAAO,2BAAuC,EACjE,MAAM,CAAC,EAAE,MAAM;IAQX,mBAAmB;IAQnB,aAAa,CAAC,OAAO,EAAE,MAAM;CAUpC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ApiClient } from "./client";
|
|
2
|
+
export const PORTAL_API_ENDPOINTS_BY_ENV = {
|
|
3
|
+
mainnet: "https://api.mezo.org/api/",
|
|
4
|
+
testnet: "https://api.test.mezo.org/api/",
|
|
5
|
+
};
|
|
6
|
+
export class PortalApiClient extends ApiClient {
|
|
7
|
+
constructor(environment = "mainnet", apiUrl) {
|
|
8
|
+
super({
|
|
9
|
+
apiUrl: apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment],
|
|
10
|
+
removeVersioning: true,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async getPortalStatistics() {
|
|
14
|
+
const data = await this.handleRequest("/v1/statistics", {
|
|
15
|
+
method: "GET",
|
|
16
|
+
});
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
async getPortalMats(address) {
|
|
20
|
+
const data = await this.handleRequest(`/v2/account/${address}/mats`, {
|
|
21
|
+
method: "GET",
|
|
22
|
+
});
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../src/api/portal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAkBpC,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,OAAO,EAAE,2BAA2B;IACpC,OAAO,EAAE,gCAAgC;CAC1C,CAAA;AAED,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAC5C,YACE,cAAwD,SAAS,EACjE,MAAe;QAEf,KAAK,CAAC;YACJ,MAAM,EAAE,MAAM,IAAI,2BAA2B,CAAC,WAAW,CAAC;YAC1D,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,mBAAmB;QACvB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAmB,gBAAgB,EAAE;YACxE,MAAM,EAAE,KAAK;SACd,CAAC,CAAA;QAEF,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAe;QACjC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CACnC,eAAe,OAAO,OAAO,EAC7B;YACE,MAAM,EAAE,KAAK;SACd,CACF,CAAA;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
|