Skip to content

Commit

Permalink
Ignore platform requirements if extension is installed (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Sep 19, 2024
1 parent 8f118dc commit 8c368f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
19 changes: 10 additions & 9 deletions helpers/__tests__/services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('services helpers: filterUniqueServices', () => {
const serviceList = [serviceA, serviceB, serviceC, serviceD]
const expectedList = [serviceA, serviceB, serviceC]
const filteredList = filterUniqueServices({ address: true, uid: false })(
serviceList
serviceList,
)

expect(filteredList).toEqual(expectedList)
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('services helpers: filterUniqueServices', () => {
const serviceList = [serviceA, serviceB, serviceC, serviceD]
const expectedList = [serviceA, serviceB, serviceC]
const filteredList = filterUniqueServices({ address: true, uid: true })(
serviceList
serviceList,
)

expect(filteredList).toEqual(expectedList)
Expand Down Expand Up @@ -131,10 +131,10 @@ describe('services helpers: combineServices', () => {
const expectedListTwo = [serviceC, serviceA, serviceB]

expect(combineServices(serviceListOne, serviceListTwo)).toEqual(
expectedListOne
expectedListOne,
)
expect(combineServices(serviceListOne, serviceListTwo, true)).toEqual(
expectedListTwo
expectedListTwo,
)
})
})
Expand Down Expand Up @@ -202,10 +202,10 @@ describe('services helpers: filterOptInServices', () => {
const expectedResponseB = [serviceA, serviceB, serviceC]

const walletsA = serviceListA.map(x =>
injectedServiceToWallet(x as Service)
injectedServiceToWallet(x as Service),
)
const walletsB = serviceListB.map(x =>
injectedServiceToWallet(x as Service)
injectedServiceToWallet(x as Service),
)

const filterOptInServicesA = filterOptInServices({
Expand Down Expand Up @@ -263,10 +263,11 @@ describe('services helpers: filterServicesByPlatform', () => {
services: [x],
}))
const services = extractWalletServices(wallets as any)
const extensions = []
const expectedRes = [serviceA, serviceB, serviceC]

expect(filterServicesByPlatform({ wallets, platform })(services)).toEqual(
expectedRes
)
expect(
filterServicesByPlatform({ wallets, platform, extensions })(services),
).toEqual(expectedRes)
})
})
5 changes: 4 additions & 1 deletion helpers/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,13 @@ export const requiresPlatform = service => {
return requiredPlatformTypes.includes(service?.method)
}

export const filterServicesByPlatform = ({ wallets, platform }) =>
export const filterServicesByPlatform = ({ wallets, platform, extensions }) =>
filter(service => {
if (!requiresPlatform(service)) return true

// If extension is installed, ignore platform requirements
if (isExtensionInstalled(extensions, service)) return true

const wallet = wallets?.find(w => w.uid === service.walletUid)
if (!wallet.installLink) return true

Expand Down
4 changes: 2 additions & 2 deletions helpers/wallet-pipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const getWalletPipes = ({
// Filter out extensions if not supported because they were added on the FCL side in previous versions
ifElse(
always(areUninstalledExtensionsSupported),
filterServicesByPlatform({ wallets, platform }),
filterServicesByPlatform({ wallets, platform, extensions }),
reject(isExtension),
),
) as any,
Expand Down Expand Up @@ -137,7 +137,7 @@ export const getWalletPipes = ({
ifElse(
always(includeUninstalledServices),
pipe(
filterServicesByPlatform({ wallets, platform }),
filterServicesByPlatform({ wallets, platform, extensions }),
appendInstallData({ wallets, platform, extensions }),
),
filterUninstalledServices({ extensions }),
Expand Down

0 comments on commit 8c368f4

Please sign in to comment.