Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added devtools action names #74

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Added devtools action names](https://github.com/multiversx/mx-sdk-dapp-core/pull/74)
- [Added transaction display info support](https://github.com/multiversx/mx-sdk-dapp-core/pull/73)
- [Remove storage helpers](https://github.com/multiversx/mx-sdk-dapp-core/pull/72)

Expand Down
94 changes: 61 additions & 33 deletions src/store/actions/account/accountActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,36 @@ import { getStore } from 'store/store';
import { AccountType } from 'types/account.types';

export const setAddress = (address: string) =>
getStore().setState(({ account: state }) => {
state.address = address;
});
getStore().setState(
({ account: state }) => {
state.address = address;
},
false,
'setAddress'
);

export const setAccount = (account: AccountType) => {
getStore().setState(({ account: state }) => {
const isSameAddress = state.address === account.address;
state.accounts = {
[state.address]: isSameAddress ? account : emptyAccount
};
});
getStore().setState(
({ account: state }) => {
const isSameAddress = state.address === account.address;
state.accounts = {
[state.address]: isSameAddress ? account : emptyAccount
};
},
false,
'setAccount'
);
};

// TODO: check if needed
export const setLedgerAccount = (ledgerAccount: LedgerAccountType | null) =>
getStore().setState(({ account: state }) => {
state.ledgerAccount = ledgerAccount;
});
getStore().setState(
({ account: state }) => {
state.ledgerAccount = ledgerAccount;
},
false,
'setLedgerAccount'
);

// TODO: check if needed
export const updateLedgerAccount = ({
Expand All @@ -34,30 +46,46 @@ export const updateLedgerAccount = ({
index: LedgerAccountType['index'];
address: LedgerAccountType['address'];
}) =>
getStore().setState(({ account: state }) => {
if (state.ledgerAccount) {
state.ledgerAccount.address = address;
state.ledgerAccount.index = index;
}
});
getStore().setState(
({ account: state }) => {
if (state.ledgerAccount) {
state.ledgerAccount.address = address;
state.ledgerAccount.index = index;
}
},
false,
'updateLedgerAccount'
);

export const setWalletConnectAccount = (walletConnectAccount: string | null) =>
getStore().setState(({ account: state }) => {
state.walletConnectAccount = walletConnectAccount;
});
getStore().setState(
({ account: state }) => {
state.walletConnectAccount = walletConnectAccount;
},
false,
'setWalletConnectAccount'
);

export const setWebsocketEvent = (message: string) =>
getStore().setState(({ account: state }) => {
state.websocketEvent = {
timestamp: Date.now(),
message
};
});
getStore().setState(
({ account: state }) => {
state.websocketEvent = {
timestamp: Date.now(),
message
};
},
false,
'setWebsocketEvent'
);

export const setWebsocketBatchEvent = (data: BatchTransactionsWSResponseType) =>
getStore().setState(({ account: state }) => {
state.websocketBatchEvent = {
timestamp: Date.now(),
data
};
});
getStore().setState(
({ account: state }) => {
state.websocketBatchEvent = {
timestamp: Date.now(),
data
};
},
false,
'setWebsocketBatchEvent'
);
20 changes: 14 additions & 6 deletions src/store/actions/config/configActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ export const setNativeAuthConfig = (config: NativeAuthConfigType) =>
});

export const setWalletConnectConfig = (config: WalletConnectConfig) =>
getStore().setState(({ config: state }) => {
state.walletConnectConfig = config;
});
getStore().setState(
({ config: state }) => {
state.walletConnectConfig = config;
},
false,
'setWalletConnectConfig'
);

export const setCrossWindowConfig = (config: CrossWindowConfig) =>
getStore().setState(({ config: state }) => {
state.crossWindowConfig = config;
});
getStore().setState(
({ config: state }) => {
state.crossWindowConfig = config;
},
false,
'setCrossWindowConfig'
);
126 changes: 85 additions & 41 deletions src/store/actions/loginInfo/loginInfoActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,110 @@ import { TokenLoginType } from 'types/login.types';
export const setProviderType = <T extends ProviderTypeEnum = ProviderTypeEnum>(
providerType: T
) =>
getStore().setState(({ loginInfo: state }) => {
state.providerType = providerType;
});
getStore().setState(
({ loginInfo: state }) => {
state.providerType = providerType;
},
false,
'setProviderType'
);

export const setTokenLogin = (tokenLogin: TokenLoginType) =>
getStore().setState(({ loginInfo: state }) => {
state.tokenLogin = tokenLogin;
});
getStore().setState(
({ loginInfo: state }) => {
state.tokenLogin = tokenLogin;
},
false,
'setTokenLogin'
);

export const setLoginToken = (loginToken: string) =>
getStore().setState(({ loginInfo: state }) => {
if (state.tokenLogin != null) {
state.tokenLogin.loginToken = loginToken;
return;
}
state.tokenLogin = {
loginToken
};
});
getStore().setState(
({ loginInfo: state }) => {
if (state.tokenLogin != null) {
state.tokenLogin.loginToken = loginToken;
return;
}
state.tokenLogin = {
loginToken
};
},
false,
'setLoginToken'
);

export const setTokenLoginSignature = (signature: string) =>
getStore().setState(({ loginInfo: state }) => {
if (state?.tokenLogin != null) {
state.tokenLogin.signature = signature;
}
});
getStore().setState(
({ loginInfo: state }) => {
if (state?.tokenLogin != null) {
state.tokenLogin.signature = signature;
}
},
false,
'setTokenLoginSignature'
);

export const setWalletLogin = (walletLogin: LoginInfoType | null) =>
getStore().setState(({ loginInfo: state }) => {
state.walletLogin = walletLogin;
});
getStore().setState(
({ loginInfo: state }) => {
state.walletLogin = walletLogin;
},
false,
'setWalletLogin'
);

export const setWalletConnectLogin = (
walletConnectLogin: WalletConnectLoginType | null
) =>
getStore().setState(({ loginInfo: state }) => {
state.walletConnectLogin = walletConnectLogin;
});
getStore().setState(
({ loginInfo: state }) => {
state.walletConnectLogin = walletConnectLogin;
},
false,
'setWalletConnectLogin'
);

export const setLedgerLogin = (ledgerLogin: LedgerLoginType | null) =>
getStore().setState(({ loginInfo: state }) => {
state.ledgerLogin = ledgerLogin;
});
getStore().setState(
({ loginInfo: state }) => {
state.ledgerLogin = ledgerLogin;
},
false,
'setLedgerLogin'
);

export const setLogoutRoute = (logoutRoute: string | undefined) =>
getStore().setState(({ loginInfo: state }) => {
state.logoutRoute = logoutRoute;
});
getStore().setState(
({ loginInfo: state }) => {
state.logoutRoute = logoutRoute;
},
false,
'setLogoutRoute'
);

export const setIsWalletConnectV2Initialized = (isInitialized: boolean) =>
getStore().setState(({ loginInfo: state }) => {
state.isWalletConnectV2Initialized = isInitialized;
});
getStore().setState(
({ loginInfo: state }) => {
state.isWalletConnectV2Initialized = isInitialized;
},
false,
'setIsWalletConnectV2Initialized'
);

export const removeLoginExpiresAt = () =>
getStore().setState(({ loginInfo: state }) => {
state.loginExpiresAt = null;
});
getStore().setState(
({ loginInfo: state }) => {
state.loginExpiresAt = null;
},
false,
'removeLoginExpiresAt'
);

export const addLoginExpiresAt = (expiresAt: number) =>
getStore().setState(({ loginInfo: state }) => {
state.loginExpiresAt = expiresAt;
});
getStore().setState(
({ loginInfo: state }) => {
state.loginExpiresAt = expiresAt;
},
false,
'addLoginExpiresAt'
);
40 changes: 24 additions & 16 deletions src/store/actions/network/networkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@ import { NetworkType } from 'types/network.types';
import { getStore } from '../../store';

export const initializeNetworkConfig = (newNetwork: NetworkType) =>
getStore().setState(({ network: state }) => {
const walletConnectV2RelayAddress =
newNetwork.walletConnectV2RelayAddresses[
Math.floor(
Math.random() * newNetwork.walletConnectV2RelayAddresses.length
)
];
getStore().setState(
({ network: state }) => {
const walletConnectV2RelayAddress =
newNetwork.walletConnectV2RelayAddresses[
Math.floor(
Math.random() * newNetwork.walletConnectV2RelayAddresses.length
)
];

state.network = {
...state.network,
...newNetwork,
walletConnectV2RelayAddress
};
});
state.network = {
...state.network,
...newNetwork,
walletConnectV2RelayAddress
};
},
false,
'initializeNetworkConfig'
);

export const setCustomWalletAddress = (customWalletAddress: string) =>
getStore().setState(({ network: state }) => {
state.network.customWalletAddress = customWalletAddress;
});
getStore().setState(
({ network: state }) => {
state.network.customWalletAddress = customWalletAddress;
},
false,
'setCustomWalletAddress'
);

export { initializeNetwork } from './initializeNetwork';
18 changes: 11 additions & 7 deletions src/store/actions/sharedActions/sharedActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ export const loginAction = ({
address,
providerType
}: LoginActionPayloadType) => {
getStore().setState(({ account, loginInfo }) => {
account.address = address;
account.publicKey = new Address(address).hex();
getStore().setState(
({ account, loginInfo }) => {
account.address = address;
account.publicKey = new Address(address).hex();

if (loginInfo) {
loginInfo.providerType = providerType;
}
});
if (loginInfo) {
loginInfo.providerType = providerType;
}
},
false,
'loginAction'
);
};
Loading
Loading