UI Improvements (#65)

* Rebase ui branch

* Fix scrollview (#69)

* Add loading prop to button

* Change function reference

* Remove fragment

---------

Co-authored-by: Adw8 <adwait@deepstacksoft.com>
Co-authored-by: IshaVenikar <145848618+IshaVenikar@users.noreply.github.com>
This commit is contained in:
neerajvijay1997 2024-03-28 16:23:12 +05:30 committed by GitHub
parent b134c957f6
commit 290ea0097c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 18 deletions

View File

@ -11,7 +11,7 @@ import { web3wallet } from '../utils/wallet-connect/WalletConnectUtils';
import { useAccounts } from '../context/AccountsContext'; import { useAccounts } from '../context/AccountsContext';
import { useWalletConnect } from '../context/WalletConnectContext'; import { useWalletConnect } from '../context/WalletConnectContext';
import { EIP155_CHAINS } from '../utils/wallet-connect/EIP155Data'; import { EIP155_CHAINS } from '../utils/wallet-connect/EIP155Data';
import { COSMOS_MAINNET_CHAINS } from '../utils/wallet-connect/COSMOSData'; import { COSMOS_CHAINS } from '../utils/wallet-connect/COSMOSData';
const PairingModal = ({ const PairingModal = ({
visible, visible,
@ -21,7 +21,9 @@ const PairingModal = ({
setToastVisible, setToastVisible,
}: PairingModalProps) => { }: PairingModalProps) => {
const { accounts, currentIndex } = useAccounts(); const { accounts, currentIndex } = useAccounts();
const [isLoading, setIsLoading] = useState(false);
const dappName = currentProposal?.params?.proposer?.metadata.name;
const url = currentProposal?.params?.proposer?.metadata.url; const url = currentProposal?.params?.proposer?.metadata.url;
const icon = currentProposal?.params.proposer?.metadata.icons[0]; const icon = currentProposal?.params.proposer?.metadata.icons[0];
@ -80,7 +82,7 @@ const PairingModal = ({
const eip155Chains = Object.keys(EIP155_CHAINS); const eip155Chains = Object.keys(EIP155_CHAINS);
// cosmos // cosmos
const cosmosChains = Object.keys(COSMOS_MAINNET_CHAINS); const cosmosChains = Object.keys(COSMOS_CHAINS);
// Set selected account as the first account in supported namespaces // Set selected account as the first account in supported namespaces
const sortedAccounts = Object.entries(accounts).reduce( const sortedAccounts = Object.entries(accounts).reduce(
@ -160,6 +162,7 @@ const PairingModal = ({
const handleAccept = async () => { const handleAccept = async () => {
try { try {
if (currentProposal && namespaces) { if (currentProposal && namespaces) {
setIsLoading(true);
const { id } = currentProposal; const { id } = currentProposal;
await web3wallet!.approveSession({ await web3wallet!.approveSession({
@ -168,6 +171,7 @@ const PairingModal = ({
}); });
const sessions = web3wallet!.getActiveSessions(); const sessions = web3wallet!.getActiveSessions();
setIsLoading(false);
setActiveSessions(sessions); setActiveSessions(sessions);
setModalVisible(false); setModalVisible(false);
setToastVisible(true); setToastVisible(true);
@ -186,12 +190,14 @@ const PairingModal = ({
const handleReject = async () => { const handleReject = async () => {
if (currentProposal) { if (currentProposal) {
setIsLoading(true);
const { id } = currentProposal; const { id } = currentProposal;
await web3wallet!.rejectSession({ await web3wallet!.rejectSession({
id, id,
reason: getSdkError('USER_REJECTED_METHODS'), reason: getSdkError('USER_REJECTED_METHODS'),
}); });
setIsLoading(false);
setModalVisible(false); setModalVisible(false);
setCurrentProposal(undefined); setCurrentProposal(undefined);
setWalletConnectData({ setWalletConnectData({
@ -215,11 +221,16 @@ const PairingModal = ({
/> />
)} )}
<Text variant="titleMedium">{dappName}</Text>
<Text variant="bodyMedium">{url}</Text> <Text variant="bodyMedium">{url}</Text>
<View style={styles.marginVertical8} /> <View style={styles.marginVertical8} />
<Text variant="titleMedium">Connect to this site?</Text> <Text variant="titleMedium">Connect to this site?</Text>
<Text>Chains: {walletConnectData.walletConnectChains}</Text> <Text variant="titleMedium">Chains:</Text>
{walletConnectData.walletConnectChains.map(chain => (
<Text style={styles.centerText} key={chain}>
{chain}
</Text>
))}
<View style={styles.marginVertical8}> <View style={styles.marginVertical8}>
<Text variant="titleMedium">Methods Requested:</Text> <Text variant="titleMedium">Methods Requested:</Text>
{walletConnectData.walletConnectMethods.map(method => ( {walletConnectData.walletConnectMethods.map(method => (
@ -237,18 +248,18 @@ const PairingModal = ({
</Text> </Text>
))} ))}
</View> </View>
<View style={styles.flexRow}>
<Button mode="contained" onPress={handleAccept}>
Accept
</Button>
<View style={styles.space} />
<Button mode="outlined" onPress={handleReject}>
Cancel
</Button>
</View>
</View> </View>
</ScrollView> </ScrollView>
<View style={styles.flexRow}>
<Button mode="contained" onPress={handleAccept} loading={isLoading}>
{isLoading ? 'Connecting' : 'Yes'}
</Button>
<View style={styles.space} />
<Button mode="outlined" onPress={handleReject}>
No
</Button>
</View>
</View> </View>
</View> </View>
</Modal> </Modal>

View File

@ -128,7 +128,8 @@ const SignRequest = ({ route }: SignRequestProps) => {
}, [retrieveData, sanitizePath, route]); }, [retrieveData, sanitizePath, route]);
const handleWalletConnectRequest = async () => { const handleWalletConnectRequest = async () => {
const { requestEvent } = route.params; setIsLoading(true)
const { requestEvent } = route.params || {};
if (!account) { if (!account) {
throw new Error('account not found'); throw new Error('account not found');
@ -147,6 +148,7 @@ const SignRequest = ({ route }: SignRequestProps) => {
const { topic } = requestEvent; const { topic } = requestEvent;
await web3wallet!.respondSessionRequest({ topic, response }); await web3wallet!.respondSessionRequest({ topic, response });
setIsLoading(false)
}; };
const handleIntent = async () => { const handleIntent = async () => {
@ -174,13 +176,15 @@ const SignRequest = ({ route }: SignRequestProps) => {
}; };
const rejectRequestHandler = async () => { const rejectRequestHandler = async () => {
if (route.params.requestEvent) { if (route.params?.requestEvent) {
const response = rejectWalletConnectRequest(route.params.requestEvent); setIsLoading(true);
const { topic } = route.params.requestEvent; const response = rejectWalletConnectRequest(route.params?.requestEvent);
const { topic } = route.params?.requestEvent;
await web3wallet!.respondSessionRequest({ await web3wallet!.respondSessionRequest({
topic, topic,
response, response,
}); });
setIsLoading(true);
} }
navigation.navigate('Laconic'); navigation.navigate('Laconic');
}; };

View File

@ -137,6 +137,8 @@ const styles = StyleSheet.create({
buttonContainer: { buttonContainer: {
flexDirection: 'row', flexDirection: 'row',
marginLeft: 20, marginLeft: 20,
marginTop: 20,
marginBottom: 20,
justifyContent: 'space-evenly', justifyContent: 'space-evenly',
}, },
badRequestContainer: { badRequestContainer: {
@ -155,6 +157,7 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
marginBottom: 10, marginBottom: 10,
paddingHorizontal: 20,
}, },
modalContentContainer: { modalContentContainer: {
display: 'flex', display: 'flex',
@ -186,6 +189,7 @@ const styles = StyleSheet.create({
alignItems: 'center', alignItems: 'center',
marginTop: 20, marginTop: 20,
paddingHorizontal: 16, paddingHorizontal: 16,
marginBottom: 10,
}, },
marginVertical8: { marginVertical8: {
marginVertical: 8, marginVertical: 8,