-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip crosswindow provider login * implement login with crosswindow provider, fix network config initialization and relogin * apply specific condition for crosswindow at the generic login * add todos * revert minification changes * fix todo * todo fix * changelog update * rebasing on top of development branch * cleanup * upgrade sdk=dapp-utils and cross-window-provider * 0.0.0-alpha.9
- Loading branch information
1 parent
a2aaf05
commit c912e08
Showing
42 changed files
with
354 additions
and
493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,64 @@ | ||
import { initStore } from 'store/store'; | ||
import { defaultStorageCallback, StorageCallback } from 'store/storage'; | ||
import { setTokenLoginNativeAuthTokenConfig } from 'store/actions/loginInfo/loginInfoActions'; | ||
import { setNativeAuthConfig } from 'store/actions/config/configActions'; | ||
import { initializeNetwork } from 'store/actions'; | ||
import { CustomNetworkType } from 'types/network.types'; | ||
import { EnvironmentsEnum } from 'types/enums.types'; | ||
import { NativeAuthConfigType } from 'services/nativeAuth/nativeAuth.types'; | ||
import { getDefaultNativeAuthConfig } from 'services/nativeAuth/methods/getDefaultNativeAuthConfig'; | ||
|
||
type InitAppType = { | ||
storage?: { | ||
getStorageCallback: StorageCallback; | ||
}; | ||
nativeAuth?: boolean | NativeAuthConfigType; | ||
dAppConfig?: { | ||
nativeAuth?: boolean | NativeAuthConfigType; | ||
network?: CustomNetworkType; | ||
environment?: EnvironmentsEnum; | ||
}; | ||
}; | ||
const defaultInitAppProps = { | ||
storage: { | ||
getStorageCallback: defaultStorageCallback | ||
} | ||
}; | ||
export const initializeDApp = (props?: InitAppType) => { | ||
const { storage, nativeAuth } = { ...defaultInitAppProps, ...props }; | ||
|
||
/** | ||
* Initializes the dApp with the given configuration. | ||
* @param props - The configuration for the dApp initialization. | ||
* @param props.storage - The storage configuration for the dApp. | ||
* @param props.storage.getStorageCallback - The callback to get the storage (custom storage). | ||
* @param props.nativeAuth - The native auth configuration for the dApp. | ||
* @param props.nativeAuth - If set to `true`, will fallback on default configuration. | ||
* @param props.nativeAuth - If set to `false`, will disable native auth. | ||
* @param props.nativeAuth - If set to `NativeAuthConfigType`, will set the native auth configuration. | ||
* | ||
* !!! Avoid changing the configuration during the dApp lifecycle. | ||
* | ||
* @example | ||
* ```ts | ||
* initializeDApp({ | ||
* nativeAuth: true | ||
* }); | ||
* ``` | ||
* */ | ||
export const initializeDApp = async (props?: InitAppType) => { | ||
const { storage, dAppConfig } = { ...defaultInitAppProps, ...props }; | ||
initStore(storage.getStorageCallback); | ||
|
||
if (nativeAuth) { | ||
if (dAppConfig?.nativeAuth) { | ||
const nativeAuthConfig: NativeAuthConfigType = | ||
typeof nativeAuth === 'boolean' | ||
typeof dAppConfig.nativeAuth === 'boolean' | ||
? getDefaultNativeAuthConfig() | ||
: nativeAuth; | ||
: dAppConfig.nativeAuth; | ||
|
||
setNativeAuthConfig(nativeAuthConfig); | ||
} | ||
|
||
setTokenLoginNativeAuthTokenConfig(nativeAuthConfig); | ||
if (dAppConfig?.network) { | ||
await initializeNetwork({ | ||
customNetworkConfig: dAppConfig.network, | ||
environment: dAppConfig.environment ?? EnvironmentsEnum.devnet | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getWindowLocation } from 'utils/window/getWindowLocation'; | ||
|
||
export function getCallbackUrl() { | ||
const { origin, pathname } = getWindowLocation(); | ||
return encodeURIComponent(`${origin}${pathname}`); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/core/methods/login/helpers/getImpersonatedAccountDetails.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { getAccount } from 'utils/account/getAccount'; | ||
import { getModifiedLoginToken } from './getModifiedLoginToken'; | ||
|
||
interface GetImpersonatedAccountDetailsType { | ||
address: string; | ||
originalLoginToken?: string; | ||
extraInfoData: { | ||
multisig?: string; | ||
impersonate?: string; | ||
}; | ||
} | ||
|
||
export const getImpersonatedAccountDetails = async ({ | ||
originalLoginToken, | ||
extraInfoData, | ||
address | ||
}: GetImpersonatedAccountDetailsType) => { | ||
const modifiedLoginToken = await getModifiedLoginToken({ | ||
loginToken: originalLoginToken, | ||
extraInfoData | ||
}); | ||
|
||
const tokenAddress = | ||
extraInfoData.multisig || extraInfoData.impersonate || address; | ||
|
||
const accountAddress = modifiedLoginToken != null ? tokenAddress : address; | ||
|
||
const account = await getAccount(accountAddress); | ||
|
||
return { | ||
account, | ||
address: accountAddress, | ||
modifiedLoginToken | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { setAccount } from 'store/actions/account'; | ||
import { setLoginToken } from 'store/actions/loginInfo/loginInfoActions'; | ||
import { IProvider } from 'core/providers/types/providerFactory.types'; | ||
import { loginAction } from 'store/actions'; | ||
import { AccountType } from 'types/account.types'; | ||
import { getImpersonatedAccountDetails } from './getImpersonatedAccountDetails'; | ||
import { getLatestNonce } from 'core/methods/account/getLatestNonce'; | ||
|
||
export async function impersonateAccount({ | ||
loginToken, | ||
extraInfoData, | ||
address, | ||
provider | ||
}: { | ||
loginToken: string; | ||
extraInfoData: { | ||
multisig?: string; | ||
impersonate?: string; | ||
}; | ||
address: string; | ||
provider: IProvider; | ||
}) { | ||
const impersonationDetails = await getImpersonatedAccountDetails({ | ||
originalLoginToken: loginToken, | ||
extraInfoData, | ||
address | ||
}); | ||
|
||
if (impersonationDetails.modifiedLoginToken) { | ||
setLoginToken(impersonationDetails.modifiedLoginToken); | ||
} | ||
|
||
if (impersonationDetails.account) { | ||
loginAction({ | ||
address: impersonationDetails.address, | ||
providerType: provider.getType() | ||
}); | ||
|
||
const newAccount: AccountType = { | ||
...impersonationDetails.account, | ||
nonce: getLatestNonce(impersonationDetails.account) | ||
}; | ||
|
||
setAccount(newAccount); | ||
return { | ||
...impersonationDetails, | ||
account: newAccount | ||
}; | ||
} | ||
|
||
return impersonationDetails; | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.