Skip to content

Commit

Permalink
Merge pull request #5558 from bithyve/fix/nfc-issues
Browse files Browse the repository at this point in the history
Fix CC registration with NFC on Android and wrong toast
  • Loading branch information
cakesoft-utkarsh authored Nov 11, 2024
2 parents 4d4c467 + c09c56f commit 16a9bed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/hooks/useConfigReocvery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CommonActions, useNavigation } from '@react-navigation/native';
import { resetRealyVaultState } from 'src/store/reducers/bhr';
import { generateVaultId } from 'src/services/wallets/factories/VaultFactory';
import TickIcon from 'src/assets/images/icon_tick.svg';
import ToastErrorIcon from 'src/assets/images/toast_error.svg';
import useToastMessage from './useToastMessage';
import useVault from './useVault';

Expand Down Expand Up @@ -105,6 +106,8 @@ const useConfigRecovery = () => {
setRecoveryLoading(false);
recoveryError.failed = true;
recoveryError.message = err;
showToast(err.message ? err.message : err.toString(), <ToastErrorIcon />);
navigation.goBack();
}
};

Expand Down
13 changes: 8 additions & 5 deletions src/screens/NFCChannel/ShareWithNfc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function ShareWithNfc({
sendConfirmationRouteParams,
tnxDetails,
fileName,
useNdef = false,
}: {
data: string;
signer?: Signer;
Expand All @@ -43,6 +44,7 @@ function ShareWithNfc({
sendConfirmationRouteParams?: SendConfirmationRouteParams;
tnxDetails?: tnxDetailsProps;
fileName?: string;
useNdef?: boolean; // For hardware wallets interactions
}) {
const { session } = useContext(HCESessionContext);
const navigation = useNavigation<any>();
Expand All @@ -53,17 +55,15 @@ function ShareWithNfc({
const cleanUp = () => {
setVisible(false);
Vibration.cancel();
if (isAndroid) {
if (isAndroid && !useNdef) {
NFC.stopTagSession(session);
}
};
useEffect(() => {
const unsubDisconnect = session.on(HCESession.Events.HCE_STATE_DISCONNECTED, () => {
cleanUp();
});
const unsubRead = session.on(HCESession.Events.HCE_STATE_READ, () => {
showToast('Cosigner details shared successfully', <TickIcon />);
});
const unsubRead = session.on(HCESession.Events.HCE_STATE_READ, () => {});
return () => {
cleanUp();
unsubRead();
Expand All @@ -76,7 +76,10 @@ function ShareWithNfc({

const shareWithNFC = async () => {
try {
if (isIos) {
if (isIos || useNdef) {
if (!isIos) {
setVisible(true);
}
Vibration.vibrate([700, 50, 100, 50], true);
const enc = NFC.encodeTextRecord(data);
await NFC.send([NfcTech.Ndef], enc);
Expand Down
2 changes: 1 addition & 1 deletion src/screens/QRScreens/RegisterWithQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function RegisterWithQR({ route, navigation }: any) {
)}
</Box>
<Box style={styles.centerBottom}>
<ShareWithNfc data={walletConfig} signer={signer} />
<ShareWithNfc data={walletConfig} signer={signer} useNdef />
</Box>
<Buttons
primaryText="Confirm Registration"
Expand Down

0 comments on commit 16a9bed

Please sign in to comment.