Skip to content

Commit

Permalink
Merge pull request #1010 from multiversx/ag-wc-custom-requests
Browse files Browse the repository at this point in the history
add custom request option for WC button/hook
  • Loading branch information
andreigiura authored Jan 5, 2024
2 parents 1518575 + c4fd4e1 commit ea709f4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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]
- [Add custom request option for WC button](https://github.com/multiversx/mx-sdk-dapp/pull/1010)

## [[v2.26.5]](https://github.com/multiversx/mx-sdk-dapp/pull/1009)] - 2024-01-04
- [Fixed provider initialised check](https://github.com/multiversx/mx-sdk-dapp/pull/1008)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const WalletConnectLoginButton = ({
showScamPhishingAlert,
title = 'Login with the xPortal App',
token,
wrapContentInsideModal = true
wrapContentInsideModal = true,
customRequestMethods = []
}: WalletConnectLoginButtonPropsType) => {
const {
disabledConnectButton,
Expand Down Expand Up @@ -84,6 +85,7 @@ export const WalletConnectLoginButton = ({
title={title}
token={token}
wrapContentInsideModal={wrapContentInsideModal}
customRequestMethods={customRequestMethods}
/>
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/UI/walletConnect/WalletConnectLoginButton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export interface WalletConnectLoginButtonPropsType
showScamPhishingAlert?: boolean;
title?: string;
wrapContentInsideModal?: boolean;
customRequestMethods?: Array<string>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const WalletConnectLoginContainerComponent = (
showLoginModal,
token,
wrapContentInsideModal,
styles
styles,
customRequestMethods
} = props;

const canLoginRef = useRef<boolean>(true);
Expand All @@ -30,7 +31,8 @@ const WalletConnectLoginContainerComponent = (
nativeAuth,
onLoginRedirect,
logoutRoute,
canLoginRef
canLoginRef,
customRequestMethods
});

const onCloseModal = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const WalletConnectLoginContentComponent = ({
token,
canLoginRef,
globalStyles,
styles
styles,
customRequestMethods = []
}: WalletConnectLoginModalPropsType & WithStylesImportType) => {
const [
initLoginWithWalletConnectV2,
Expand All @@ -47,7 +48,8 @@ const WalletConnectLoginContentComponent = ({
nativeAuth,
onLoginRedirect,
logoutRoute,
canLoginRef
canLoginRef,
customRequestMethods
});

const [qrCodeSvg, setQrCodeSvg] = useState<string>('');
Expand Down
1 change: 1 addition & 0 deletions src/UI/walletConnect/WalletConnectLoginContainer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export interface WalletConnectLoginModalPropsType
title?: string;
wrapContentInsideModal?: boolean;
canLoginRef?: MutableRefObject<boolean>;
customRequestMethods?: Array<string>;
}
7 changes: 5 additions & 2 deletions src/hooks/login/useWalletConnectV2Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export enum WalletConnectV2Error {
export interface InitWalletConnectV2Type extends OnProviderLoginType {
logoutRoute?: string;
canLoginRef?: MutableRefObject<boolean>;
customRequestMethods?: Array<string>;
}

export interface WalletConnectV2LoginHookCustomStateType {
Expand All @@ -68,7 +69,8 @@ export const useWalletConnectV2Login = ({
nativeAuth,
onLoginRedirect,
logoutRoute: providerLogoutRoute,
canLoginRef: parentCanLoginRef
canLoginRef: parentCanLoginRef,
customRequestMethods = []
}: InitWalletConnectV2Type): WalletConnectV2LoginHookReturnType => {
const dispatch = useDispatch();
const hasNativeAuth = nativeAuth != null;
Expand Down Expand Up @@ -97,7 +99,8 @@ export const useWalletConnectV2Login = ({

const logoutRoute = providerLogoutRoute ?? dappLogoutRoute ?? '/';
const dappMethods: string[] = [
WalletConnectOptionalMethodsEnum.CANCEL_ACTION
WalletConnectOptionalMethodsEnum.CANCEL_ACTION,
...customRequestMethods
];
if (tokenToSign) {
dappMethods.push(WalletConnectOptionalMethodsEnum.SIGN_LOGIN_TOKEN);
Expand Down

0 comments on commit ea709f4

Please sign in to comment.