@arthur2079/internal-profile 0.1.2-next.7 → 0.10.1-next.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.
- package/dist/api/errors.d.ts +3 -0
- package/dist/api/errors.js +9 -0
- package/dist/api/mod.d.ts +4 -0
- package/dist/api/mod.js +2 -0
- package/dist/api/request.d.ts +19 -0
- package/dist/api/request.js +96 -0
- package/dist/api/types.d.ts +193 -0
- package/dist/api/types.js +1 -0
- package/dist/components/ConnectWalletModal/ConnectWalletFooter.d.ts +5 -0
- package/dist/components/ConnectWalletModal/ConnectWalletFooter.js +9 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.constants.d.ts +5 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.constants.js +8 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.d.ts +3 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.helpers.d.ts +2 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.helpers.js +9 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.js +194 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.styles.d.ts +19 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.styles.js +101 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.types.d.ts +44 -0
- package/dist/components/ConnectWalletModal/ConnectWalletModal.types.js +1 -0
- package/dist/components/ConnectWalletModal/EmptyWalletList.d.ts +2 -0
- package/dist/components/ConnectWalletModal/EmptyWalletList.js +9 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.d.ts +3 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.js +37 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.styles.d.ts +1 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.styles.js +51 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.types.d.ts +12 -0
- package/dist/components/ConnectWalletModal/StatefulConnectContainer.types.js +1 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.d.ts +3 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.js +87 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.styles.d.ts +21 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.styles.js +83 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.types.d.ts +12 -0
- package/dist/components/ConnectWalletModal/WalletsChainSelect.types.js +1 -0
- package/dist/components/ConnectWalletModal/index.d.ts +3 -0
- package/dist/components/ConnectWalletModal/index.js +2 -0
- package/dist/components/ProfileWallet/ProfileWallet.d.ts +3 -0
- package/dist/components/ProfileWallet/ProfileWallet.js +54 -0
- package/dist/components/ProfileWallet/ProfileWallet.styles.d.ts +6 -0
- package/dist/components/ProfileWallet/ProfileWallet.styles.js +54 -0
- package/dist/components/ProfileWallet/ProfileWallet.types.d.ts +11 -0
- package/dist/components/ProfileWallet/ProfileWallet.types.js +1 -0
- package/dist/components/ProfileWallet/index.d.ts +1 -0
- package/dist/components/ProfileWallet/index.js +1 -0
- package/dist/components/ProfileWallets/ConnectedWallets.d.ts +2 -0
- package/dist/components/ProfileWallets/ConnectedWallets.js +25 -0
- package/dist/components/ProfileWallets/ConnectedWallets.styles.d.ts +4 -0
- package/dist/components/ProfileWallets/ConnectedWallets.styles.js +30 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.d.ts +5 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.js +9 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.styles.d.ts +1 -0
- package/dist/components/ProfileWallets/ConnectedWalletsEmptyState.styles.js +8 -0
- package/dist/components/ProfileWallets/ProfileWallets.d.ts +4 -0
- package/dist/components/ProfileWallets/ProfileWallets.js +37 -0
- package/dist/components/ProfileWallets/ProfileWallets.styles.d.ts +5 -0
- package/dist/components/ProfileWallets/ProfileWallets.styles.js +17 -0
- package/dist/components/ProfileWallets/ProfileWallets.types.d.ts +14 -0
- package/dist/components/ProfileWallets/ProfileWallets.types.js +1 -0
- package/dist/components/ProfileWallets/index.d.ts +1 -0
- package/dist/components/ProfileWallets/index.js +1 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.constants.d.ts +3 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.constants.js +2 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.d.ts +3 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.js +23 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.styles.d.ts +4 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.styles.js +23 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.types.d.ts +23 -0
- package/dist/components/ProfileWalletsModal/ProfileWalletsModal.types.js +1 -0
- package/dist/components/ProfileWalletsModal/index.d.ts +2 -0
- package/dist/components/ProfileWalletsModal/index.js +1 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.d.ts +2 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.js +21 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.styles.d.ts +4 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.styles.js +49 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.types.d.ts +7 -0
- package/dist/components/SocialWalletIntroModal/SocialWalletIntroModal.types.js +1 -0
- package/dist/components/SocialWalletIntroModal/index.d.ts +1 -0
- package/dist/components/SocialWalletIntroModal/index.js +1 -0
- package/dist/components/StackModal/ModalContainer.d.ts +4 -0
- package/dist/components/StackModal/ModalContainer.js +33 -0
- package/dist/components/StackModal/ModalContainer.types.d.ts +6 -0
- package/dist/components/StackModal/ModalContainer.types.js +1 -0
- package/dist/components/StackModal/StackModal.d.ts +3 -0
- package/dist/components/StackModal/StackModal.js +90 -0
- package/dist/components/StackModal/StackModal.styles.d.ts +2 -0
- package/dist/components/StackModal/StackModal.styles.js +77 -0
- package/dist/components/StackModal/StackModal.types.d.ts +3 -0
- package/dist/components/StackModal/StackModal.types.js +1 -0
- package/dist/components/StackModal/index.d.ts +1 -0
- package/dist/components/StackModal/index.js +1 -0
- package/dist/components/WalletItem/WalletItem.d.ts +3 -0
- package/dist/components/WalletItem/WalletItem.js +60 -0
- package/dist/components/WalletItem/WalletItem.styles.d.ts +9 -0
- package/dist/components/WalletItem/WalletItem.styles.js +71 -0
- package/dist/components/WalletItem/WalletItem.types.d.ts +8 -0
- package/dist/components/WalletItem/WalletItem.types.js +1 -0
- package/dist/components/WalletItem/index.d.ts +1 -0
- package/dist/components/WalletItem/index.js +1 -0
- package/dist/components/mod.d.ts +5 -0
- package/dist/components/mod.js +3 -0
- package/dist/constants/errors.d.ts +1 -0
- package/dist/constants/errors.js +1 -0
- package/dist/constants/events.d.ts +3 -0
- package/dist/constants/events.js +3 -0
- package/dist/constants/links.d.ts +2 -0
- package/dist/constants/links.js +2 -0
- package/dist/constants/mod.d.ts +3 -0
- package/dist/constants/mod.js +3 -0
- package/dist/constants/modals.d.ts +3 -0
- package/dist/constants/modals.js +3 -0
- package/dist/fetcher.d.ts +3 -0
- package/dist/fetcher.js +10 -0
- package/dist/hooks/mod.d.ts +4 -0
- package/dist/hooks/mod.js +3 -0
- package/dist/hooks/useLocalStorage/index.d.ts +1 -0
- package/dist/hooks/useLocalStorage/index.js +1 -0
- package/dist/hooks/useLocalStorage/useLocalStorage.d.ts +1 -0
- package/dist/hooks/useLocalStorage/useLocalStorage.js +24 -0
- package/dist/hooks/useProfile/index.d.ts +1 -0
- package/dist/hooks/useProfile/index.js +1 -0
- package/dist/hooks/useProfile/useProfile.constants.d.ts +2 -0
- package/dist/hooks/useProfile/useProfile.constants.js +8 -0
- package/dist/hooks/useProfile/useProfile.d.ts +2 -0
- package/dist/hooks/useProfile/useProfile.helpers.d.ts +4 -0
- package/dist/hooks/useProfile/useProfile.helpers.js +3 -0
- package/dist/hooks/useProfile/useProfile.js +20 -0
- package/dist/hooks/useProfile/useProfile.types.d.ts +11 -0
- package/dist/hooks/useProfile/useProfile.types.js +1 -0
- package/dist/hooks/useStackModal.d.ts +38 -0
- package/dist/hooks/useStackModal.js +61 -0
- package/dist/hooks/useStatefulConnect.d.ts +7 -0
- package/dist/hooks/useStatefulConnect.js +15 -0
- package/dist/mod.d.ts +1 -0
- package/dist/mod.js +1 -0
- package/dist/store/helpers.d.ts +9 -0
- package/dist/store/helpers.js +69 -0
- package/dist/store/middlewares.d.ts +6 -0
- package/dist/store/middlewares.js +40 -0
- package/dist/store/mod.d.ts +4 -0
- package/dist/store/mod.js +3 -0
- package/dist/store/selectors.d.ts +47 -0
- package/dist/store/selectors.js +21 -0
- package/dist/store/slice.d.ts +134 -0
- package/dist/store/slice.js +230 -0
- package/dist/store/thunks.d.ts +153 -0
- package/dist/store/thunks.js +223 -0
- package/dist/store/types.d.ts +67 -0
- package/dist/store/types.js +1 -0
- package/dist/store/utils.d.ts +1 -0
- package/dist/store/utils.js +11 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +1 -0
- package/dist/utils/mod.d.ts +1 -0
- package/dist/utils/mod.js +1 -0
- package/dist/utils/wallets.d.ts +16 -0
- package/dist/utils/wallets.js +34 -0
- package/package.json +7 -7
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { getLoginMessage, getMergeAccountMessage, getProfileDetails, getProfileLeaderboard, getProfileSummary, getPublicLeaderboard, getPublicProfileLeaderboard, getPublicProfileSummary, getSetClaimMessage, logIn, logOut, mergeAccount, setClaimWallet, updateProfileData, UserUnauthorizedError, } from '../api/mod';
|
|
4
|
+
import { extractPublickKeyFromCosmosInstance, getErrorMessage, throwIfAborted } from './helpers';
|
|
5
|
+
import { memoizeThunk } from './utils';
|
|
6
|
+
// To learn more about this pattern, check https://github.com/rango-exchange/app-v2/pull/281
|
|
7
|
+
export function createSignMessage() {
|
|
8
|
+
const actionType = 'profile/signMessage';
|
|
9
|
+
const signMessageThunk = memoizeThunk(actionType, () => createAsyncThunk(actionType, async (params, options) => {
|
|
10
|
+
const { rejectWithValue, getState, dispatch, signal } = options;
|
|
11
|
+
const { account, getSigners, callback, errorCallback } = params;
|
|
12
|
+
const { meta: { blockchains }, profile: { profileAuth, isLoggedIn }, } = getState();
|
|
13
|
+
const { numberOfRetries } = profileAuth;
|
|
14
|
+
throwIfAborted(signal);
|
|
15
|
+
const signer = await getSigners(account.walletType);
|
|
16
|
+
const blockchainMeta = blockchains.find((blockchain) => blockchain.name === account.blockchain);
|
|
17
|
+
if (!blockchainMeta) {
|
|
18
|
+
return rejectWithValue('Something went wrong. Please try again.');
|
|
19
|
+
}
|
|
20
|
+
let signAction;
|
|
21
|
+
let saveAction;
|
|
22
|
+
if (isLoggedIn) {
|
|
23
|
+
signAction = getMergeAccountMessage;
|
|
24
|
+
saveAction = mergeAccount;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
signAction = getLoginMessage;
|
|
28
|
+
saveAction = logIn;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
throwIfAborted(signal);
|
|
32
|
+
const pubKeyBase64 = await extractPublickKeyFromCosmosInstance(account.walletType, {
|
|
33
|
+
blockchainMeta,
|
|
34
|
+
});
|
|
35
|
+
const { message, messageId } = await signAction({
|
|
36
|
+
address: account.address,
|
|
37
|
+
blockchain: account.blockchain,
|
|
38
|
+
pubKeyBase64,
|
|
39
|
+
}, signal);
|
|
40
|
+
throwIfAborted(signal);
|
|
41
|
+
const signature = await signer
|
|
42
|
+
.getSigner(blockchainMeta.type)
|
|
43
|
+
.signMessage(message, account.address, blockchainMeta.chainId);
|
|
44
|
+
throwIfAborted(signal);
|
|
45
|
+
const { profile } = await saveAction({ messageId, signature, pubKeyBase64 }, signal);
|
|
46
|
+
if (profile) {
|
|
47
|
+
callback?.(profile, { actionType: isLoggedIn ? 'merge' : 'login' });
|
|
48
|
+
}
|
|
49
|
+
return profile;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
if (signal.aborted || axios.isCancel(error)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const shouldLogOutAndRetry = !isLoggedIn && error instanceof UserUnauthorizedError && numberOfRetries === 0;
|
|
56
|
+
if (shouldLogOutAndRetry) {
|
|
57
|
+
await logOut(signal);
|
|
58
|
+
// Use a timeout to dispatch signMessage after incrementing the numberOfRetries.
|
|
59
|
+
setTimeout(async () => dispatch(signMessageThunk()(params)), 0);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
errorCallback?.(error);
|
|
63
|
+
return rejectWithValue(getErrorMessage(error));
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
return signMessageThunk();
|
|
67
|
+
}
|
|
68
|
+
export function createFetchProfileSummary() {
|
|
69
|
+
const actionType = 'profile/fetchProfileSummary';
|
|
70
|
+
const fetchProfileSummaryThunk = memoizeThunk(actionType, () => createAsyncThunk(actionType, async (params, options) => {
|
|
71
|
+
const { rejectWithValue, signal, getState, fulfillWithValue, dispatch } = options;
|
|
72
|
+
const state = getState().profile;
|
|
73
|
+
const publicProfile = params.public ||
|
|
74
|
+
!state.isLoggedIn ||
|
|
75
|
+
(state.isLoggedIn && state.username !== params.username);
|
|
76
|
+
const request = publicProfile
|
|
77
|
+
? getPublicProfileSummary.bind(null, params.username)
|
|
78
|
+
: getProfileSummary;
|
|
79
|
+
try {
|
|
80
|
+
const profileSummary = await request(signal);
|
|
81
|
+
return fulfillWithValue(profileSummary.profile);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
if (error instanceof UserUnauthorizedError) {
|
|
85
|
+
dispatch(fetchProfileSummaryThunk()({ username: params.username, public: true }));
|
|
86
|
+
return rejectWithValue(null);
|
|
87
|
+
}
|
|
88
|
+
return rejectWithValue(getErrorMessage(error));
|
|
89
|
+
}
|
|
90
|
+
}));
|
|
91
|
+
return fetchProfileSummaryThunk();
|
|
92
|
+
}
|
|
93
|
+
export function createSetClaim() {
|
|
94
|
+
const actionType = 'profile/setClaim';
|
|
95
|
+
const setClaimThunk = memoizeThunk(actionType, () => createAsyncThunk(actionType, async (params, options) => {
|
|
96
|
+
const { rejectWithValue, getState, dispatch, signal } = options;
|
|
97
|
+
const { account, getSigners } = params;
|
|
98
|
+
const { meta: { blockchains }, } = getState();
|
|
99
|
+
throwIfAborted(signal);
|
|
100
|
+
const signer = await getSigners(account.walletType);
|
|
101
|
+
const blockchainMeta = blockchains.find((blockchain) => blockchain.name === account.blockchain);
|
|
102
|
+
if (!blockchainMeta) {
|
|
103
|
+
return rejectWithValue(`We couldn't find ${account.blockchain} in our initial data. Please try again.`);
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
throwIfAborted(signal);
|
|
107
|
+
const { message, messageId } = await getSetClaimMessage({
|
|
108
|
+
address: account.address,
|
|
109
|
+
blockchain: account.blockchain,
|
|
110
|
+
}, signal);
|
|
111
|
+
throwIfAborted(signal);
|
|
112
|
+
const signature = await signer
|
|
113
|
+
.getSigner(blockchainMeta.type)
|
|
114
|
+
.signMessage(message, account.address, blockchainMeta.chainId);
|
|
115
|
+
throwIfAborted(signal);
|
|
116
|
+
const { profile } = await setClaimWallet({ messageId, signature }, signal);
|
|
117
|
+
return profile;
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (signal.aborted || axios.isCancel(error)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return rejectWithValue(getErrorMessage(error));
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
return setClaimThunk();
|
|
127
|
+
}
|
|
128
|
+
export function createRequestLogOutUser() {
|
|
129
|
+
const actionType = 'profile/logOut';
|
|
130
|
+
const logOutThunk = memoizeThunk(actionType, () => createAsyncThunk(actionType, async (_, options) => {
|
|
131
|
+
const { rejectWithValue, signal } = options;
|
|
132
|
+
try {
|
|
133
|
+
await logOut(signal);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return rejectWithValue(getErrorMessage(error));
|
|
137
|
+
}
|
|
138
|
+
}));
|
|
139
|
+
return logOutThunk();
|
|
140
|
+
}
|
|
141
|
+
export function createProfileThunks() {
|
|
142
|
+
const fetchProfileDetails = createAsyncThunk('profile/fetchProfileDetails', async (_, options) => {
|
|
143
|
+
const { rejectWithValue, signal } = options;
|
|
144
|
+
try {
|
|
145
|
+
const profileDetails = await getProfileDetails(signal);
|
|
146
|
+
return profileDetails.profile;
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (error instanceof UserUnauthorizedError) {
|
|
150
|
+
return rejectWithValue(null);
|
|
151
|
+
}
|
|
152
|
+
return rejectWithValue(getErrorMessage(error));
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const fetchProfileLeaderboard = createAsyncThunk('profile/fetchProfileLeaderboard', async (params, options) => {
|
|
156
|
+
const { rejectWithValue, signal, getState, dispatch } = options;
|
|
157
|
+
const state = getState().profile;
|
|
158
|
+
const publicProfile = params.public ||
|
|
159
|
+
!state.isLoggedIn ||
|
|
160
|
+
(state.isLoggedIn && state.username !== params.username);
|
|
161
|
+
const request = publicProfile
|
|
162
|
+
? getPublicProfileLeaderboard.bind(null, params.username)
|
|
163
|
+
: getProfileLeaderboard;
|
|
164
|
+
try {
|
|
165
|
+
const profileLeaderboard = await request(signal);
|
|
166
|
+
return profileLeaderboard.data;
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
if (error instanceof UserUnauthorizedError) {
|
|
170
|
+
dispatch(fetchProfileLeaderboard({ username: params.username, public: true }));
|
|
171
|
+
return rejectWithValue(null);
|
|
172
|
+
}
|
|
173
|
+
return rejectWithValue(getErrorMessage(error));
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const fetchPublicLeaderboard = createAsyncThunk('profile/fetchPublicLeaderboard', async (params, options) => {
|
|
177
|
+
const { rejectWithValue, signal } = options;
|
|
178
|
+
try {
|
|
179
|
+
const leaderboard = await getPublicLeaderboard(params, signal);
|
|
180
|
+
return { leaderboard: leaderboard.data, totalPages: leaderboard.totalPages };
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
return rejectWithValue(getErrorMessage(error));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const fetchTopPublicLeaderboard = createAsyncThunk('profile/fetchTopPublicLeaderboard', async (params, options) => {
|
|
187
|
+
const { rejectWithValue, signal } = options;
|
|
188
|
+
try {
|
|
189
|
+
const leaderboard = await getPublicLeaderboard({ type: params.type, page: 0, offset: 10 }, signal);
|
|
190
|
+
return leaderboard.data;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
return rejectWithValue(getErrorMessage(error));
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
const updateUsername = createAsyncThunk('profile/updateUsername', async (params, options) => {
|
|
197
|
+
const { rejectWithValue, signal } = options;
|
|
198
|
+
const { userName, callback } = params;
|
|
199
|
+
const DEFAULT_ERROR_MESSAGE = 'An error occurred while updating the username.';
|
|
200
|
+
try {
|
|
201
|
+
const result = await updateProfileData({ userName }, signal);
|
|
202
|
+
if (result.success) {
|
|
203
|
+
callback();
|
|
204
|
+
return { username: userName };
|
|
205
|
+
}
|
|
206
|
+
return rejectWithValue(DEFAULT_ERROR_MESSAGE);
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
return rejectWithValue(error instanceof Error ? error.message : DEFAULT_ERROR_MESSAGE);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
return {
|
|
213
|
+
signMessage: createSignMessage(),
|
|
214
|
+
fetchProfileSummary: createFetchProfileSummary(),
|
|
215
|
+
fetchProfileDetails,
|
|
216
|
+
fetchProfileLeaderboard,
|
|
217
|
+
fetchPublicLeaderboard,
|
|
218
|
+
fetchTopPublicLeaderboard,
|
|
219
|
+
updateUsername,
|
|
220
|
+
requestLogOutUser: createRequestLogOutUser(),
|
|
221
|
+
setClaim: createSetClaim(),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ProfileAccount, ProfileDetails, ProfileLeaderboard, ProfileSummary } from '../api/mod';
|
|
2
|
+
import type { useWallets } from '@rango-dev/widget-embedded';
|
|
3
|
+
type ProfileAuth = {
|
|
4
|
+
numberOfRetries: number;
|
|
5
|
+
accountMerged: boolean;
|
|
6
|
+
} & ({
|
|
7
|
+
loading: true;
|
|
8
|
+
error: null;
|
|
9
|
+
account: ProfileAccount;
|
|
10
|
+
accountMerged: false;
|
|
11
|
+
} | {
|
|
12
|
+
loading: false;
|
|
13
|
+
error: string | null;
|
|
14
|
+
account: null;
|
|
15
|
+
});
|
|
16
|
+
type ProfileSummaryState = {
|
|
17
|
+
loading: boolean;
|
|
18
|
+
error: string | null;
|
|
19
|
+
data: ProfileSummary | null;
|
|
20
|
+
};
|
|
21
|
+
export type ProfileState = {
|
|
22
|
+
isLoggedIn: boolean;
|
|
23
|
+
username: string | null;
|
|
24
|
+
profileAuth: ProfileAuth;
|
|
25
|
+
profileSummary: {
|
|
26
|
+
private: ProfileSummaryState;
|
|
27
|
+
public: ProfileSummaryState;
|
|
28
|
+
};
|
|
29
|
+
profileDetails: {
|
|
30
|
+
loading: boolean;
|
|
31
|
+
error: string | null;
|
|
32
|
+
data: ProfileDetails | null;
|
|
33
|
+
};
|
|
34
|
+
profileLeaderboard: {
|
|
35
|
+
loading: boolean;
|
|
36
|
+
error: string | null;
|
|
37
|
+
data: ProfileLeaderboard[] | null;
|
|
38
|
+
};
|
|
39
|
+
publicLeaderboard: {
|
|
40
|
+
loading: boolean;
|
|
41
|
+
error: string | null;
|
|
42
|
+
totalPages: number | null;
|
|
43
|
+
data: ProfileLeaderboard[] | null;
|
|
44
|
+
};
|
|
45
|
+
topPublicLeaderboard: {
|
|
46
|
+
loading: boolean;
|
|
47
|
+
error: string | null;
|
|
48
|
+
data: ProfileLeaderboard[] | null;
|
|
49
|
+
};
|
|
50
|
+
updateUsername: {
|
|
51
|
+
loading: boolean;
|
|
52
|
+
error: string | null;
|
|
53
|
+
};
|
|
54
|
+
logOut: {
|
|
55
|
+
loading: boolean;
|
|
56
|
+
error: string | null;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type SignMessageParams = {
|
|
60
|
+
account: ProfileAccount;
|
|
61
|
+
getSigners: ReturnType<typeof useWallets>['getSigners'];
|
|
62
|
+
callback?: (profileSummary: ProfileSummary, meta: {
|
|
63
|
+
actionType: 'login' | 'merge';
|
|
64
|
+
}) => void;
|
|
65
|
+
errorCallback?: (error: unknown) => void;
|
|
66
|
+
};
|
|
67
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function memoizeThunk<Result>(key: string, callback: () => Result): () => Result;
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { walletAndSupportedChainsNames, getAddedAccountsToProfile, getConciseAddress, } from './wallets';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { walletAndSupportedChainsNames, getAddedAccountsToProfile, getConciseAddress, } from './wallets';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProfileSummary } from '../api/mod';
|
|
2
|
+
import type { Networks, WalletInfoWithExtra } from '@rango-dev/widget-embedded';
|
|
3
|
+
import type { BlockchainMeta } from 'rango-types';
|
|
4
|
+
export type ExtendedModalWalletInfo = WalletInfoWithExtra & {
|
|
5
|
+
isHub?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function walletAndSupportedChainsNames(supportedChains: BlockchainMeta[]): Networks[] | null;
|
|
8
|
+
export declare function checkIsWalletPartiallyConnected(wallet: ExtendedModalWalletInfo, namespacesState?: Map<string, {
|
|
9
|
+
connected: boolean;
|
|
10
|
+
}>): boolean;
|
|
11
|
+
export declare function getAddedAccountsToProfile(profileSummary: ProfileSummary): {
|
|
12
|
+
address: string;
|
|
13
|
+
blockchain: string;
|
|
14
|
+
walletType: null;
|
|
15
|
+
}[];
|
|
16
|
+
export declare const getConciseAddress: (address: string | null, maxChars?: number) => string | null;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function walletAndSupportedChainsNames(supportedChains) {
|
|
2
|
+
if (!supportedChains) {
|
|
3
|
+
return null;
|
|
4
|
+
}
|
|
5
|
+
let walletAndSupportedChainsNames = [];
|
|
6
|
+
walletAndSupportedChainsNames = supportedChains.map((blockchainMeta) => blockchainMeta.name);
|
|
7
|
+
return walletAndSupportedChainsNames;
|
|
8
|
+
}
|
|
9
|
+
export function checkIsWalletPartiallyConnected(wallet, namespacesState) {
|
|
10
|
+
if (!wallet.isHub || !wallet.needsNamespace || wallet.state !== 'connected') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const namespaces = wallet.needsNamespace.data;
|
|
14
|
+
const supportedNamespaces = namespaces.filter((namespace) => !namespace.unsupported);
|
|
15
|
+
return supportedNamespaces.some((namespace) => !namespacesState?.get(namespace.value)?.connected);
|
|
16
|
+
}
|
|
17
|
+
export function getAddedAccountsToProfile(profileSummary) {
|
|
18
|
+
return profileSummary.wallets.map((account) => ({
|
|
19
|
+
address: account.address,
|
|
20
|
+
blockchain: account.blockchain,
|
|
21
|
+
walletType: null,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
25
|
+
export const getConciseAddress = (address, maxChars = 6) => {
|
|
26
|
+
if (address === undefined || address === null) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
30
|
+
if (address.length < 2 * maxChars + 3) {
|
|
31
|
+
return address;
|
|
32
|
+
}
|
|
33
|
+
return address.substr(0, maxChars) + '...' + address.substr(address.length - maxChars);
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arthur2079/internal-profile",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.10.1-next.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
7
|
"exports": {
|
|
@@ -39,23 +39,23 @@
|
|
|
39
39
|
"dev": "tsc -p ./tsconfig.json --watch"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@arthur2079/internal-social-wallet": "^0.
|
|
43
|
-
"@rango-dev/widget-embedded": "^0.
|
|
42
|
+
"@arthur2079/internal-social-wallet": "^0.10.1-next.1",
|
|
43
|
+
"@rango-dev/widget-embedded": "^0.60.1",
|
|
44
44
|
"@reduxjs/toolkit": "^1.6.0",
|
|
45
45
|
"@types/node": "^14.14.31",
|
|
46
46
|
"@types/react": "^18.0.26",
|
|
47
47
|
"@types/react-dom": "^18.0.10",
|
|
48
48
|
"axios": "^1.16.0",
|
|
49
49
|
"immer": "*",
|
|
50
|
-
"rango-types": "^0.
|
|
50
|
+
"rango-types": "^0.5.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@arthur2079/internal-social-wallet": "^0.
|
|
54
|
-
"@rango-dev/widget-embedded": "^0.
|
|
53
|
+
"@arthur2079/internal-social-wallet": "^0.10.1-next.1",
|
|
54
|
+
"@rango-dev/widget-embedded": "^0.60.1",
|
|
55
55
|
"@reduxjs/toolkit": "^1.6.0",
|
|
56
56
|
"axios": "^1.16.0",
|
|
57
57
|
"immer": "*",
|
|
58
|
-
"rango-types": "^0.
|
|
58
|
+
"rango-types": "^0.5.0"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public",
|