From d50cfbfe84d94a5eee30c2fca2b70e7726be1165 Mon Sep 17 00:00:00 2001 From: Adwait Gharpure <69599306+Adw8@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:21:01 +0530 Subject: [PATCH] Add support for displaying svg images (#71) * Add support for SVG images * Fix imports --------- Co-authored-by: Adw8 --- package.json | 1 + src/components/PairingModal.tsx | 16 +++--- src/screens/SignRequest.tsx | 21 +++++--- src/screens/WalletConnect.tsx | 21 ++++++-- src/styles/stylesheet.js | 1 + yarn.lock | 94 +++++++++++++++++++++++++++++++-- 6 files changed, 133 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 21dc97d..efa41e9 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "react-native-quick-crypto": "^0.6.1", "react-native-safe-area-context": "^4.9.0", "react-native-screens": "^3.29.0", + "react-native-svg": "^15.1.0", "react-native-vector-icons": "^10.0.3", "react-native-vision-camera": "^3.9.0", "text-encoding-polyfill": "^0.6.7" diff --git a/src/components/PairingModal.tsx b/src/components/PairingModal.tsx index 06ebbc5..fe3ea6b 100644 --- a/src/components/PairingModal.tsx +++ b/src/components/PairingModal.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useMemo, useState } from 'react'; import { Image, View, Modal, ScrollView } from 'react-native'; import { Button, Text } from 'react-native-paper'; +import { SvgUri } from 'react-native-svg'; import mergeWith from 'lodash/mergeWith'; import { buildApprovedNamespaces, getSdkError } from '@walletconnect/utils'; @@ -190,14 +191,12 @@ const PairingModal = ({ const handleReject = async () => { if (currentProposal) { - setIsLoading(true); const { id } = currentProposal; await web3wallet!.rejectSession({ id, reason: getSdkError('USER_REJECTED_METHODS'), }); - setIsLoading(false); setModalVisible(false); setCurrentProposal(undefined); setWalletConnectData({ @@ -215,10 +214,15 @@ const PairingModal = ({ {icon && ( - + <> + {icon.endsWith('.svg') ? ( + + + + ) : ( + + )} + )} {dappName} diff --git a/src/screens/SignRequest.tsx b/src/screens/SignRequest.tsx index 5fe8ad5..a109018 100644 --- a/src/screens/SignRequest.tsx +++ b/src/screens/SignRequest.tsx @@ -1,6 +1,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { Alert, Image, ScrollView, View } from 'react-native'; import { ActivityIndicator, Button, Text, Appbar } from 'react-native-paper'; +import { SvgUri } from 'react-native-svg'; import { useNavigation } from '@react-navigation/native'; import { @@ -128,7 +129,7 @@ const SignRequest = ({ route }: SignRequestProps) => { }, [retrieveData, sanitizePath, route]); const handleWalletConnectRequest = async () => { - setIsLoading(true) + setIsLoading(true); const { requestEvent } = route.params || {}; if (!account) { @@ -148,7 +149,7 @@ const SignRequest = ({ route }: SignRequestProps) => { const { topic } = requestEvent; await web3wallet!.respondSessionRequest({ topic, response }); - setIsLoading(false) + setIsLoading(false); }; const handleIntent = async () => { @@ -223,10 +224,18 @@ const SignRequest = ({ route }: SignRequestProps) => { {requestIcon && ( - + <> + {requestIcon.endsWith('.svg') ? ( + + + + ) : ( + + )} + )} {requestName} {requestURL} diff --git a/src/screens/WalletConnect.tsx b/src/screens/WalletConnect.tsx index bfc353a..3955009 100644 --- a/src/screens/WalletConnect.tsx +++ b/src/screens/WalletConnect.tsx @@ -1,6 +1,7 @@ import React, { useEffect } from 'react'; import { Image, TouchableOpacity, View } from 'react-native'; import { List, Text } from 'react-native-paper'; +import { SvgUri } from 'react-native-svg'; import { getSdkError } from '@walletconnect/utils'; @@ -43,10 +44,22 @@ export default function WalletConnect() { //TODO: Refactor description={`${sessionId} \n\n${session.peer.metadata.url}\n\n${session.peer.metadata.description}`} left={() => ( - + <> + {session.peer.metadata.icons[0].endsWith('.svg') ? ( + + + + ) : ( + + )} + )} right={() => (