Skip to content

Commit

Permalink
Merge pull request #4601 from bithyve/giftingSats
Browse files Browse the repository at this point in the history
DeepLink: Gift & F&F merge
  • Loading branch information
Parsh committed Oct 27, 2021
2 parents 82ffa93 + 8eec6a2 commit 1a200b5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
46 changes: 43 additions & 3 deletions src/common/CommonFunctions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export const generateDeepLink = async( { deepLinkKind, encryptionType, encryptio

let deepLink: string

if( deepLinkKind === DeepLinkKind.GIFT ){
if( deepLinkKind === DeepLinkKind.GIFT || deepLink === DeepLinkKind.KEEPER_GIFT ){
deepLink =
`https://hexawallet.io/${appType}/${deepLinkKind}/${walletName}/${encryptedChannelKeys}/${encryptionType}-${encryptionHint}/${extraData.channelAddress}/${extraData.amount}/${extraData.note}/${extraData.themeId}/v${appVersion}`
} else {
Expand Down Expand Up @@ -449,7 +449,6 @@ 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 Down Expand Up @@ -484,6 +483,28 @@ export const processDeepLink = ( deepLink: string ) => {
return {
giftRequest
}

case DeepLinkKind.KEEPER_GIFT:
const trustedContactGiftRequest = {
walletName: splits[ 5 ],
encryptedChannelKeys: splits[ 6 ],
encryptionType,
encryptionHint,
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 ],
channelAddress: splits[ 8 ],
amount: splits[ 9 ],
note: splits[ 10 ],
themeId: splits[ 11 ],
version,
}
return {
trustedContactRequest: trustedContactGiftRequest
}
}
}
catch ( error ) {
Expand All @@ -500,7 +521,6 @@ 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,
Expand Down Expand Up @@ -557,6 +577,26 @@ export const processRequestQR = ( qrData: string ) => {
isQR: true,
}
break

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,
channelAddress: parsedData.channelAddress,
amount: parsedData.amount,
note: parsedData.note,
themeId: parsedData.themeId,
isExistingContact: false,
isQR: true,
version: parsedData.version,
type: parsedData.type,
}
break
}

return {
Expand Down
29 changes: 26 additions & 3 deletions src/pages/Contacts/AddContactSendRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,21 @@ export default function AddContactSendRequest( props ) {
}

const keysToEncrypt = currentContact.channelKey + '-' + ( currentContact.secondaryChannelKey ? currentContact.secondaryChannelKey : '' )
const extraData = giftToSend? {
channelAddress: giftToSend.channelAddress,
amount: giftToSend.amount,
note: giftToSend.note,
themeId: giftToSend.themeId
}: null

const { deepLink, encryptedChannelKeys, encryptionType, encryptionHint, shortLink } = await generateDeepLink( {
deepLinkKind: giftId? DeepLinkKind.KEEPER_GIFT: getDeepLinkKindFromContactsRelationType( currentContact.relationType ),
deepLinkKind: giftToSend? DeepLinkKind.KEEPER_GIFT: getDeepLinkKindFromContactsRelationType( currentContact.relationType ),
encryptionType: encryptLinkWith,
encryptionKey: encryption_key,
walletName: wallet.walletName,
keysToEncrypt,
generateShortLink: true,
extraData
} )
const link = shortLink !== '' ? shortLink: deepLink
setTrustedLink( link )
Expand All @@ -249,16 +257,31 @@ export default function AddContactSendRequest( props ) {
else if( isKeeper ) qrType = QRCodeTypes.KEEPER_REQUEST
else qrType = QRCodeTypes.CONTACT_REQUEST

setTrustedQR(
if( giftToSend ){
JSON.stringify( {
type: qrType,
encryptedChannelKeys: encryptedChannelKeys,
encryptionType,
encryptionHint,
walletName: wallet.walletName,
channelAddress: giftToSend.channelAddress,
amount: giftToSend.amount,
note: giftToSend.note,
themeId: giftToSend.themeId,
version: appVersion,
} )
)
} else{
setTrustedQR(
JSON.stringify( {
type: qrType,
encryptedChannelKeys: encryptedChannelKeys,
encryptionType,
encryptionHint,
walletName: wallet.walletName,
version: appVersion,
} )
)
}

// update deeplink configuration for the contact
if( !currentContact.deepLinkConfig || currentContact.deepLinkConfig.encryptionType !== encryptLinkWith )
Expand Down

0 comments on commit 1a200b5

Please sign in to comment.