Skip to content

Commit

Permalink
Merge pull request #988 from multiversx/development
Browse files Browse the repository at this point in the history
2.25.0
  • Loading branch information
razvantomegea authored Dec 14, 2023
2 parents 82f386a + df97163 commit 10618f4
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 199 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [[v2.25.0]](https://github.com/multiversx/mx-sdk-dapp/pull/988)] - 2023-12-14

- [Added latest `axios` version](https://github.com/multiversx/mx-sdk-dapp/pull/989)
- [Prevent redirect on logout if `callbackURL` is the current URL](https://github.com/multiversx/mx-sdk-dapp/pull/987)
- [Fix sign message with web wallet provider](https://github.com/multiversx/mx-sdk-dapp/pull/985)
- [Fix typo in AxiosInterceptor](https://github.com/multiversx/mx-sdk-dapp/pull/984)

## [[v2.24.4]](https://github.com/multiversx/mx-sdk-dapp/pull/983)] - 2023-12-11

- [Add entire dappConfig into redux store](https://github.com/multiversx/mx-sdk-dapp/pull/982)
- [Fix CSS injection on SSR/Client side](https://github.com/multiversx/mx-sdk-dapp/pull/981)

## [[v2.24.3]](https://github.com/multiversx/mx-sdk-dapp/pull/979)] - 2023-11-29

- [Removed `senderUsername` and `receiverUsername` for `SetGuardian` tx](https://github.com/multiversx/mx-sdk-dapp/pull/978)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-dapp",
"version": "2.24.4",
"version": "2.25.0",
"description": "A library to hold the main logic for a dapp on the MultiversX blockchain",
"author": "MultiversX",
"license": "GPL-3.0-or-later",
Expand Down Expand Up @@ -153,7 +153,7 @@
"@multiversx/sdk-wallet-connect-provider": "4.0.4",
"@multiversx/sdk-web-wallet-provider": "3.1.0",
"@reduxjs/toolkit": "1.8.2",
"axios": "0.24.0",
"axios": "1.6.2",
"bignumber.js": "9.x",
"linkify-react": "4.0.2",
"linkifyjs": "4.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ export const invokeSendTransactions = async ({
const transactionsToSend = transactions.map((tx) => newTransaction(tx));
return await sendSignedTransactionsAsync(transactionsToSend);
} catch (error) {
const responseData = <{ message: string }>(
(error as AxiosError).response?.data
);

handleSendTransactionsErrors({
errorMessage:
(error as AxiosError).response?.data?.message ?? (error as any).message,
errorMessage: responseData?.message ?? (error as any).message,
sessionId,
clearSignInfo
});
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/signMessage/useSignMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export const useSignMessage = () => {
// Message was signed successfully
dispatch(
setSignSession({
sessionId: currentSessionId,
sessionId,
signedSession: {
signature,
status
Expand Down
5 changes: 4 additions & 1 deletion src/reduxStore/slices/signedMessageInfoSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export const signedMessageInfoSlice = createSlice({
state.isSigning =
signedSession.status === SignedMessageStatusesEnum.pending;

state.signedSessions[sessionId] = signedSession;
state.signedSessions[sessionId] = {
...state.signedSessions[sessionId],
...signedSession
};
},
setSignSessionState: (
state: SignedMessageInfoStateType,
Expand Down
35 changes: 17 additions & 18 deletions src/utils/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { getAccountProvider, getProviderType } from 'providers';
import { logoutAction } from 'reduxStore/commonActions';
import { store } from 'reduxStore/store';
import { LoginMethodsEnum } from 'types';
import { getIsLoggedIn } from 'utils/getIsLoggedIn';
import { matchPath } from '../wrappers/AuthenticatedRoutesWrapper/helpers/matchPath';
import { getAddress, getWebviewToken } from './account';
import { preventRedirects, safeRedirect } from './redirect';
import { storage } from './storage';
import { localStorageKeys } from './storage/local';
import { addOriginToLocationPath } from './window';
import { addOriginToLocationPath, getWindowLocation } from './window';

const broadcastLogoutAcrossTabs = (address: string) => {
const storedData = storage.local.getItem(localStorageKeys.logoutEvent);
Expand All @@ -22,31 +22,23 @@ const broadcastLogoutAcrossTabs = (address: string) => {
data: address,
expires: 0
});

storage.local.removeItem(localStorageKeys.logoutEvent);
};

export async function logout(
callbackUrl?: string,
onRedirect?: (callbackUrl?: string) => void,
shouldAttemptRelogin = Boolean(getWebviewToken())
shouldAttemptReLogin = Boolean(getWebviewToken())
) {
const isLoggedIn = getIsLoggedIn();
const provider = getAccountProvider();
const providerType = getProviderType(provider);
const isWalletProvider = providerType === LoginMethodsEnum.wallet;

if (shouldAttemptRelogin && provider?.relogin != null) {
if (shouldAttemptReLogin && provider?.relogin != null) {
return await provider.relogin();
}

if (isWalletProvider) {
if (!isLoggedIn) {
return;
}

preventRedirects();
}

const url = addOriginToLocationPath(callbackUrl);
store.dispatch(logoutAction());

Expand All @@ -55,10 +47,18 @@ export async function logout(
broadcastLogoutAcrossTabs(address);
} catch (err) {
console.error('error fetching logout address', err);
return redirectToCallbackUrl(url, onRedirect);
}

if (!provider || providerType === LoginMethodsEnum.none) {
const location = getWindowLocation();
const callbackPathname = new URL(url).pathname;

// Prevent page redirect if
// the logout callbackURL is equal to the current URL
if (matchPath(location.pathname, callbackPathname)) {
preventRedirects();
}

if (!provider?.isInitialized?.()) {
return redirectToCallbackUrl(url, onRedirect);
}

Expand All @@ -76,10 +76,9 @@ export async function logout(

function redirectToCallbackUrl(
callbackUrl?: string,
onRedirect?: (callbackUrl?: string) => void,
isWalletProvider?: boolean
onRedirect?: (callbackUrl?: string) => void
) {
if (callbackUrl && !isWalletProvider) {
if (callbackUrl) {
if (typeof onRedirect === 'function') {
onRedirect(callbackUrl);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import axios from 'axios';
import { useAxiosInterceptorContext } from './AxiosInterceptorContextProvider';

export interface AxiosInterceptorType extends PropsWithChildren {
authenticatedDomanis: string[];
authenticatedDomains: string[];
}

export const AxiosInterceptor = ({
children,
authenticatedDomanis
authenticatedDomains
}: AxiosInterceptorType) => {
const { loginInfo } = useAxiosInterceptorContext();
const bearerToken = loginInfo?.tokenLogin?.nativeAuthToken;
Expand Down Expand Up @@ -37,10 +37,8 @@ export const AxiosInterceptor = ({

requestIdRef.current = axios.interceptors.request.use(
async (config) => {
if (authenticatedDomanis.includes(String(config?.baseURL))) {
config.headers = {
Authorization: `Bearer ${bearerToken}`
};
if (authenticatedDomains.includes(String(config?.baseURL))) {
config.headers.set('Authorization', `Bearer ${bearerToken}`);
}

return config;
Expand Down
Loading

0 comments on commit 10618f4

Please sign in to comment.