Skip to content

Commit

Permalink
reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Jul 24, 2024
1 parent 579fc43 commit 6a3a39f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 40 deletions.
File renamed without changes.
31 changes: 0 additions & 31 deletions helpers/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,6 @@ export const filterSupportedStrategies =
return services.filter(s => supportedStrategies.includes(s.method))
}

export const injectClientServices =
(clientServices = []) =>
(services, { wallets }) => {
const walletMap = services.reduce((acc, service) => {
const wallet = wallets.find(w => w.uid === service.walletUid)
const addr = service?.provider?.address || wallet?.address
const uid = service?.uid
if (addr) acc[addr] = wallet
if (uid) acc[uid] = wallet
return acc
}, {})

const injectedServices = map(
pipe(clone, service => {
const wallet = walletMap[service?.provider?.address]
if (wallet) {
service.walletUid = wallet.uid
return service
} else {
return service
}
}),
clientServices
)

return filterUniqueServices({ address: true, uid: false })([
...injectedServices,
...services,
])
}

export const filterUniqueServices =
({ address = true, uid = false }) =>
services => {
Expand Down
9 changes: 5 additions & 4 deletions helpers/walletPipes.ts → helpers/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { clone, identity, partial, pipe } from 'rambda'
import { clone, partial, pipe } from 'rambda'
import { filterUniqueServices } from './services'
import { nextJsImageToBase64 } from './image'
import { Service, ServicesPipeFactory } from '../types'
import { Wallet, WalletConfig } from '../data/wallets'

export type ServiceWithWallet = Service & { walletUid: string }
type WalletConfigWithProcessedIcon = Omit<WalletConfig, 'icon'> & {
export type WalletConfigWithIcon = Omit<WalletConfig, 'icon'> & {
icon: string
}

Expand Down Expand Up @@ -46,6 +46,7 @@ export const extractWalletServices =
return acc
}, [])

// TODO: does this belong here?
export const injectClientServices = (
clientServices: ServiceWithWallet[] = [],
wallets: Wallet[] = []
Expand Down Expand Up @@ -96,7 +97,7 @@ export const injectClientServices = (

export const walletsForNetwork =
(network: string) =>
(wallets: WalletConfigWithProcessedIcon[] = []): Wallet[] =>
(wallets: WalletConfigWithIcon[] = []): Wallet[] =>
wallets
.filter(wallet => wallet.services[network])
.map(wallet => ({
Expand All @@ -106,7 +107,7 @@ export const walletsForNetwork =

export const walletIconsToBase64 = (
wallets: WalletConfig[]
): WalletConfigWithProcessedIcon[] =>
): WalletConfigWithIcon[] =>
wallets.map((wallet: WalletConfig) => ({
...wallet,
icon: wallet.icon ? nextJsImageToBase64(wallet.icon) : undefined,
Expand Down
6 changes: 3 additions & 3 deletions pages/api/[network]/_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Cors from 'cors'
import { wallets } from '../../../data/wallets'
import { findMatchingPipeVersion } from '../../../helpers/version'
import { NETWORKS } from '../../../helpers/constants'
import { getServicePipes } from '../../../helpers/servicePipes'
import { getWalletPipe } from '../../../helpers/walletPipes'
import { getServicePipes } from '../../../helpers/service-pipes'
import { getWalletPipe } from '../../../helpers/wallets'
import { NextApiRequest } from 'next'

// Initializing the cors middleware
Expand Down Expand Up @@ -57,7 +57,7 @@ export async function getWalletsFromRequest(req: NextApiRequest) {

// Support emulator and use local service configuration
const netConfig = network === NETWORKS.EMULATOR ? NETWORKS.LOCAL : network

// Get the pipe for processing wallets
const walletPipe = getWalletPipe({
network: netConfig,
Expand Down
2 changes: 1 addition & 1 deletion pages/api/[network]/authn.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import { NextApiHandler } from 'next'
import Sentry from '../../../config/sentry.server'
import { walletToProvider } from '../../../helpers/walletPipes'
import { walletToProvider } from '../../../helpers/wallets'
import { cors, getWalletsFromRequest, runMiddleware } from './_common'
import { Wallet } from '../../../data/wallets'

Expand Down
2 changes: 1 addition & 1 deletion types/services.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Wallet } from '../data/wallets'
import { ServiceWithWallet } from '../helpers/walletPipes'
import { ServiceWithWallet } from '../helpers/wallets'

export type Provider = {
address?: string
Expand Down

0 comments on commit 6a3a39f

Please sign in to comment.