Skip to content

Commit

Permalink
Install prettier
Browse files Browse the repository at this point in the history
chasefleming committed Oct 26, 2021
1 parent dfe13bd commit cd1cd62
Showing 20 changed files with 126 additions and 97 deletions.
6 changes: 2 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"presets": [
"next/babel"
],
"presets": ["next/babel"],
"plugins": [
[
"styled-components",
@@ -12,4 +10,4 @@
}
]
]
}
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next
node_modules
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "avoid"
}
30 changes: 18 additions & 12 deletions components/Discovery.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useEffect, useMemo } from "react"
import {useEffect, useMemo} from "react"
import styled from "styled-components"
import {WalletUtils} from "@onflow/fcl"
import {
gte as isGreaterThanOrEqualToVersion,
valid as isValidVersion,
} from "semver"
import { useFetch } from "../hooks/useFetch"
import { useFCL } from "../hooks/useFCL"
import { combineServices, serviceListOfType } from "../helpers/services"
import { SERVICE_TYPES } from "../helpers/constants"
import {useFetch} from "../hooks/useFetch"
import {useFCL} from "../hooks/useFCL"
import {combineServices, serviceListOfType} from "../helpers/services"
import {SERVICE_TYPES} from "../helpers/constants"
import Header from "./Header"
import Footer from "./Footer"
import ServiceCard from "./ServiceCard"
@@ -74,11 +74,11 @@ const ProviderCardDisabled = styled.div`
-moz-appearance: none;
`

export const Discovery = ({ network, handleCancel }) => {
export const Discovery = ({network, handleCancel}) => {
const requestUrl = `/api/services?=${network}`
const supportedVersion = "0.0.79" // Version that supports browser extension redirects
const { appVersion, extensions } = useFCL()
const { loading, data, error } = useFetch(requestUrl)
const {appVersion, extensions} = useFCL()
const {loading, data, error} = useFetch(requestUrl)
const services = useMemo(() => {
let defaultServices = serviceListOfType(data, SERVICE_TYPES.AUTHN)

@@ -88,12 +88,18 @@ export const Discovery = ({ network, handleCancel }) => {
isGreaterThanOrEqualToVersion(appVersion, supportedVersion)
) {
// Add browser extensions
const combinedServiceList = combineServices(defaultServices, extensions, true)
defaultServices = serviceListOfType(combinedServiceList, SERVICE_TYPES.AUTHN)
const combinedServiceList = combineServices(
defaultServices,
extensions,
true
)
defaultServices = serviceListOfType(
combinedServiceList,
SERVICE_TYPES.AUTHN
)
}

return defaultServices

}, [data, extensions, appVersion])

const showProvider = provider => provider.enabled !== false
@@ -138,4 +144,4 @@ export const Discovery = ({ network, handleCancel }) => {
<Footer handleCancel={handleCancel} />
</AppContainer>
)
}
}
2 changes: 1 addition & 1 deletion components/Footer.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ const AppCancel = styled.button`
-moz-appearance: none;
`

export default function Footer({ handleCancel }) {
export default function Footer({handleCancel}) {
return (
<AppFooter>
<AppCancel onClick={handleCancel}>Cancel</AppCancel>
2 changes: 1 addition & 1 deletion components/Header.js
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ export default function Header() {
return (
<AppHeader>
<AppLogoWrapper>
<AppLogo src="/logo.svg" alt='Flow Logo' />
<AppLogo src="/logo.svg" alt="Flow Logo" />
</AppLogoWrapper>
<AppTitle>Choose a Provider</AppTitle>
</AppHeader>
2 changes: 1 addition & 1 deletion components/ServiceCard.js
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ const ProviderCardDescription = styled.div`
text-align: left;
`

export default function ServiceCard({ icon, name, description }) {
export default function ServiceCard({icon, name, description}) {
return (
<ProviderCardRow>
<ProviderCardIcon icon={icon} />
20 changes: 10 additions & 10 deletions helpers/__tests__/paths.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { createPathFromArray } from "../paths"
import {createPathFromArray} from "../paths"

describe('paths helpers: createPathFromArray', () => {
it('should create paths from array of directories', () => {
const arrOne = ['authn']
const arrTwo = ['testnet', 'authn']
const arrThree = ['canarynet', 'authn']
describe("paths helpers: createPathFromArray", () => {
it("should create paths from array of directories", () => {
const arrOne = ["authn"]
const arrTwo = ["testnet", "authn"]
const arrThree = ["canarynet", "authn"]

const expectedResponseOne = '/authn'
const expectedResponseTwo = '/testnet/authn'
const expectedResponseThree = '/canarynet/authn'
const expectedResponseOne = "/authn"
const expectedResponseTwo = "/testnet/authn"
const expectedResponseThree = "/canarynet/authn"

expect(createPathFromArray(arrOne)).toEqual(expectedResponseOne)
expect(createPathFromArray(arrTwo)).toEqual(expectedResponseTwo)
expect(createPathFromArray(arrThree)).toEqual(expectedResponseThree)
})
})
})
58 changes: 30 additions & 28 deletions helpers/__tests__/services.test.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,65 @@
import { combineServices, serviceListOfType } from "../services"

describe('services helpers: combineServices', () => {
it('should combine services with right ordering and filter unique', () => {
import {combineServices, serviceListOfType} from "../services"

describe("services helpers: combineServices", () => {
it("should combine services with right ordering and filter unique", () => {
const serviceA = {
"id": 1,
"endpoint": "https://flow-wallet.blocto.app/authn",
"provider": {
"name": "Blocto"
}
id: 1,
endpoint: "https://flow-wallet.blocto.app/authn",
provider: {
name: "Blocto",
},
}

const serviceB = {
"id": 2,
"endpoint": "https://fcl-ledger.onflow.org/mainnet/authn",
"provider": {
"name": "Ledger"
}
id: 2,
endpoint: "https://fcl-ledger.onflow.org/mainnet/authn",
provider: {
name: "Ledger",
},
}

const serviceC = {
"id": 3,
id: 3,
endpoint: "liquality",
provider: {
name: "Liquality Wallet Extension",
}
},
}

const serviceListOne = [serviceA, serviceB]
const serviceListTwo = [serviceC, serviceC]
const expectedListOne = [serviceA, serviceB, serviceC]
const expectedListTwo = [serviceC, serviceA, serviceB]

expect(combineServices(serviceListOne, serviceListTwo)).toEqual(expectedListOne)
expect(combineServices(serviceListOne, serviceListTwo, true)).toEqual(expectedListTwo)
expect(combineServices(serviceListOne, serviceListTwo)).toEqual(
expectedListOne
)
expect(combineServices(serviceListOne, serviceListTwo, true)).toEqual(
expectedListTwo
)
})
})

describe('services helpers: serviceListOfType', () => {
it('should combine services with right ordering and filter unique', () => {

describe("services helpers: serviceListOfType", () => {
it("should combine services with right ordering and filter unique", () => {
const serviceA = {
"id": 1,
"type": "authn"
id: 1,
type: "authn",
}

const serviceB = {
"id": 2,
"type": "authz"
id: 2,
type: "authz",
}

const serviceC = {
"id": 2,
"type": "pre-authz"
id: 2,
type: "pre-authz",
}

const serviceList = [serviceA, serviceB, serviceC]

expect(serviceListOfType(serviceList, "authn").length).toEqual(1)
expect(serviceListOfType(serviceList, "authn")[0]).toEqual(serviceA)
})
})
})
10 changes: 5 additions & 5 deletions helpers/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const PATHS = {
MAIN: '/authn',
TESTNET: '/testnet/authn',
CANARYNET: '/canarynet/authn'
MAIN: "/authn",
TESTNET: "/testnet/authn",
CANARYNET: "/canarynet/authn",
}

export const SERVICE_TYPES = {
AUTHN: "authn"
}
AUTHN: "authn",
}
2 changes: 1 addition & 1 deletion helpers/paths.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const createPathFromArray = (arr = []) => `/${arr.join('/')}`
export const createPathFromArray = (arr = []) => `/${arr.join("/")}`
11 changes: 8 additions & 3 deletions helpers/services.js
Original file line number Diff line number Diff line change
@@ -10,14 +10,19 @@ const filterUniqueServices = services => {
})
}

export const combineServices = (existingServices = [], newServices = [], front = false) => {
export const combineServices = (
existingServices = [],
newServices = [],
front = false
) => {
let combined
if (front) {
combined = newServices.concat(existingServices)
} else {
combined = existingServices.concat(newServices)
combined = existingServices.concat(newServices)
}
return filterUniqueServices(combined)
}

export const serviceListOfType = (services = [], type) => services.filter(service => service.type === type)
export const serviceListOfType = (services = [], type) =>
services.filter(service => service.type === type)
8 changes: 4 additions & 4 deletions hooks/useFCL.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import {useEffect, useState} from "react"
import {WalletUtils} from "@onflow/fcl"
import { valid as isValidVersion } from "semver"
import {valid as isValidVersion} from "semver"

export function useFCL() {
const [appVersion, setAppVersion] = useState(null)
@@ -17,6 +17,6 @@ export function useFCL() {

return {
appVersion,
extensions
extensions,
}
}
}
6 changes: 3 additions & 3 deletions hooks/useFetch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react";
import {useEffect, useState} from "react"

export function useFetch(url) {
const [data, setData] = useState()
@@ -17,6 +17,6 @@ export function useFetch(url) {
return {
loading,
data,
error
error,
}
}
}
4 changes: 2 additions & 2 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
reactStrictMode: true,
eslint: {
ignoreDuringBuilds: true
}
ignoreDuringBuilds: true,
},
}
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
},
"devDependencies": {
"babel-plugin-styled-components": "^1.13.3",
"jest": "^27.3.1"
"jest": "^27.3.1",
"prettier": "^2.4.1"
}
}
18 changes: 9 additions & 9 deletions pages/[...path].js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { useRouter } from 'next/router'
import { Discovery } from '../components/Discovery'
import { PATHS } from '../helpers/constants'
import { createPathFromArray } from '../helpers/paths'
import {useRouter} from "next/router"
import {Discovery} from "../components/Discovery"
import {PATHS} from "../helpers/constants"
import {createPathFromArray} from "../helpers/paths"

const Router = ({ handleCancel }) => {
const Router = ({handleCancel}) => {
const router = useRouter()
const { path } = router.query // ['authn'] ['testnet', 'authn'] ['canarynet', 'authn']
const {path} = router.query // ['authn'] ['testnet', 'authn'] ['canarynet', 'authn']
const pathStr = createPathFromArray(path)
const isValidRoute = Object.values(PATHS).some(p => p === pathStr)
const network = path && path.length === 2 ? path[0] : 'mainnet'
const network = path && path.length === 2 ? path[0] : "mainnet"

if (!isValidRoute) return <div>Page Not Found</div>

return <Discovery network={network} handleCancel={handleCancel} />
}

export default Router
export default Router
Loading

0 comments on commit cd1cd62

Please sign in to comment.