Skip to content
This repository was archived by the owner on Oct 19, 2023. It is now read-only.

Commit b3fb28e

Browse files
authored
Merge pull request #289 from nevermined-io/feat/set-user-state-no-login
add new state notSigned
2 parents 98af18d + 2220b6e commit b3fb28e

File tree

7 files changed

+1148
-490
lines changed

7 files changed

+1148
-490
lines changed

catalog/CHANGELOG.md

Lines changed: 789 additions & 0 deletions
Large diffs are not rendered by default.

catalog/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@nevermined-io/catalog",
3-
"version": "1.3.8",
3+
"version": "1.4.0",
44
"main": "./dist/index.js",
55
"types": "./dist/index.d.ts",
66
"dependencies": {
7-
"@nevermined-io/sdk-dtp": "^0.4.7",
8-
"@nevermined-io/sdk": "^1.3.6",
7+
"@nevermined-io/sdk-dtp": "^0.4.8",
8+
"@nevermined-io/sdk": "^1.3.7",
99
"@types/jsonwebtoken": "^8.5.8",
1010
"axios": "^0.27.2",
1111
"axios-retry": "^3.3.1",

catalog/src/services/account.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export const useUserProfile = (
313313
/** Submit user profile */
314314
submitUserProfile: () => Promise<void>
315315
/** Indicates current user profile loading status */
316-
userProfileLoadingStatus: null | 'loading' | 'loaded' | 'failed'
316+
userProfileLoadingStatus: null | 'loading' | 'loaded' | 'failed' | 'notSigned'
317317
/** Reload current user profile */
318318
reloadUserProfile: () => void
319319
} => {
@@ -325,7 +325,7 @@ export const useUserProfile = (
325325
const [isAddressAdded, setIsAddressAdded] = useState(false)
326326
const [isTokenGenerated, setIsTokenGenerated] = useState(false)
327327
const [userProfileLoadingStatus, setUserProfileLoadingStatus] = useState<
328-
null | 'loading' | 'loaded' | 'failed'
328+
null | 'loading' | 'loaded' | 'failed' | 'notSigned'
329329
>(null)
330330

331331
const [userId, setUserId] = useState('')
@@ -343,14 +343,17 @@ export const useUserProfile = (
343343
const [reloadTrigger, setReloadTrigger] = useState<Date>()
344344

345345
const checkAuth = async () => {
346+
let tokenObject = { token: '' }
346347
if (!account.isTokenValid()) {
347348
setIsTokenGenerated(false)
348349
setErrorMessage(
349350
'Your login is expired. Please first sign with your wallet before to continue',
350351
)
351-
await account.generateToken()
352-
setIsTokenGenerated(true)
352+
tokenObject = await account.generateToken()
353+
setIsTokenGenerated(Boolean(tokenObject.token))
353354
}
355+
356+
return tokenObject.token
354357
}
355358

356359
const addAddress = async () => {
@@ -425,7 +428,7 @@ export const useUserProfile = (
425428
setNewAddress('')
426429
}
427430

428-
await checkAuth()
431+
const tokenAuth = await checkAuth()
429432

430433
setAddresses([...userProfileData.addresses])
431434

@@ -439,7 +442,7 @@ export const useUserProfile = (
439442
additionalInformation: userProfileData.additionalInformation,
440443
})
441444

442-
setUserProfileLoadingStatus('loaded')
445+
setUserProfileLoadingStatus(tokenAuth ? 'loaded' : 'notSigned')
443446
} catch (error: any) {
444447
if (addresses?.length && !addresses.some((a) => a.toLowerCase() === walletAddress)) {
445448
setNewAddress(walletAddress)

providers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@nevermined-io/providers",
33
"private": false,
4-
"version": "1.3.8",
4+
"version": "1.4.0",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
77
"dependencies": {

providers/src/client.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'wagmi'
1212
import { Provider } from '@wagmi/core'
1313
import { ConnectKitProvider } from 'connectkit'
14-
import { ConnectKitProviderProps } from './types'
14+
import { ConnectKitProviderProps, DataStatus, ProviderStatus } from './types'
1515

1616
/**
1717
* This component is a layer of [Wagmi](https://wagmi.sh/docs/getting-started) and [ConnectKit](https://docs.family.co/connectkit)
@@ -38,6 +38,8 @@ export interface WalletProviderState {
3838
login: (connector: Connector<any, any, any>) => void // eslint-disable-line
3939
/** If chain is between the available networks supported */
4040
checkIsChainCorrect: () => boolean
41+
/** get data status including message*/
42+
dataStatus: DataStatus
4143
}
4244

4345
export const WalletContext = createContext({} as WalletProviderState)
@@ -55,27 +57,52 @@ export const ClientComp = ({
5557
}) => {
5658
const [walletAddress, setWalletAddress] = useState<string>('')
5759
const { address, status } = useAccount()
60+
const [dataStatus, setDataStatus] = useState<DataStatus>({} as DataStatus)
5861
const { connect, connectors } = useConnect({
5962
onError(error) {
63+
setDataStatus({
64+
message: error.message,
65+
status: ProviderStatus.ErrorConnect
66+
})
6067
console.error(`Error connect: ${error}`)
6168
},
6269
onSuccess(data) {
70+
setDataStatus({
71+
message: data,
72+
status: ProviderStatus.SuccessConnect
73+
})
6374
console.log(`Wallet is connected: ${data}`)
6475
},
6576
})
6677
const { disconnect } = useDisconnect({
6778
onError(error) {
79+
setDataStatus({
80+
message: error.message,
81+
status: ProviderStatus.ErrorDisconnect
82+
})
6883
console.error(`Error disconnect: ${error}`)
6984
},
70-
onSuccess() {
85+
onSuccess(data) {
86+
setDataStatus({
87+
message: data,
88+
status: ProviderStatus.SuccessDisconnect
89+
})
7190
console.log(`Wallet is disconnected`)
7291
},
7392
})
7493
const { switchNetwork } = useSwitchNetwork({
7594
onError(error) {
95+
setDataStatus({
96+
message: error.message,
97+
status: ProviderStatus.ErrorSwitchNetwork
98+
})
7699
console.error(`Error switch network: ${error}`)
77100
},
78101
onSuccess(data) {
102+
setDataStatus({
103+
message: data,
104+
status: ProviderStatus.SuccessSwitchNetwork
105+
})
79106
console.log(`New network is selected: ${data.name}`)
80107
},
81108
})
@@ -112,6 +139,7 @@ export const ClientComp = ({
112139
value={{
113140
client,
114141
walletAddress,
142+
dataStatus,
115143
login,
116144
getConnectors,
117145
logout,

providers/src/types.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,42 @@ import { ReactNode } from 'react'
22
import { Languages, Theme, Mode, CustomTheme, CustomAvatarProps } from 'connectkit/build/types'
33

44
export type ConnectKitOptions = {
5-
language?: Languages;
6-
hideTooltips?: boolean;
7-
hideQuestionMarkCTA?: boolean;
8-
hideNoWalletCTA?: boolean;
9-
walletConnectCTA?: 'modal' | 'link' | 'both';
10-
avoidLayoutShift?: boolean; // Avoids layout shift when the ConnectKit modal is open by adding padding to the body
11-
embedGoogleFonts?: boolean; // Automatically embeds Google Font of the current theme. Does not work with custom themes
12-
truncateLongENSAddress?: boolean;
13-
walletConnectName?: string;
14-
reducedMotion?: boolean;
15-
disclaimer?: ReactNode | string;
16-
bufferPolyfill?: boolean;
17-
customAvatar?: React.FC<CustomAvatarProps>;
18-
initialChainId?: number;
5+
language?: Languages
6+
hideTooltips?: boolean
7+
hideQuestionMarkCTA?: boolean
8+
hideNoWalletCTA?: boolean
9+
walletConnectCTA?: 'modal' | 'link' | 'both'
10+
avoidLayoutShift?: boolean // Avoids layout shift when the ConnectKit modal is open by adding padding to the body
11+
embedGoogleFonts?: boolean // Automatically embeds Google Font of the current theme. Does not work with custom themes
12+
truncateLongENSAddress?: boolean
13+
walletConnectName?: string
14+
reducedMotion?: boolean
15+
disclaimer?: ReactNode | string
16+
bufferPolyfill?: boolean
17+
customAvatar?: React.FC<CustomAvatarProps>
18+
initialChainId?: number
1919
}
2020

2121
export type ConnectKitProviderProps = {
22-
children?: React.ReactNode;
23-
theme?: Theme;
24-
mode?: Mode;
25-
customTheme?: CustomTheme;
26-
options?: ConnectKitOptions;
27-
}
22+
children?: React.ReactNode
23+
theme?: Theme
24+
mode?: Mode
25+
customTheme?: CustomTheme
26+
options?: ConnectKitOptions
27+
}
28+
29+
export enum ProviderStatus {
30+
SuccessConnect = 'SuccessConnect',
31+
ErrorConnect = 'ErrorConnect',
32+
SuccessDisconnect = 'SuccessDisconnect',
33+
ErrorDisconnect = 'ErrorDisconnect',
34+
SuccessSwitchNetwork = 'SuccessSwitchNetwork',
35+
ErrorSwitchNetwork = 'ErrorSwitchNetwork',
36+
SuccessWalletSign = 'SuccessWalletSign',
37+
ErrorWalletSign = 'ErrorWalletSign',
38+
}
39+
40+
export interface DataStatus {
41+
message: unknown
42+
status: ProviderStatus
43+
}

0 commit comments

Comments
 (0)