@mezo-org/passport 0.4.0-dev.4 → 0.4.0-dev.41
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 +21 -49
- package/dist/src/api/auth.js.map +1 -1
- package/dist/src/api/client.d.ts +24 -0
- package/dist/src/api/client.d.ts.map +1 -0
- package/dist/src/api/client.js +54 -0
- package/dist/src/api/client.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 +33 -0
- package/dist/src/api/portal.d.ts.map +1 -0
- package/dist/src/api/portal.js +23 -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 +41 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +20 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/constants.d.ts +6 -2
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +8 -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 +4 -1
- package/dist/src/hooks/index.d.ts.map +1 -1
- package/dist/src/hooks/index.js +4 -1
- package/dist/src/hooks/index.js.map +1 -1
- package/dist/src/hooks/useAssetsConversionRates.d.ts +7 -0
- package/dist/src/hooks/useAssetsConversionRates.d.ts.map +1 -0
- package/dist/src/hooks/useAssetsConversionRates.js +24 -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 +73 -0
- package/dist/src/hooks/useAuthenticateWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useAuthenticateWithWallet.js +69 -0
- package/dist/src/hooks/useAuthenticateWithWallet.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 +95 -0
- package/dist/src/hooks/useDropdownData.js.map +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.d.ts.map +1 -1
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js +1 -0
- package/dist/src/hooks/useEnsureNoSessionAndFetchNonce.js.map +1 -1
- 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 +6 -34
- 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 +73 -0
- package/dist/src/hooks/useSignUpWithWallet.d.ts.map +1 -0
- package/dist/src/hooks/useSignUpWithWallet.js +11 -0
- package/dist/src/hooks/useSignUpWithWallet.js.map +1 -0
- 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 +57 -0
- package/dist/src/lib/contracts/index.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 +131 -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 +13 -5
- package/src/api/auth.ts +72 -129
- package/src/api/client.ts +78 -0
- package/src/api/fetch-error.ts +8 -0
- package/src/api/index.ts +2 -0
- package/src/api/portal.ts +57 -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 +27 -6
- package/src/constants.ts +8 -4
- package/src/hooks/constants.ts +1 -0
- package/src/hooks/index.ts +7 -1
- package/src/hooks/useAssetsConversionRates.ts +32 -0
- package/src/hooks/useAuthenticateWithWallet.ts +102 -0
- 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 +139 -0
- package/src/hooks/useEnsureNoSessionAndFetchNonce.ts +1 -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 +14 -42
- package/src/hooks/useSignOut.ts +18 -4
- package/src/hooks/useSignUpWithWallet.ts +21 -0
- 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 +9 -1
- package/src/lib/contracts/index.ts +88 -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
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { FetchError } from "./fetch-error"
|
|
2
|
+
|
|
3
|
+
type RequestHandlerOptions = Omit<RequestInit, "credentials" | "body"> & {
|
|
4
|
+
body?: Record<string, unknown>
|
|
5
|
+
queryParams?: Record<string, string | undefined>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export abstract class ApiClient {
|
|
9
|
+
private apiUrl: string
|
|
10
|
+
|
|
11
|
+
constructor(apiUrl: string) {
|
|
12
|
+
this.apiUrl = apiUrl
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The request handler for the Passport API. It accepts an API endpoint and
|
|
17
|
+
* request options.
|
|
18
|
+
* @dev Generic type `D` is a type of returned object from the function
|
|
19
|
+
* @dev WARNING: This function hardcodes `credentials: "include"`, meaning
|
|
20
|
+
* cookies and authentication headers will be sent with every request. Ensure
|
|
21
|
+
* this is safe if you plan to use it in other contexts than auth api worker.
|
|
22
|
+
* @param endpoint - The API endpoint to request. Should start with
|
|
23
|
+
* forward slash ("/")
|
|
24
|
+
* @param options - The request options, the `RequestInit` type with
|
|
25
|
+
* additional type-safe properties
|
|
26
|
+
* @returns The promise of the API response
|
|
27
|
+
*/
|
|
28
|
+
protected async handleRequest<D>(
|
|
29
|
+
endpoint: `/${string}`,
|
|
30
|
+
options: RequestHandlerOptions = {},
|
|
31
|
+
): Promise<D> {
|
|
32
|
+
try {
|
|
33
|
+
const { method, body, queryParams = {}, ...restOptions } = options
|
|
34
|
+
|
|
35
|
+
// If last character in apiUrl is forward slash we are removing it
|
|
36
|
+
const authApiUrlRoute = this.apiUrl.replace(/\/$/, "")
|
|
37
|
+
const url = new URL(`${authApiUrlRoute}${endpoint}`)
|
|
38
|
+
|
|
39
|
+
// Removes falsy values (e.g. null, undefined etc.) from query params and
|
|
40
|
+
// appends remaining ones to the URL
|
|
41
|
+
Object.entries(queryParams)
|
|
42
|
+
.filter(([, value]) => value) // Remove falsy values
|
|
43
|
+
.forEach(([key, value]) => url.searchParams.append(key, value!))
|
|
44
|
+
|
|
45
|
+
const response = await fetch(url, {
|
|
46
|
+
method,
|
|
47
|
+
credentials: "include",
|
|
48
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
49
|
+
...restOptions,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const data = await response.json()
|
|
53
|
+
|
|
54
|
+
if (!response.ok || data?.error) {
|
|
55
|
+
const error =
|
|
56
|
+
data?.error ||
|
|
57
|
+
`An error occurred when handling API request: ${JSON.stringify(data)}`
|
|
58
|
+
throw new FetchError(
|
|
59
|
+
response.status,
|
|
60
|
+
`Error [${response.status}]: ${error}`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return data as D
|
|
65
|
+
} catch (error) {
|
|
66
|
+
if (error instanceof FetchError) {
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const errorMessage =
|
|
71
|
+
error instanceof Error ? error.message : JSON.stringify(error)
|
|
72
|
+
throw new FetchError(
|
|
73
|
+
500,
|
|
74
|
+
`Error [500]: An error occurred when handling API request: ${errorMessage}`,
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ApiClient } from "./client"
|
|
2
|
+
|
|
3
|
+
type PortalStatistics = {
|
|
4
|
+
hodlers: number
|
|
5
|
+
depositedBitcoin: string
|
|
6
|
+
tvl: number
|
|
7
|
+
currentUsdPerBtc: string
|
|
8
|
+
currentUsdPerEth: string
|
|
9
|
+
currentUsdPerTToken: string
|
|
10
|
+
usdPerBtc24hChange: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type PortalMats = {
|
|
14
|
+
address: string
|
|
15
|
+
totalMats: number
|
|
16
|
+
matsFromDeposits: number
|
|
17
|
+
matsFromReferrals: number
|
|
18
|
+
matsFromSecondaryReferrals: number
|
|
19
|
+
netMatsTransferred: number
|
|
20
|
+
dailyMats: number
|
|
21
|
+
dailyMatsFromDeposits: number
|
|
22
|
+
dailyMatsFromReferrals: number
|
|
23
|
+
dailyMatsFromSecondaryReferrals: number
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const PORTAL_API_ENDPOINTS_BY_ENV = {
|
|
27
|
+
mainnet: "https://api.mezo.org/api/v1",
|
|
28
|
+
testnet: "https://api.test.mezo.org/api/v1",
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class PortalApiClient extends ApiClient {
|
|
32
|
+
constructor(
|
|
33
|
+
environment: keyof typeof PORTAL_API_ENDPOINTS_BY_ENV = "mainnet",
|
|
34
|
+
apiUrl?: string,
|
|
35
|
+
) {
|
|
36
|
+
super(apiUrl ?? PORTAL_API_ENDPOINTS_BY_ENV[environment])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async getPortalStatistics() {
|
|
40
|
+
const data = await this.handleRequest<PortalStatistics>("/statistics", {
|
|
41
|
+
method: "GET",
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return data
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async getPortalMats(address: string) {
|
|
48
|
+
const data = await this.handleRequest<PortalMats>(
|
|
49
|
+
`/accounts/${address}/mats`,
|
|
50
|
+
{
|
|
51
|
+
method: "GET",
|
|
52
|
+
},
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
return data
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Block, BlockProps } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { SVGProps } from "react"
|
|
3
|
+
|
|
4
|
+
function DefaultAvatar(props: SVGProps<SVGSVGElement>) {
|
|
5
|
+
return (
|
|
6
|
+
<svg viewBox="0 0 214 214" fill="none" {...props}>
|
|
7
|
+
<rect y="-0.478027" width="166.379" height="81.7091" fill="#FF004D" />
|
|
8
|
+
<rect x="166" y="-0.478027" width="48" height="82" fill="black" />
|
|
9
|
+
<rect
|
|
10
|
+
x="166.379"
|
|
11
|
+
y="81.231"
|
|
12
|
+
width="24.1044"
|
|
13
|
+
height="132.291"
|
|
14
|
+
fill="#DFFF80"
|
|
15
|
+
/>
|
|
16
|
+
<rect
|
|
17
|
+
x="118.758"
|
|
18
|
+
y="81.231"
|
|
19
|
+
width="24.1044"
|
|
20
|
+
height="132.291"
|
|
21
|
+
fill="#FF5500"
|
|
22
|
+
/>
|
|
23
|
+
<rect
|
|
24
|
+
x="71.1372"
|
|
25
|
+
y="81.231"
|
|
26
|
+
width="24.1044"
|
|
27
|
+
height="132.291"
|
|
28
|
+
fill="#5A59A7"
|
|
29
|
+
/>
|
|
30
|
+
<rect
|
|
31
|
+
x="23.5166"
|
|
32
|
+
y="81.231"
|
|
33
|
+
width="24.1044"
|
|
34
|
+
height="132.291"
|
|
35
|
+
fill="#47B5FF"
|
|
36
|
+
/>
|
|
37
|
+
<rect y="81.231" width="23.5165" height="132.291" fill="#A3C238" />
|
|
38
|
+
<rect
|
|
39
|
+
x="190.483"
|
|
40
|
+
y="81.231"
|
|
41
|
+
width="23.5165"
|
|
42
|
+
height="132.291"
|
|
43
|
+
fill="#6E6E70"
|
|
44
|
+
/>
|
|
45
|
+
<rect
|
|
46
|
+
x="142.863"
|
|
47
|
+
y="81.231"
|
|
48
|
+
width="23.5165"
|
|
49
|
+
height="132.291"
|
|
50
|
+
fill="#0A3C01"
|
|
51
|
+
/>
|
|
52
|
+
<rect
|
|
53
|
+
x="95.2417"
|
|
54
|
+
y="81.231"
|
|
55
|
+
width="23.5165"
|
|
56
|
+
height="132.291"
|
|
57
|
+
fill="#F2A91F"
|
|
58
|
+
/>
|
|
59
|
+
<rect
|
|
60
|
+
x="47.6211"
|
|
61
|
+
y="81.231"
|
|
62
|
+
width="23.5165"
|
|
63
|
+
height="132.291"
|
|
64
|
+
fill="#6B3D01"
|
|
65
|
+
/>
|
|
66
|
+
</svg>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function DefaultAvatarComponent(props: BlockProps) {
|
|
71
|
+
return <Block as={DefaultAvatar} {...props} />
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default DefaultAvatarComponent
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Block, Button, ButtonProps, useStyletron } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { forwardRef, ReactNode, useMemo } from "react"
|
|
3
|
+
|
|
4
|
+
type ConnectedTriggerProps = Omit<ButtonProps, "children" | "size"> & {
|
|
5
|
+
avatar: ReactNode
|
|
6
|
+
size?: "medium" | "large"
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const ConnectedTrigger = forwardRef<HTMLButtonElement, ConnectedTriggerProps>(
|
|
10
|
+
(props, ref) => {
|
|
11
|
+
const { onClick, avatar, size = "medium", ...restProps } = props
|
|
12
|
+
|
|
13
|
+
const [, theme] = useStyletron()
|
|
14
|
+
|
|
15
|
+
const avatarSize = useMemo(() => {
|
|
16
|
+
const sizeMap = {
|
|
17
|
+
medium: theme.sizing.scale950,
|
|
18
|
+
large: theme.sizing.scale1400,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return sizeMap[size]
|
|
22
|
+
}, [theme, size])
|
|
23
|
+
|
|
24
|
+
const buttonPadding = useMemo(() => {
|
|
25
|
+
const paddingMap = {
|
|
26
|
+
medium: theme.sizing.scale0,
|
|
27
|
+
large: theme.sizing.scale100,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return paddingMap[size]
|
|
31
|
+
}, [theme, size])
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Button
|
|
35
|
+
overrides={{
|
|
36
|
+
BaseButton: {
|
|
37
|
+
props: { ref, ...restProps },
|
|
38
|
+
style: {
|
|
39
|
+
borderRadius: "100%",
|
|
40
|
+
overflow: "hidden",
|
|
41
|
+
padding: buttonPadding,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
}}
|
|
45
|
+
onClick={onClick}
|
|
46
|
+
>
|
|
47
|
+
{typeof avatar === "string" ? (
|
|
48
|
+
<Block
|
|
49
|
+
width={avatarSize}
|
|
50
|
+
height={avatarSize}
|
|
51
|
+
as="img"
|
|
52
|
+
src={avatar}
|
|
53
|
+
alt=""
|
|
54
|
+
/>
|
|
55
|
+
) : (
|
|
56
|
+
<Block
|
|
57
|
+
width={avatarSize}
|
|
58
|
+
height={avatarSize}
|
|
59
|
+
overrides={{
|
|
60
|
+
Block: {
|
|
61
|
+
style: {
|
|
62
|
+
borderRadius: "100%",
|
|
63
|
+
overflow: "hidden",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
{avatar}
|
|
69
|
+
</Block>
|
|
70
|
+
)}
|
|
71
|
+
</Button>
|
|
72
|
+
)
|
|
73
|
+
},
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
export default ConnectedTrigger
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Block, useStyletron } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { useEffect } from "react"
|
|
3
|
+
import useDropdownStore, { DropdownView } from "../../stores/dropdownStore"
|
|
4
|
+
import Root from "./Root/Root"
|
|
5
|
+
import Receive from "./Receive/Receive"
|
|
6
|
+
import { DetailedCryptoAsset } from "../../utils/cryptoAssets"
|
|
7
|
+
import TestnetTopBanner from "./TestnetTopBanner"
|
|
8
|
+
|
|
9
|
+
type ContentProps = {
|
|
10
|
+
mezoId: string
|
|
11
|
+
matsBalance: number
|
|
12
|
+
accountAddress: string
|
|
13
|
+
walletAddress: string
|
|
14
|
+
walletType: "bitcoin" | "evm"
|
|
15
|
+
usdTotalBalance: number
|
|
16
|
+
usdTroveDebt: number
|
|
17
|
+
usdCollateral: number
|
|
18
|
+
assets: {
|
|
19
|
+
btc: DetailedCryptoAsset
|
|
20
|
+
musd: DetailedCryptoAsset
|
|
21
|
+
}
|
|
22
|
+
otherAssetsCount: number
|
|
23
|
+
otherAssetsUsdTotal: number
|
|
24
|
+
onSignOut?: () => void
|
|
25
|
+
onOtherAssetsClick?: () => void
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function Content(props: ContentProps) {
|
|
29
|
+
const {
|
|
30
|
+
mezoId,
|
|
31
|
+
accountAddress,
|
|
32
|
+
walletAddress,
|
|
33
|
+
walletType,
|
|
34
|
+
usdTotalBalance,
|
|
35
|
+
assets,
|
|
36
|
+
matsBalance,
|
|
37
|
+
usdTroveDebt,
|
|
38
|
+
usdCollateral,
|
|
39
|
+
otherAssetsCount,
|
|
40
|
+
otherAssetsUsdTotal,
|
|
41
|
+
onSignOut,
|
|
42
|
+
onOtherAssetsClick,
|
|
43
|
+
} = props
|
|
44
|
+
|
|
45
|
+
const [_, theme] = useStyletron()
|
|
46
|
+
|
|
47
|
+
const currentView = useDropdownStore((state) => state.view)
|
|
48
|
+
const setView = useDropdownStore((state) => state.setView)
|
|
49
|
+
|
|
50
|
+
useEffect(
|
|
51
|
+
() => () => {
|
|
52
|
+
setView(DropdownView.ROOT)
|
|
53
|
+
},
|
|
54
|
+
[setView],
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Block
|
|
59
|
+
display="inline-flex"
|
|
60
|
+
flexDirection="column"
|
|
61
|
+
backgroundColor={theme.colors.backgroundPrimary}
|
|
62
|
+
width="100%"
|
|
63
|
+
overrides={{
|
|
64
|
+
Block: {
|
|
65
|
+
style: {
|
|
66
|
+
boxSizing: "border-box",
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
}}
|
|
70
|
+
>
|
|
71
|
+
<TestnetTopBanner />
|
|
72
|
+
|
|
73
|
+
{currentView === DropdownView.ROOT && (
|
|
74
|
+
<Root
|
|
75
|
+
mezoId={mezoId}
|
|
76
|
+
accountAddress={accountAddress}
|
|
77
|
+
walletAddress={walletAddress}
|
|
78
|
+
walletType={walletType}
|
|
79
|
+
usdTotalBalance={usdTotalBalance}
|
|
80
|
+
assets={assets}
|
|
81
|
+
matsBalance={matsBalance}
|
|
82
|
+
usdTroveDebt={usdTroveDebt}
|
|
83
|
+
usdCollateral={usdCollateral}
|
|
84
|
+
otherAssetsCount={otherAssetsCount}
|
|
85
|
+
otherAssetsUsdTotal={otherAssetsUsdTotal}
|
|
86
|
+
onSignOut={onSignOut}
|
|
87
|
+
onOtherAssetsClick={onOtherAssetsClick}
|
|
88
|
+
/>
|
|
89
|
+
)}
|
|
90
|
+
|
|
91
|
+
{currentView === DropdownView.RECEIVE && (
|
|
92
|
+
<Receive address={accountAddress} />
|
|
93
|
+
)}
|
|
94
|
+
</Block>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default Content
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Button, ButtonProps, LogIn01, useStyletron } from "@mezo-org/mezo-clay"
|
|
2
|
+
import React, { forwardRef } from "react"
|
|
3
|
+
|
|
4
|
+
type DisconnectedTriggerProps = Omit<ButtonProps, "children"> & {
|
|
5
|
+
children: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const DisconnectedTrigger = forwardRef<
|
|
9
|
+
HTMLButtonElement,
|
|
10
|
+
DisconnectedTriggerProps
|
|
11
|
+
>((props, ref) => {
|
|
12
|
+
const { onClick, children, ...restProps } = props
|
|
13
|
+
|
|
14
|
+
const [, theme] = useStyletron()
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Button
|
|
18
|
+
startEnhancer={
|
|
19
|
+
<LogIn01 color="currentColor" size={theme.sizing.scale600} />
|
|
20
|
+
}
|
|
21
|
+
overrides={{
|
|
22
|
+
Root: {
|
|
23
|
+
props: { ref },
|
|
24
|
+
},
|
|
25
|
+
}}
|
|
26
|
+
size="small"
|
|
27
|
+
shape="pill"
|
|
28
|
+
onClick={onClick}
|
|
29
|
+
{...restProps}
|
|
30
|
+
>
|
|
31
|
+
{children}
|
|
32
|
+
</Button>
|
|
33
|
+
)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export default DisconnectedTrigger
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ButtonProps,
|
|
3
|
+
StatefulPopover,
|
|
4
|
+
StatefulPopoverProps,
|
|
5
|
+
useStyletron,
|
|
6
|
+
} from "@mezo-org/mezo-clay"
|
|
7
|
+
import { useConnectModal } from "@rainbow-me/rainbowkit"
|
|
8
|
+
import React, { useEffect, useMemo } from "react"
|
|
9
|
+
import { useDisconnect } from "wagmi"
|
|
10
|
+
import DefaultAvatar from "../../assets/DefaultAvatar"
|
|
11
|
+
import useWalletAccount from "../../hooks/useWalletAccount"
|
|
12
|
+
import ConnectedTrigger from "./ConnectedTrigger"
|
|
13
|
+
import Content from "./Content"
|
|
14
|
+
import DisconnectedTrigger from "./DisconnectedTrigger"
|
|
15
|
+
import { useSignInWithWallet } from "../../hooks"
|
|
16
|
+
import useDropdownData from "../../hooks/useDropdownData"
|
|
17
|
+
|
|
18
|
+
export type DropdownProps = {
|
|
19
|
+
/** The callback to be called when the user clicks the sign-out button */
|
|
20
|
+
onSignOut?: () => void
|
|
21
|
+
/** The callback to be called when the user clicks the button in sign-in state */
|
|
22
|
+
onSignIn?: () => void
|
|
23
|
+
/** The props to be passed to the trigger button */
|
|
24
|
+
triggerProps?: {
|
|
25
|
+
signedIn?: Omit<ButtonProps, "onClick" | "size"> & {
|
|
26
|
+
size: "medium" | "large"
|
|
27
|
+
}
|
|
28
|
+
signedOut?: Omit<ButtonProps, "onClick">
|
|
29
|
+
}
|
|
30
|
+
onOtherAssetsClick?: () => void
|
|
31
|
+
/** Time in milliseconds after which account data (like mats or mezo id) in dropdown should be re-fetched. Default is 90000 (90 secs) */
|
|
32
|
+
accountDataRefetchInterval?: number
|
|
33
|
+
/** Time in milliseconds after which native balance in dropdown should be re-fetched. Default is 90000 (90 secs) */
|
|
34
|
+
nativeBalanceRefetchInterval?: number
|
|
35
|
+
} & Omit<StatefulPopoverProps, "children" | "content">
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Passport Dropdown component that displays user's wallet and assets information.
|
|
39
|
+
* @param {DropdownProps} props - Component props.
|
|
40
|
+
* @returns {JSX.Element}
|
|
41
|
+
*/
|
|
42
|
+
export function Dropdown(props: DropdownProps) {
|
|
43
|
+
const {
|
|
44
|
+
placement = "bottomRight",
|
|
45
|
+
animateOutTime = 120,
|
|
46
|
+
onSignIn,
|
|
47
|
+
onSignOut,
|
|
48
|
+
overrides,
|
|
49
|
+
triggerProps,
|
|
50
|
+
onOtherAssetsClick,
|
|
51
|
+
accountDataRefetchInterval,
|
|
52
|
+
nativeBalanceRefetchInterval,
|
|
53
|
+
...restProps
|
|
54
|
+
} = props
|
|
55
|
+
|
|
56
|
+
const [, theme] = useStyletron()
|
|
57
|
+
|
|
58
|
+
const data = useDropdownData({
|
|
59
|
+
accountDataRefetchInterval,
|
|
60
|
+
nativeBalanceRefetchInterval,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const isCriticalDropdownDataLoaded = useMemo(
|
|
64
|
+
() => Boolean(data.mezoId && data.accountAddress && data.walletAddress),
|
|
65
|
+
[data],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const { openConnectModal } = useConnectModal()
|
|
69
|
+
|
|
70
|
+
const { isConnected } = useWalletAccount()
|
|
71
|
+
|
|
72
|
+
const { signInWithWalletAsync, isPending } = useSignInWithWallet()
|
|
73
|
+
|
|
74
|
+
const { disconnectAsync } = useDisconnect()
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (onSignIn) return
|
|
78
|
+
|
|
79
|
+
const handleSignIn = async () => {
|
|
80
|
+
if (!isConnected) return
|
|
81
|
+
|
|
82
|
+
try {
|
|
83
|
+
await signInWithWalletAsync()
|
|
84
|
+
} catch (error) {
|
|
85
|
+
await disconnectAsync()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
handleSignIn()
|
|
90
|
+
}, [disconnectAsync, isConnected, onSignIn, signInWithWalletAsync])
|
|
91
|
+
|
|
92
|
+
if (!isConnected || !isCriticalDropdownDataLoaded) {
|
|
93
|
+
return (
|
|
94
|
+
<DisconnectedTrigger
|
|
95
|
+
// If connect wallet flow is not provided it fallbacks to RainbowKit's
|
|
96
|
+
// connect modal
|
|
97
|
+
onClick={onSignIn || openConnectModal}
|
|
98
|
+
isLoading={isPending}
|
|
99
|
+
{...triggerProps?.signedOut}
|
|
100
|
+
>
|
|
101
|
+
Sign in
|
|
102
|
+
</DisconnectedTrigger>
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<StatefulPopover
|
|
108
|
+
content={
|
|
109
|
+
<Content
|
|
110
|
+
mezoId={data.mezoId!}
|
|
111
|
+
matsBalance={data.matsBalance}
|
|
112
|
+
accountAddress={data.accountAddress!}
|
|
113
|
+
walletAddress={data.walletAddress!}
|
|
114
|
+
walletType={data.walletType}
|
|
115
|
+
usdTotalBalance={data.usdTotalBalance}
|
|
116
|
+
usdTroveDebt={data.usdTroveDebt}
|
|
117
|
+
usdCollateral={data.usdCollateral}
|
|
118
|
+
assets={data.assets}
|
|
119
|
+
otherAssetsCount={data.otherAssetsCount}
|
|
120
|
+
otherAssetsUsdTotal={data.otherAssetsUsdTotal}
|
|
121
|
+
onSignOut={onSignOut}
|
|
122
|
+
onOtherAssetsClick={onOtherAssetsClick}
|
|
123
|
+
/>
|
|
124
|
+
}
|
|
125
|
+
placement={placement}
|
|
126
|
+
animateOutTime={animateOutTime}
|
|
127
|
+
overrides={{
|
|
128
|
+
...overrides,
|
|
129
|
+
Body: {
|
|
130
|
+
...overrides?.Body,
|
|
131
|
+
style: {
|
|
132
|
+
width: "396px",
|
|
133
|
+
borderRadius: theme.borders.radius500,
|
|
134
|
+
boxShadow: theme.lighting.shadow500,
|
|
135
|
+
overflow: "hidden",
|
|
136
|
+
...overrides?.Body?.style,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
}}
|
|
140
|
+
{...restProps}
|
|
141
|
+
>
|
|
142
|
+
<ConnectedTrigger
|
|
143
|
+
avatar={<DefaultAvatar />}
|
|
144
|
+
{...triggerProps?.signedIn}
|
|
145
|
+
/>
|
|
146
|
+
</StatefulPopover>
|
|
147
|
+
)
|
|
148
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ListItem,
|
|
3
|
+
ListItemLabel,
|
|
4
|
+
mergeOverrides,
|
|
5
|
+
ListItemLabelProps,
|
|
6
|
+
IconProps,
|
|
7
|
+
ListItemProps,
|
|
8
|
+
} from "@mezo-org/mezo-clay"
|
|
9
|
+
import React, { FC } from "react"
|
|
10
|
+
|
|
11
|
+
const SHARED_LABEL_OVERRIDES: ListItemLabelProps["overrides"] = {
|
|
12
|
+
LabelDescription: {
|
|
13
|
+
style: {
|
|
14
|
+
color: "#4B4B4B", // contentSecondary
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type ListingItemProps = {
|
|
20
|
+
icon?: FC<IconProps>
|
|
21
|
+
label: string
|
|
22
|
+
subLabel?: string
|
|
23
|
+
value: string
|
|
24
|
+
subValue?: string
|
|
25
|
+
overrides?: ListItemProps["overrides"]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default function ListingItem(props: ListingItemProps) {
|
|
29
|
+
const {
|
|
30
|
+
icon: Icon,
|
|
31
|
+
label,
|
|
32
|
+
subLabel = "",
|
|
33
|
+
value,
|
|
34
|
+
subValue = "",
|
|
35
|
+
overrides,
|
|
36
|
+
} = props
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<ListItem
|
|
40
|
+
artwork={Icon}
|
|
41
|
+
// eslint-disable-next-line react/no-unstable-nested-components
|
|
42
|
+
endEnhancer={() => (
|
|
43
|
+
<ListItemLabel
|
|
44
|
+
description={subValue}
|
|
45
|
+
overrides={mergeOverrides(
|
|
46
|
+
{
|
|
47
|
+
LabelRoot: {
|
|
48
|
+
style: {
|
|
49
|
+
textAlign: "right",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
SHARED_LABEL_OVERRIDES,
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
{value}
|
|
57
|
+
</ListItemLabel>
|
|
58
|
+
)}
|
|
59
|
+
overrides={mergeOverrides(
|
|
60
|
+
{
|
|
61
|
+
Root: {
|
|
62
|
+
style: {
|
|
63
|
+
backgroundColor: "transparent",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
Content: {
|
|
67
|
+
style: {
|
|
68
|
+
border: 0,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
overrides,
|
|
73
|
+
)}
|
|
74
|
+
>
|
|
75
|
+
<ListItemLabel description={subLabel} overrides={SHARED_LABEL_OVERRIDES}>
|
|
76
|
+
{label}
|
|
77
|
+
</ListItemLabel>
|
|
78
|
+
</ListItem>
|
|
79
|
+
)
|
|
80
|
+
}
|