Add support for rejecting transaction request (#119)

* Implement functionality to reject request

* Change button label
This commit is contained in:
Adwait Gharpure 2024-07-08 16:40:16 +05:30 committed by GitHub
parent 521776ea3e
commit c3f9f7c245
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@ import { getPathKey } from '../utils/misc';
import {
WalletConnectRequests,
approveWalletConnectRequest,
rejectWalletConnectRequest,
} from '../utils/wallet-connect/wallet-connect-requests';
import { web3wallet } from '../utils/wallet-connect/WalletConnectUtils';
import { MEMO } from './ApproveTransfer';
@ -95,9 +96,9 @@ const ApproveTransaction = ({ route }: ApproveTransactionProps) => {
setCosmosStargateClient(client);
} catch (error: any) {
setTxError(error.message);
setIsTxErrorDialogOpen(true);
const response = formatJsonRpcError(requestEventId, error.message);
await web3wallet!.respondSessionRequest({ topic, response });
setIsTxErrorDialogOpen(true);
}
};
@ -144,9 +145,9 @@ const ApproveTransaction = ({ route }: ApproveTransactionProps) => {
);
} catch (error: any) {
setTxError(error.message);
setIsTxErrorDialogOpen(true);
const response = formatJsonRpcError(requestEventId, error.message);
await web3wallet!.respondSessionRequest({ topic, response });
setIsTxErrorDialogOpen(true);
}
};
getCosmosGas();
@ -207,12 +208,22 @@ const ApproveTransaction = ({ route }: ApproveTransactionProps) => {
navigation.navigate('Laconic');
} catch (error: any) {
setTxError(error.message);
setIsTxErrorDialogOpen(true);
const response = formatJsonRpcError(requestEventId, error.message);
await web3wallet!.respondSessionRequest({ topic, response });
setIsTxErrorDialogOpen(true);
}
};
const rejectRequestHandler = async () => {
const response = rejectWalletConnectRequest(requestEvent);
await web3wallet!.respondSessionRequest({
topic,
response,
});
navigation.navigate('Laconic');
};
return (
<>
<ScrollView contentContainerStyle={styles.approveTransaction}>
@ -256,7 +267,13 @@ const ApproveTransaction = ({ route }: ApproveTransactionProps) => {
/>
<View style={styles.buttonContainer}>
<Button mode="contained" onPress={acceptRequestHandler}>
Send tx to chain
Yes
</Button>
<Button
mode="contained"
onPress={rejectRequestHandler}
buttonColor="#B82B0D">
No
</Button>
</View>
</>