Skip to content

Commit

Permalink
[WC] Add waiting when signing transaction with WC
Browse files Browse the repository at this point in the history
  • Loading branch information
S2kael committed Nov 15, 2024
1 parent 77d8773 commit 97b8cf9
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ConfirmationDefinitions, ConfirmationResult, EvmSendTransactionRequest,
import { WC_DEFAULT_CHAIN_ID } from '@subwallet/extension-base/services/wallet-connect-service/constants';
import { CONFIRMATION_QR_MODAL } from '@subwallet/extension-koni-ui/constants/modal';
import { InjectContext } from '@subwallet/extension-koni-ui/contexts/InjectContext';
import { WalletConnectContext } from '@subwallet/extension-koni-ui/contexts/WalletConnectContext';
import { useGetChainInfoByChainId, useLedger, useNotification } from '@subwallet/extension-koni-ui/hooks';
import useUnlockChecker from '@subwallet/extension-koni-ui/hooks/common/useUnlockChecker';
import { completeConfirmation, wcSendTransactionRequest, wcSignMessageRequest } from '@subwallet/extension-koni-ui/messaging';
Expand Down Expand Up @@ -63,6 +64,7 @@ const Component: React.FC<Props> = (props: Props) => {
const notify = useNotification();

const { activeModal } = useContext(ModalContext);
const { waitingSigningModal: { close: closeWaiting, open: openWaiting } } = useContext(WalletConnectContext);
const { evmWallet } = useContext(InjectContext);

const chain = useGetChainInfoByChainId(chainId);
Expand Down Expand Up @@ -223,17 +225,25 @@ const Component: React.FC<Props> = (props: Props) => {
}

setLoading(true);
openWaiting();
promise
.then(({ signature }) => {
closeWaiting();
onApproveSignature({ signature: signature as `0x${string}` });
})
.catch((e) => {
console.error(e);
const error = e as Error;

closeWaiting();
notify({
message: error.message,
type: 'error'
});
})
.finally(() => {
setLoading(false);
});
}, [account.address, isMessage, onApproveSignature, payload, chainId]);
}, [isMessage, openWaiting, payload.payload, account.address, chainId, closeWaiting, onApproveSignature, notify]);

const onConfirm = useCallback(() => {
removeTransactionPersist(extrinsicType);
Expand Down
8 changes: 3 additions & 5 deletions packages/extension-koni-ui/src/Popup/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,9 @@ export function Root (): React.ReactElement {
return (
<SecurityContextProvider>
<WalletModalContextProvider>
<WalletConnectContextProvider>
<DefaultRoute>
<Outlet />
</DefaultRoute>
</WalletConnectContextProvider>
<DefaultRoute>
<Outlet />
</DefaultRoute>
</WalletModalContextProvider>
</SecurityContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Component (props: Props): React.ReactElement<Props> {
<SwModal
className={CN(className, '-light-theme')}
closable={false}
destroyOnClose={true}
id={modalId}
maskClosable={false}
title={t('Success')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useSelector } from 'react-redux';
import { useSearchParams } from 'react-router-dom';

import { UnlockModal } from '../components/Modal/UnlockModal';
import { WalletConnectContextProvider } from './WalletConnectContext';

interface Props {
children: React.ReactNode;
Expand Down Expand Up @@ -127,42 +128,46 @@ export const WalletModalContextProvider = ({ children }: Props) => {

// todo: will remove ClaimDappStakingRewardsModal after Astar upgrade to v3

return <WalletModalContext.Provider value={contextValue}>
<div
id='popup-container'
style={{ zIndex: hasActiveModal ? undefined : -1 }}
/>
{children}
<SwModal
className={'modal-full'}
closable={false}
destroyOnClose={true}
id={'confirmations'}
onCancel={onCloseModal}
transitionName={'fade'}
wrapClassName={CN({ 'd-none': !hasConfirmations })}
>
<Confirmations />
</SwModal>
<CreateAccountModal />
<RemindBackupSeedPhraseModal />
<ImportAccountModal />
<AttachAccountModal />
<NewSeedModal />
<ImportSeedModal />
<DeriveAccountModal />
<ClaimDappStakingRewardsModal />
<RequestCreatePasswordModal />
<RequestCameraAccessModal />
<CustomizeModal />
<UnlockModal />
{
!!leaderboardModalProps && (
<LeaderboardModal
{...leaderboardModalProps}
onCancel={closeLeaderboardModal}
return (
<WalletModalContext.Provider value={contextValue}>
<WalletConnectContextProvider>
<div
id='popup-container'
style={{ zIndex: hasActiveModal ? undefined : -1 }}
/>
)
}
</WalletModalContext.Provider>;
{children}
<SwModal
className={'modal-full'}
closable={false}
destroyOnClose={true}
id={'confirmations'}
onCancel={onCloseModal}
transitionName={'fade'}
wrapClassName={CN({ 'd-none': !hasConfirmations })}
>
<Confirmations />
</SwModal>
<CreateAccountModal />
<RemindBackupSeedPhraseModal />
<ImportAccountModal />
<AttachAccountModal />
<NewSeedModal />
<ImportSeedModal />
<DeriveAccountModal />
<ClaimDappStakingRewardsModal />
<RequestCreatePasswordModal />
<RequestCameraAccessModal />
<CustomizeModal />
<UnlockModal />
{
!!leaderboardModalProps && (
<LeaderboardModal
{...leaderboardModalProps}
onCancel={closeLeaderboardModal}
/>
)
}
</WalletConnectContextProvider>
</WalletModalContext.Provider>
);
};

0 comments on commit 97b8cf9

Please sign in to comment.