Skip to content

Commit

Permalink
DL/QR type: keeper gift
Browse files Browse the repository at this point in the history
  • Loading branch information
Parsh committed Oct 25, 2021
1 parent c6cbca5 commit e6a88a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/bitcoin/utilities/Interface.ts
Expand Up @@ -783,7 +783,8 @@ export enum QRCodeTypes {
RECOVERY_REQUEST = 'RECOVERY_REQUEST',
EXISTING_CONTACT = 'EXISTING_CONTACT',
APPROVE_KEEPER = 'APPROVE_KEEPER',
GIFT = 'GIFT'
GIFT = 'GIFT',
KEEPER_GIFT = 'KEEPER_GIFT'
}

export interface UTXO {
Expand Down Expand Up @@ -934,7 +935,8 @@ export enum DeepLinkKind {
PRIMARY_KEEPER = 'PRIMARY_KEEPER',
RECIPROCAL_KEEPER = 'RECIPROCAL_KEEPER',
EXISTING_CONTACT = 'EXISTING_CONTACT',
GIFT = 'GIFT'
GIFT = 'GIFT',
KEEPER_GIFT = 'KEEPER_GIFT'
}

export enum DeepLinkEncryptionType {
Expand Down
4 changes: 4 additions & 0 deletions src/common/CommonFunctions/index.ts
Expand Up @@ -449,6 +449,7 @@ export const processDeepLink = ( deepLink: string ) => {
case DeepLinkKind.PRIMARY_KEEPER:
case DeepLinkKind.RECIPROCAL_KEEPER:
case DeepLinkKind.EXISTING_CONTACT:
case DeepLinkKind.KEEPER_GIFT:
const trustedContactRequest = {
walletName: splits[ 5 ],
encryptedChannelKeys: splits[ 6 ],
Expand All @@ -457,6 +458,7 @@ export const processDeepLink = ( deepLink: string ) => {
isKeeper: [ DeepLinkKind.KEEPER, DeepLinkKind.RECIPROCAL_KEEPER, DeepLinkKind.PRIMARY_KEEPER, DeepLinkKind.EXISTING_CONTACT ].includes( ( splits[ 4 ] as DeepLinkKind ) ), // only used as a flag for the UI(not to be passed to initTC during approval)
isPrimaryKeeper: DeepLinkKind.PRIMARY_KEEPER === splits[ 4 ],
isExistingContact: [ DeepLinkKind.RECIPROCAL_KEEPER, DeepLinkKind.EXISTING_CONTACT ].includes( ( splits[ 4 ] as DeepLinkKind ) ),
isKeeperGift: DeepLinkKind.KEEPER_GIFT? true: false,
isQR: false,
deepLinkKind: splits[ 4 ],
version,
Expand Down Expand Up @@ -498,13 +500,15 @@ export const processRequestQR = ( qrData: string ) => {
case QRCodeTypes.CONTACT_REQUEST:
case QRCodeTypes.PRIMARY_KEEPER_REQUEST:
case QRCodeTypes.KEEPER_REQUEST:
case QRCodeTypes.KEEPER_GIFT:
trustedContactRequest = {
walletName: parsedData.walletName,
encryptedChannelKeys: parsedData.encryptedChannelKeys,
encryptionType: parsedData.encryptionType,
encryptionHint: parsedData.encryptionHint,
isKeeper: parsedData.type === QRCodeTypes.KEEPER_REQUEST || parsedData.type === QRCodeTypes.PRIMARY_KEEPER_REQUEST, // only used as a flag for the UI(not to be passed to initTC during approval)
isPrimaryKeeper: parsedData.type === QRCodeTypes.PRIMARY_KEEPER_REQUEST,
isKeeperGift: DeepLinkKind.KEEPER_GIFT? true: false,
isExistingContact: false,
isQR: true,
version: parsedData.version,
Expand Down
14 changes: 11 additions & 3 deletions src/pages/Contacts/AddContactSendRequest.tsx
Expand Up @@ -31,7 +31,7 @@ import ModalHeader from '../../components/ModalHeader'
import TimerModalContents from './TimerModalContents'
import RequestKeyFromContact from '../../components/RequestKeyFromContact'
import ShareOtpWithContact from '../NewBHR/ShareOtpWithTrustedContact'
import { DeepLinkEncryptionType, QRCodeTypes, TrustedContact, Trusted_Contacts, Wallet } from '../../bitcoin/utilities/Interface'
import { DeepLinkEncryptionType, DeepLinkKind, QRCodeTypes, TrustedContact, Trusted_Contacts, Wallet } from '../../bitcoin/utilities/Interface'
import { initializeTrustedContact, InitTrustedContactFlowKind, PermanentChannelsSyncKind, syncPermanentChannels, updateTrustedContacts } from '../../store/actions/trustedContacts'
import useTrustedContacts from '../../utils/hooks/state-selectors/trusted-contacts/UseTrustedContacts'
import idx from 'idx'
Expand Down Expand Up @@ -231,7 +231,7 @@ export default function AddContactSendRequest( props ) {

const keysToEncrypt = currentContact.channelKey + '-' + ( currentContact.secondaryChannelKey ? currentContact.secondaryChannelKey : '' )
const { deepLink, encryptedChannelKeys, encryptionType, encryptionHint, shortLink } = await generateDeepLink( {
deepLinkKind: getDeepLinkKindFromContactsRelationType( currentContact.relationType ),
deepLinkKind: giftId? DeepLinkKind.KEEPER_GIFT: getDeepLinkKindFromContactsRelationType( currentContact.relationType ),
encryptionType: encryptLinkWith,
encryptionKey: encryption_key,
walletName: wallet.walletName,
Expand All @@ -241,9 +241,17 @@ export default function AddContactSendRequest( props ) {
const link = shortLink !== '' ? shortLink: deepLink
setTrustedLink( link )
const appVersion = DeviceInfo.getVersion()

let qrType: string
if( giftId ) qrType = QRCodeTypes.KEEPER_GIFT
else if( existingContact ) qrType = QRCodeTypes.EXISTING_CONTACT
else if( isPrimary ) qrType = QRCodeTypes.PRIMARY_KEEPER_REQUEST
else if( isKeeper ) qrType = QRCodeTypes.KEEPER_REQUEST
else qrType = QRCodeTypes.CONTACT_REQUEST

setTrustedQR(
JSON.stringify( {
type: existingContact ? QRCodeTypes.EXISTING_CONTACT : isPrimary ? QRCodeTypes.PRIMARY_KEEPER_REQUEST : isKeeper ? QRCodeTypes.KEEPER_REQUEST : QRCodeTypes.CONTACT_REQUEST,
type: qrType,
encryptedChannelKeys: encryptedChannelKeys,
encryptionType,
encryptionHint,
Expand Down

0 comments on commit e6a88a3

Please sign in to comment.