Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore platform requirements if extension is installed #264

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading