@mezo-org/passport 0.16.0-dev.0 → 0.16.0-dev.1

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.
Files changed (126) hide show
  1. package/dist/src/api/auth.d.ts +9 -0
  2. package/dist/src/api/auth.d.ts.map +1 -1
  3. package/dist/src/api/auth.js +7 -0
  4. package/dist/src/api/auth.js.map +1 -1
  5. package/dist/src/assets/EditIcon.d.ts +5 -0
  6. package/dist/src/assets/EditIcon.d.ts.map +1 -0
  7. package/dist/src/assets/EditIcon.js +10 -0
  8. package/dist/src/assets/EditIcon.js.map +1 -0
  9. package/dist/src/components/Dropdown/Content.d.ts.map +1 -1
  10. package/dist/src/components/Dropdown/Content.js +3 -1
  11. package/dist/src/components/Dropdown/Content.js.map +1 -1
  12. package/dist/src/components/Dropdown/Dropdown.js +1 -1
  13. package/dist/src/components/Dropdown/Dropdown.js.map +1 -1
  14. package/dist/src/components/Dropdown/NestedViewLayout.d.ts.map +1 -1
  15. package/dist/src/components/Dropdown/NestedViewLayout.js +1 -0
  16. package/dist/src/components/Dropdown/NestedViewLayout.js.map +1 -1
  17. package/dist/src/components/Dropdown/Receive/Receive.js +1 -1
  18. package/dist/src/components/Dropdown/Receive/Receive.js.map +1 -1
  19. package/dist/src/components/Dropdown/Root/AccountAddressActions.js +1 -1
  20. package/dist/src/components/Dropdown/Root/AccountAddressActions.js.map +1 -1
  21. package/dist/src/components/Dropdown/Root/Root.d.ts.map +1 -1
  22. package/dist/src/components/Dropdown/Root/Root.js +6 -2
  23. package/dist/src/components/Dropdown/Root/Root.js.map +1 -1
  24. package/dist/src/components/Dropdown/Root/WalletAddress.js +1 -1
  25. package/dist/src/components/Dropdown/Root/WalletAddress.js.map +1 -1
  26. package/dist/src/components/Dropdown/Settings/InlineEditField.d.ts +12 -0
  27. package/dist/src/components/Dropdown/Settings/InlineEditField.d.ts.map +1 -0
  28. package/dist/src/components/Dropdown/Settings/InlineEditField.js +95 -0
  29. package/dist/src/components/Dropdown/Settings/InlineEditField.js.map +1 -0
  30. package/dist/src/components/Dropdown/Settings/Settings.d.ts +4 -0
  31. package/dist/src/components/Dropdown/Settings/Settings.d.ts.map +1 -0
  32. package/dist/src/components/Dropdown/Settings/Settings.js +36 -0
  33. package/dist/src/components/Dropdown/Settings/Settings.js.map +1 -0
  34. package/dist/src/config.d.ts +3 -4
  35. package/dist/src/config.d.ts.map +1 -1
  36. package/dist/src/config.js +9 -13
  37. package/dist/src/config.js.map +1 -1
  38. package/dist/src/hooks/index.d.ts +2 -0
  39. package/dist/src/hooks/index.d.ts.map +1 -1
  40. package/dist/src/hooks/index.js +2 -0
  41. package/dist/src/hooks/index.js.map +1 -1
  42. package/dist/src/hooks/useAcceptDocuments.d.ts +18 -0
  43. package/dist/src/hooks/useAcceptDocuments.d.ts.map +1 -1
  44. package/dist/src/hooks/useAuthenticateWithWallet.js +1 -1
  45. package/dist/src/hooks/useAuthenticateWithWallet.js.map +1 -1
  46. package/dist/src/hooks/useBorrowData.js +1 -1
  47. package/dist/src/hooks/useBorrowData.js.map +1 -1
  48. package/dist/src/hooks/useCollateralPrice.js +1 -1
  49. package/dist/src/hooks/useCollateralPrice.js.map +1 -1
  50. package/dist/src/hooks/useCreateAccount.d.ts +18 -0
  51. package/dist/src/hooks/useCreateAccount.d.ts.map +1 -1
  52. package/dist/src/hooks/useCreateAccount.js +1 -1
  53. package/dist/src/hooks/useCreateAccount.js.map +1 -1
  54. package/dist/src/hooks/useLinkAccount.js +1 -1
  55. package/dist/src/hooks/useLinkAccount.js.map +1 -1
  56. package/dist/src/hooks/useTokensBalances.d.ts.map +1 -1
  57. package/dist/src/hooks/useTokensBalances.js +2 -10
  58. package/dist/src/hooks/useTokensBalances.js.map +1 -1
  59. package/dist/src/hooks/useUpdateMezoId.d.ts +18 -0
  60. package/dist/src/hooks/useUpdateMezoId.d.ts.map +1 -1
  61. package/dist/src/hooks/useUpdateUserProfile.d.ts +171 -0
  62. package/dist/src/hooks/useUpdateUserProfile.d.ts.map +1 -0
  63. package/dist/src/hooks/useUpdateUserProfile.js +19 -0
  64. package/dist/src/hooks/useUpdateUserProfile.js.map +1 -0
  65. package/dist/src/hooks/useWalletAccount.d.ts +3 -6
  66. package/dist/src/hooks/useWalletAccount.d.ts.map +1 -1
  67. package/dist/src/hooks/useWalletAccount.js +6 -4
  68. package/dist/src/hooks/useWalletAccount.js.map +1 -1
  69. package/dist/src/hooks/useWatchTransferEvents.d.ts.map +1 -1
  70. package/dist/src/hooks/useWatchTransferEvents.js +0 -1
  71. package/dist/src/hooks/useWatchTransferEvents.js.map +1 -1
  72. package/dist/src/index.d.ts +1 -1
  73. package/dist/src/index.d.ts.map +1 -1
  74. package/dist/src/index.js +1 -1
  75. package/dist/src/index.js.map +1 -1
  76. package/dist/src/lib/contracts/index.d.ts +1 -1
  77. package/dist/src/lib/contracts/index.d.ts.map +1 -1
  78. package/dist/src/lib/contracts/index.js +0 -3
  79. package/dist/src/lib/contracts/index.js.map +1 -1
  80. package/dist/src/stores/dropdownStore.d.ts +2 -1
  81. package/dist/src/stores/dropdownStore.d.ts.map +1 -1
  82. package/dist/src/stores/dropdownStore.js +1 -0
  83. package/dist/src/stores/dropdownStore.js.map +1 -1
  84. package/dist/src/utils/assets.d.ts +0 -15
  85. package/dist/src/utils/assets.d.ts.map +1 -1
  86. package/dist/src/utils/assets.js +0 -13
  87. package/dist/src/utils/assets.js.map +1 -1
  88. package/dist/src/utils/validation.d.ts +13 -0
  89. package/dist/src/utils/validation.d.ts.map +1 -0
  90. package/dist/src/utils/validation.js +34 -0
  91. package/dist/src/utils/validation.js.map +1 -0
  92. package/dist/src/utils/validation.test.d.ts +2 -0
  93. package/dist/src/utils/validation.test.d.ts.map +1 -0
  94. package/dist/src/utils/validation.test.js +63 -0
  95. package/dist/src/utils/validation.test.js.map +1 -0
  96. package/package.json +10 -8
  97. package/src/api/auth.ts +22 -0
  98. package/src/assets/EditIcon.tsx +33 -0
  99. package/src/components/Dropdown/Content.tsx +3 -0
  100. package/src/components/Dropdown/Dropdown.tsx +1 -1
  101. package/src/components/Dropdown/NestedViewLayout.tsx +1 -0
  102. package/src/components/Dropdown/Receive/Receive.tsx +1 -1
  103. package/src/components/Dropdown/Root/AccountAddressActions.tsx +1 -1
  104. package/src/components/Dropdown/Root/Root.tsx +29 -2
  105. package/src/components/Dropdown/Root/WalletAddress.tsx +1 -1
  106. package/src/components/Dropdown/Settings/InlineEditField.tsx +212 -0
  107. package/src/components/Dropdown/Settings/Settings.tsx +87 -0
  108. package/src/config.ts +16 -26
  109. package/src/hooks/index.ts +2 -0
  110. package/src/hooks/useAuthenticateWithWallet.ts +1 -1
  111. package/src/hooks/useBorrowData.ts +1 -1
  112. package/src/hooks/useCollateralPrice.ts +1 -1
  113. package/src/hooks/useCreateAccount.ts +1 -1
  114. package/src/hooks/useLinkAccount.ts +1 -1
  115. package/src/hooks/useTokensBalances.ts +1 -10
  116. package/src/hooks/useUpdateUserProfile.ts +34 -0
  117. package/src/hooks/useWalletAccount.ts +15 -10
  118. package/src/hooks/useWatchTransferEvents.ts +0 -1
  119. package/src/index.ts +0 -1
  120. package/src/lib/contracts/index.ts +0 -4
  121. package/src/stores/dropdownStore.ts +1 -0
  122. package/src/utils/assets.ts +0 -14
  123. package/src/utils/validation.test.ts +97 -0
  124. package/src/utils/validation.ts +35 -0
  125. package/dist/src/lib/contracts/artifacts/MEZO.json +0 -428
  126. package/src/lib/contracts/artifacts/MEZO.json +0 -428
@@ -1,4 +1,10 @@
1
- import { Block, Button, LogOut01, useStyletron } from "@mezo-org/mezo-clay"
1
+ import {
2
+ Block,
3
+ Button,
4
+ LogOut01,
5
+ Settings01,
6
+ useStyletron,
7
+ } from "@mezo-org/mezo-clay"
2
8
  import React, { useCallback } from "react"
3
9
  import { useDisconnect } from "wagmi"
4
10
  import { useSignOut } from "../../../hooks"
@@ -9,6 +15,7 @@ import AccountAddressActions from "./AccountAddressActions"
9
15
  import AccountOtherAssets from "./AccountOtherAssets"
10
16
  import AccountBtcListing from "./AccountBtcListing"
11
17
  import AccountMusdListing from "./AccountMusdListing"
18
+ import useDropdownStore, { DropdownView } from "../../../stores/dropdownStore"
12
19
 
13
20
  type RootProps = {
14
21
  onSignOut?: () => void
@@ -23,6 +30,12 @@ export default function Root(props: RootProps) {
23
30
  const { disconnect } = useDisconnect()
24
31
  const { signOut } = useSignOut()
25
32
 
33
+ const setDropdownView = useDropdownStore((state) => state.setView)
34
+ const handleSettingsClick = useCallback(
35
+ () => setDropdownView(DropdownView.SETTINGS),
36
+ [setDropdownView],
37
+ )
38
+
26
39
  const handleLogOut = useCallback(() => {
27
40
  if (onSignOut) {
28
41
  onSignOut()
@@ -61,7 +74,21 @@ export default function Root(props: RootProps) {
61
74
  overrides={overridesWithDivider}
62
75
  />
63
76
 
64
- <Block padding={theme.sizing.scale300}>
77
+ <Block
78
+ display="flex"
79
+ alignItems="center"
80
+ justifyContent="space-between"
81
+ padding={theme.sizing.scale300}
82
+ >
83
+ <Button
84
+ size="small"
85
+ shape="pill"
86
+ kind="tertiary"
87
+ startEnhancer={<Settings01 color="currentColor" size={16} />}
88
+ onClick={handleSettingsClick}
89
+ >
90
+ Settings
91
+ </Button>
65
92
  <Button
66
93
  size="small"
67
94
  shape="pill"
@@ -13,7 +13,7 @@ import React, { useState } from "react"
13
13
  import { useCopyToClipboard } from "usehooks-ts"
14
14
  import { usePassportContext } from "../../../hooks/usePassportContext"
15
15
  import { getAddressExplorerUrl, trimAddress } from "../../../utils/address"
16
- import useWalletAccount from "../../../hooks/useWalletAccount"
16
+ import { useWalletAccount } from "../../../hooks/useWalletAccount"
17
17
 
18
18
  export default function WalletAddress(props: BlockProps) {
19
19
  const { overrides, ...restProps } = props
@@ -0,0 +1,212 @@
1
+ import {
2
+ Block,
3
+ ButtonIcon,
4
+ Check,
5
+ Close,
6
+ Input,
7
+ LabelSmall,
8
+ ParagraphSmall,
9
+ Spinner,
10
+ useStyletron,
11
+ } from "@mezo-org/mezo-clay"
12
+ import React, { useCallback, useEffect, useState } from "react"
13
+ import EditIcon from "../../../assets/EditIcon"
14
+
15
+ type InlineEditFieldProps = {
16
+ label: string
17
+ value: string
18
+ placeholder?: string
19
+ onSave: (value: string) => Promise<void>
20
+ validate?: (value: string) => string | null
21
+ isLoading?: boolean
22
+ }
23
+
24
+ type InlineFieldWrapperProps = {
25
+ label: string
26
+ children: React.ReactNode
27
+ }
28
+
29
+ function InlineFieldWrapper({ label, children }: InlineFieldWrapperProps) {
30
+ const [, theme] = useStyletron()
31
+
32
+ return (
33
+ <Block
34
+ display="flex"
35
+ flexDirection="column"
36
+ overrides={{
37
+ Block: {
38
+ style: {
39
+ gap: theme.sizing.scale200,
40
+ },
41
+ },
42
+ }}
43
+ >
44
+ <LabelSmall color={theme.colors.contentSecondary}>{label}</LabelSmall>
45
+ {children}
46
+ </Block>
47
+ )
48
+ }
49
+
50
+ export default function InlineEditField(props: InlineEditFieldProps) {
51
+ const { label, value, placeholder, onSave, validate, isLoading } = props
52
+
53
+ const [, theme] = useStyletron()
54
+ const [isEditing, setIsEditing] = useState(false)
55
+ const [editValue, setEditValue] = useState(value)
56
+ const [error, setError] = useState<string | null>(null)
57
+ const [isSaving, setIsSaving] = useState(false)
58
+
59
+ useEffect(() => {
60
+ setEditValue(value)
61
+ }, [value])
62
+
63
+ const handleEdit = useCallback(() => {
64
+ setIsEditing(true)
65
+ setEditValue(value)
66
+ setError(null)
67
+ }, [value])
68
+
69
+ const handleCancel = useCallback(() => {
70
+ setIsEditing(false)
71
+ setEditValue(value)
72
+ setError(null)
73
+ }, [value])
74
+
75
+ const handleSave = useCallback(async () => {
76
+ if (validate) {
77
+ const validationError = validate(editValue)
78
+ if (validationError) {
79
+ setError(validationError)
80
+ return
81
+ }
82
+ }
83
+
84
+ setIsSaving(true)
85
+ try {
86
+ await onSave(editValue)
87
+ setIsEditing(false)
88
+ setError(null)
89
+ } catch (err) {
90
+ setError(err instanceof Error ? err.message : "Failed to save")
91
+ } finally {
92
+ setIsSaving(false)
93
+ }
94
+ }, [editValue, onSave, validate])
95
+
96
+ const handleKeyDown = useCallback(
97
+ (e: React.KeyboardEvent) => {
98
+ if (e.key === "Enter") {
99
+ handleSave()
100
+ } else if (e.key === "Escape") {
101
+ handleCancel()
102
+ }
103
+ },
104
+ [handleSave, handleCancel],
105
+ )
106
+
107
+ if (isLoading) {
108
+ return (
109
+ <InlineFieldWrapper label={label}>
110
+ <Block
111
+ display="flex"
112
+ alignItems="center"
113
+ height={theme.sizing.scale950}
114
+ >
115
+ <Spinner $size={theme.sizing.scale600} />
116
+ </Block>
117
+ </InlineFieldWrapper>
118
+ )
119
+ }
120
+
121
+ if (isEditing) {
122
+ return (
123
+ <InlineFieldWrapper label={label}>
124
+ <Block
125
+ display="flex"
126
+ alignItems="center"
127
+ width="100%"
128
+ gridGap="scale300"
129
+ >
130
+ <Block flex={1}>
131
+ <Input
132
+ value={editValue}
133
+ onChange={(e) => {
134
+ setEditValue(e.currentTarget.value)
135
+ setError(null)
136
+ }}
137
+ onKeyDown={handleKeyDown}
138
+ placeholder={placeholder}
139
+ size="small"
140
+ error={!!error}
141
+ disabled={isSaving}
142
+ autoFocus
143
+ />
144
+ </Block>
145
+ <ButtonIcon
146
+ onClick={handleSave}
147
+ size="small"
148
+ shape="circle"
149
+ kind="secondary"
150
+ disabled={isSaving}
151
+ aria-label="Save"
152
+ >
153
+ {isSaving ? (
154
+ <Spinner $size={theme.sizing.scale500} />
155
+ ) : (
156
+ <Check size={14} color="currentColor" />
157
+ )}
158
+ </ButtonIcon>
159
+ <ButtonIcon
160
+ onClick={handleCancel}
161
+ size="small"
162
+ shape="circle"
163
+ kind="tertiary"
164
+ disabled={isSaving}
165
+ aria-label="Cancel"
166
+ >
167
+ <Close size={14} color="currentColor" />
168
+ </ButtonIcon>
169
+ </Block>
170
+ {error && (
171
+ <ParagraphSmall
172
+ color={theme.colors.contentNegative}
173
+ marginTop={0}
174
+ marginBottom={0}
175
+ >
176
+ {error}
177
+ </ParagraphSmall>
178
+ )}
179
+ </InlineFieldWrapper>
180
+ )
181
+ }
182
+
183
+ return (
184
+ <InlineFieldWrapper label={label}>
185
+ <Block
186
+ display="flex"
187
+ alignItems="center"
188
+ justifyContent="space-between"
189
+ onClick={handleEdit}
190
+ overrides={{
191
+ Block: {
192
+ style: {
193
+ cursor: "pointer",
194
+ minHeight: theme.sizing.scale950,
195
+ },
196
+ },
197
+ }}
198
+ >
199
+ <ParagraphSmall
200
+ marginTop={0}
201
+ marginBottom={0}
202
+ color={
203
+ value ? theme.colors.contentPrimary : theme.colors.contentTertiary
204
+ }
205
+ >
206
+ {value || placeholder}
207
+ </ParagraphSmall>
208
+ <EditIcon size={16} color={theme.colors.contentTertiary} />
209
+ </Block>
210
+ </InlineFieldWrapper>
211
+ )
212
+ }
@@ -0,0 +1,87 @@
1
+ import { Block, ParagraphSmall, Link, useStyletron } from "@mezo-org/mezo-clay"
2
+ import React, { useCallback } from "react"
3
+ import NestedViewLayout from "../NestedViewLayout"
4
+ import InlineEditField from "./InlineEditField"
5
+ import { useGetCurrentAccount, useUpdateUserProfile } from "../../../hooks"
6
+ import { validateEmail, validateTelegram } from "../../../utils/validation"
7
+
8
+ function Settings() {
9
+ const [, theme] = useStyletron()
10
+
11
+ const { data: account, isPending: isCurrentAccountPending } =
12
+ useGetCurrentAccount()
13
+ const { updateProfileAsync } = useUpdateUserProfile()
14
+
15
+ const handleSaveEmail = useCallback(
16
+ async (value: string) => {
17
+ await updateProfileAsync({ email: value || "" })
18
+ },
19
+ [updateProfileAsync],
20
+ )
21
+
22
+ const handleSaveTelegram = useCallback(
23
+ async (value: string) => {
24
+ const handle = value.startsWith("@") ? value.slice(1) : value
25
+ await updateProfileAsync({ telegram: handle || "" })
26
+ },
27
+ [updateProfileAsync],
28
+ )
29
+
30
+ return (
31
+ <NestedViewLayout>
32
+ <ParagraphSmall
33
+ marginTop={0}
34
+ marginBottom={theme.sizing.scale800}
35
+ color={theme.colors.contentSecondary}
36
+ >
37
+ Update your contact information to stay connected.
38
+ </ParagraphSmall>
39
+
40
+ <Block
41
+ display="flex"
42
+ flexDirection="column"
43
+ overrides={{
44
+ Block: {
45
+ style: {
46
+ gap: theme.sizing.scale600,
47
+ },
48
+ },
49
+ }}
50
+ >
51
+ <InlineEditField
52
+ label="Email"
53
+ value={account?.email || ""}
54
+ placeholder="Enter your email"
55
+ onSave={handleSaveEmail}
56
+ validate={validateEmail}
57
+ isLoading={isCurrentAccountPending}
58
+ />
59
+
60
+ <InlineEditField
61
+ label="Telegram"
62
+ value={account?.telegram || ""}
63
+ placeholder="Enter your Telegram handle"
64
+ onSave={handleSaveTelegram}
65
+ validate={validateTelegram}
66
+ isLoading={isCurrentAccountPending}
67
+ />
68
+ </Block>
69
+
70
+ <ParagraphSmall
71
+ marginTop={theme.sizing.scale800}
72
+ marginBottom={0}
73
+ color={theme.colors.contentTertiary}
74
+ >
75
+ By providing your contact information, you agree to receive service
76
+ notifications and occasional promotional messages. Promotional messages
77
+ will always include an opt out link. The Privacy Policy is available{" "}
78
+ <Link href="https://mezo.org/privacy" target="_blank">
79
+ here
80
+ </Link>
81
+ .
82
+ </ParagraphSmall>
83
+ </NestedViewLayout>
84
+ )
85
+ }
86
+
87
+ export default Settings
package/src/config.ts CHANGED
@@ -12,7 +12,7 @@ import { getOKXWallet, getUnisatWallet, getXverseWallet } from "./wallet"
12
12
 
13
13
  type WagmiConfigParameters = Omit<
14
14
  CreateConfigParameters,
15
- "client" | "connectors" | "chains" | "wallets" | "transports"
15
+ "client" | "connectors" | "chains" | "transports"
16
16
  >
17
17
  type GetDefaultConfigParameters = WagmiConfigParameters & {
18
18
  appName: string
@@ -20,32 +20,12 @@ type GetDefaultConfigParameters = WagmiConfigParameters & {
20
20
  appDescription?: string
21
21
  appUrl?: string
22
22
  appIcon?: string
23
- bitcoinWallets?: WalletList
24
- walletConnectProjectId?: string
23
+ wallets?: WalletList
24
+ walletConnectProjectId: string
25
25
  chains?: [Chain, ...Chain[]]
26
26
  transports?: Pick<CreateConfigParameters, "transports">
27
27
  }
28
28
 
29
- const transports = {
30
- [CHAIN_ID.mainnet]: http(RPC_BY_NETWORK.mainnet.http),
31
- [CHAIN_ID.testnet]: http(RPC_BY_NETWORK.testnet.http),
32
- } as Pick<CreateConfigParameters, "transports">
33
-
34
- export const defaultConfig: Required<
35
- Pick<
36
- GetDefaultConfigParameters,
37
- | "transports"
38
- | "walletConnectProjectId"
39
- | "chains"
40
- | "multiInjectedProviderDiscovery"
41
- >
42
- > = {
43
- transports,
44
- walletConnectProjectId: "",
45
- chains: [mezoMainnet, mezoTestnet],
46
- multiInjectedProviderDiscovery: true,
47
- }
48
-
49
29
  const bitcoinWalletTestnetConfig = {
50
30
  rpcUrl: RPC_BY_NETWORK.testnet.http,
51
31
  chainId: CHAIN_ID.testnet,
@@ -112,17 +92,27 @@ export function getConfig(config: GetDefaultConfigParameters): Config {
112
92
  const {
113
93
  appName,
114
94
  mezoNetwork = "mainnet",
115
- walletConnectProjectId = defaultConfig.walletConnectProjectId,
95
+ walletConnectProjectId,
116
96
  ...restParameters
117
97
  } = config
118
98
 
119
- const wallets = config.bitcoinWallets ?? [...getDefaultWallets(mezoNetwork)]
99
+ const chains: [Chain, ...Chain[]] =
100
+ mezoNetwork === "mainnet" ? [mezoMainnet] : [mezoTestnet]
101
+
102
+ const transports =
103
+ mezoNetwork === "mainnet"
104
+ ? { [mezoMainnet.id]: http(RPC_BY_NETWORK.mainnet.http) }
105
+ : { [mezoTestnet.id]: http(RPC_BY_NETWORK.testnet.http) }
106
+
107
+ const wallets = config.wallets ?? [...getDefaultWallets(mezoNetwork)]
120
108
 
121
109
  return getDefaultConfig({
122
- ...defaultConfig,
123
110
  appName,
111
+ chains,
112
+ transports,
124
113
  wallets,
125
114
  projectId: walletConnectProjectId,
115
+ multiInjectedProviderDiscovery: true,
126
116
  ...restParameters,
127
117
  })
128
118
  }
@@ -25,5 +25,7 @@ export {
25
25
  useResetTokensBalances,
26
26
  } from "./useTokensBalances"
27
27
  export * from "./useUpdateMezoId"
28
+ export * from "./useUpdateUserProfile"
28
29
  export * from "./useValidateMezoId"
29
30
  export * from "./useRewardsApiClient"
31
+ export * from "./useWalletAccount"
@@ -13,7 +13,7 @@ import {
13
13
  } from "../utils/siww"
14
14
  import { useGetAccountByAddress } from "./useGetAccountByAddress"
15
15
  import type { Session } from "../api"
16
- import useWalletAccount from "./useWalletAccount"
16
+ import { useWalletAccount } from "./useWalletAccount"
17
17
 
18
18
  function useAuthenticateWithWallet(
19
19
  shouldCreateAccount = false,
@@ -9,7 +9,7 @@ import {
9
9
  import { usePassportContext } from "./usePassportContext"
10
10
  import { CHAIN_ID } from "../constants"
11
11
  import { bigIntMax, normalizePrecision } from "../utils/numbers"
12
- import useWalletAccount from "./useWalletAccount"
12
+ import { useWalletAccount } from "./useWalletAccount"
13
13
  import { getAsset } from "../utils/assets"
14
14
  import { convertToUsd } from "../utils/currency"
15
15
  import { useCollateralPrice } from "./useCollateralPrice"
@@ -6,7 +6,7 @@ import {
6
6
  } from "../lib/contracts"
7
7
  import { usePassportContext } from "./usePassportContext"
8
8
  import { CHAIN_ID } from "../constants"
9
- import useWalletAccount from "./useWalletAccount"
9
+ import { useWalletAccount } from "./useWalletAccount"
10
10
 
11
11
  // Wagmi handles typesafety with ABI const assertions. TypeScript doesn't
12
12
  // support importing JSON as const yet so types cannot be inferred from the
@@ -7,7 +7,7 @@ import {
7
7
  import { useAuthApiClient } from "./useAuthApiClient"
8
8
  import { QUERY_KEYS } from "./constants"
9
9
  import type { CreateAccountRequest, CreateAccountResponse } from "../api"
10
- import useWalletAccount from "./useWalletAccount"
10
+ import { useWalletAccount } from "./useWalletAccount"
11
11
  import { getBitcoinPublicKeyFromConnector } from "../utils/wagmi"
12
12
 
13
13
  export function useCreateAccount(
@@ -7,7 +7,7 @@ import {
7
7
  import { useAuthApiClient } from "./useAuthApiClient"
8
8
  import type { LinkAccountResponse, SignatureData } from "../api"
9
9
  import { QUERY_KEYS } from "./constants"
10
- import useWalletAccount from "./useWalletAccount"
10
+ import { useWalletAccount } from "./useWalletAccount"
11
11
  import { getBitcoinPublicKeyFromConnector } from "../utils/wagmi"
12
12
 
13
13
  type LinkAccountMutationFnParameters =
@@ -13,12 +13,11 @@ import {
13
13
  MezoChainToken,
14
14
  testnetTokenContracts,
15
15
  } from "../lib/contracts"
16
- import useWalletAccount from "./useWalletAccount"
16
+ import { useWalletAccount } from "./useWalletAccount"
17
17
  import {
18
18
  getAsset,
19
19
  isBitcoinLikeCryptoAsset,
20
20
  isTTokenCryptoAsset,
21
- isMezoCryptoAsset,
22
21
  } from "../utils/assets"
23
22
  import { convertToUsd } from "../utils/currency"
24
23
  import { CHAIN_ID, mezoMainnet, mezoTestnet } from "../constants"
@@ -66,7 +65,6 @@ const BALANCE_TOKENS: MezoChainToken[] = [
66
65
  "mUSDT",
67
66
  "mxSolvBTC",
68
67
  "MUSD",
69
- "MEZO",
70
68
  ]
71
69
 
72
70
  type UseMezoChainTokensBalancesOptions<T extends MezoChainToken[]> = {
@@ -221,13 +219,6 @@ export function useTokensBalances<T extends MezoChainToken[]>(
221
219
  conversion.decimals,
222
220
  )
223
221
  }
224
- // TODO: Provide MEZO oracle to get accurate token price
225
- if (isMezoCryptoAsset(tokenBalance.symbol)) {
226
- usd = {
227
- value: 0n,
228
- formatted: "0",
229
- }
230
- }
231
222
 
232
223
  return { ...tokenBalance, usd }
233
224
  })
@@ -0,0 +1,34 @@
1
+ import {
2
+ useQueryClient,
3
+ useMutation,
4
+ MutationOptions,
5
+ DefaultError,
6
+ } from "@tanstack/react-query"
7
+ import { useAuthApiClient } from "./useAuthApiClient"
8
+ import { QUERY_KEYS } from "./constants"
9
+ import type { UpdateAccountRequest, UpdateAccountResponse } from "../api"
10
+
11
+ export function useUpdateUserProfile(
12
+ mutationOptions: Omit<
13
+ MutationOptions<UpdateAccountResponse, DefaultError, UpdateAccountRequest>,
14
+ "mutationFn" | "mutationKey"
15
+ > = {},
16
+ ) {
17
+ const queryClient = useQueryClient()
18
+ const authApiClient = useAuthApiClient()
19
+
20
+ const { onSuccess: customOnSuccess, ...restMutationOptions } = mutationOptions
21
+
22
+ const { mutate, mutateAsync, ...rest } = useMutation({
23
+ mutationFn: (updates: UpdateAccountRequest) =>
24
+ authApiClient.updateAccount(updates),
25
+ onSuccess: (data, variables, context) => {
26
+ queryClient.resetQueries({ queryKey: [QUERY_KEYS.ACCOUNT] })
27
+
28
+ if (customOnSuccess) customOnSuccess(data, variables, context)
29
+ },
30
+ ...restMutationOptions,
31
+ })
32
+
33
+ return { updateProfile: mutate, updateProfileAsync: mutateAsync, ...rest }
34
+ }
@@ -2,21 +2,22 @@ import { OrangeKitConnector } from "@mezo-org/orangekit"
2
2
  import { useQuery } from "@tanstack/react-query"
3
3
  import { useMemo } from "react"
4
4
  import { Address } from "viem"
5
- import { Connector, useAccount } from "wagmi"
5
+ import { useAccount, UseAccountReturnType } from "wagmi"
6
6
 
7
- type UseWalletAccountReturn = {
7
+ type UseWalletAccountReturn = Omit<UseAccountReturnType, "address"> & {
8
8
  accountAddress?: Address
9
9
  walletAddress?: string
10
- isConnected: boolean
11
10
  networkFamily: "bitcoin" | "evm"
12
- connector?: Connector
13
- chainId?: number
14
11
  }
15
12
 
16
- // TODO: Invesitgate race conditions and refactor
17
-
18
- export default function useWalletAccount(): UseWalletAccountReturn {
19
- const { address: evmAddress, connector, chainId } = useAccount()
13
+ export function useWalletAccount(): UseWalletAccountReturn {
14
+ const {
15
+ address: evmAddress,
16
+ connector,
17
+ chainId,
18
+ isConnected,
19
+ ...rest
20
+ } = useAccount()
20
21
 
21
22
  const networkFamily = useMemo(
22
23
  () => (connector?.type !== "orangekit" ? "evm" : "bitcoin"),
@@ -38,6 +39,7 @@ export default function useWalletAccount(): UseWalletAccountReturn {
38
39
  balance,
39
40
  }
40
41
  },
42
+ enabled: networkFamily === "bitcoin" && !!connector,
41
43
  })
42
44
 
43
45
  const { address: btcAddress } = btcData || {}
@@ -45,9 +47,12 @@ export default function useWalletAccount(): UseWalletAccountReturn {
45
47
  return {
46
48
  accountAddress: evmAddress,
47
49
  walletAddress: btcAddress ?? evmAddress,
48
- isConnected: networkFamily === "bitcoin" ? !!btcAddress : !!evmAddress,
50
+ isConnected:
51
+ isConnected &&
52
+ (networkFamily === "bitcoin" ? !!btcAddress : !!evmAddress),
49
53
  networkFamily,
50
54
  connector,
51
55
  chainId,
56
+ ...rest,
52
57
  }
53
58
  }
@@ -69,7 +69,6 @@ function useWatchTransferEventsForAllTokens() {
69
69
  useWatchTransferEvents("mUSDT")
70
70
  useWatchTransferEvents("mxSolvBTC")
71
71
  useWatchTransferEvents("MUSD")
72
- useWatchTransferEvents("MEZO")
73
72
  }
74
73
 
75
74
  export { useWatchTransferEvents, useWatchTransferEventsForAllTokens }
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from "./components"
2
2
  export {
3
- defaultConfig,
4
3
  unisatWalletMezoMainnet,
5
4
  unisatWalletMezoTestnet,
6
5
  okxWalletMezoMainnet,
@@ -29,7 +29,6 @@ import priceFeed from "@mezo-org/musd-contracts/deployments/mainnet/PriceFeed.js
29
29
  import priceFeedTestnet from "@mezo-org/musd-contracts/deployments/matsnet/PriceFeed.json"
30
30
 
31
31
  import { Abi, Address } from "viem"
32
- import mezoArtifact from "./artifacts/MEZO.json"
33
32
 
34
33
  export type MezoChainToken =
35
34
  | "mcbBTC"
@@ -43,7 +42,6 @@ export type MezoChainToken =
43
42
  | "mUSDT"
44
43
  | "mxSolvBTC"
45
44
  | "MUSD"
46
- | "MEZO"
47
45
 
48
46
  export type MezoBorrowContract =
49
47
  | "TroveManager"
@@ -70,7 +68,6 @@ export const testnetTokenContracts = {
70
68
  mUSDT: usdtTestnet,
71
69
  mxSolvBTC: xsolvbtcTestnet,
72
70
  MUSD: musdTestnet,
73
- MEZO: mezoArtifact,
74
71
  } as unknown as ContractsMap<MezoChainToken>
75
72
 
76
73
  export const mainnetTokenContracts = {
@@ -85,7 +82,6 @@ export const mainnetTokenContracts = {
85
82
  mUSDT: usdtMainnet,
86
83
  mxSolvBTC: xsolvbtcMainnet,
87
84
  MUSD: musdMainnet,
88
- MEZO: mezoArtifact,
89
85
  } as unknown as ContractsMap<MezoChainToken>
90
86
 
91
87
  export const mainnetBorrowContracts = {
@@ -3,6 +3,7 @@ import { create } from "zustand"
3
3
  export enum DropdownView {
4
4
  ROOT = "ROOT",
5
5
  RECEIVE = "RECEIVE",
6
+ SETTINGS = "SETTINGS",
6
7
  }
7
8
 
8
9
  interface DropdownStore {