Skip to content

Commit

Permalink
OPS - Run prettier on js codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbarry committed May 27, 2022
1 parent 3afdf0e commit aa31496
Show file tree
Hide file tree
Showing 117 changed files with 2,618 additions and 2,294 deletions.
6 changes: 2 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
"projects": [
"<rootDir>/packages/*"
]
};
projects: ["<rootDir>/packages/*"],
}
2 changes: 1 addition & 1 deletion packages/fcl/src/config-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ export async function getDiscoveryService() {
type: "authn",
endpoint: discoveryWallet,
method: discoveryWalletMethod,
discoveryAuthnInclude
discoveryAuthnInclude,
}
}
31 changes: 15 additions & 16 deletions packages/fcl/src/current-user/exec-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,32 @@ export async function execService({service, msg = {}, opts = {}, config = {}}) {
}

try {
const res = await STRATEGIES[service.method](
service,
msg,
opts,
fullConfig
)
const res = await STRATEGIES[service.method](service, msg, opts, fullConfig)
if (res.status === "REDIRECT") {
invariant(
service.type === res.data.type,
"Cannot shift recursive service type in execService"
)
return await execService({
service: res.data,
msg,
opts,
config: fullConfig
service: res.data,
msg,
opts,
config: fullConfig,
})
} else {
return res
}
} catch (error) {
console.error("execService({service, msg = {}, opts = {}, config = {}})", error, {
service,
msg,
opts,
config
})
console.error(
"execService({service, msg = {}, opts = {}, config = {}})",
error,
{
service,
msg,
opts,
config,
}
)
throw error
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export function fetchService(service, opts = {}) {
"Content-Type": "application/json",
},
body: body,
}).then((d) => d.json())
}).then(d => d.json())
}
4 changes: 2 additions & 2 deletions packages/fcl/src/discovery/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import authn from "./services/authn"

const discovery = {
authn
authn,
}

export {discovery}
export {discovery}
26 changes: 15 additions & 11 deletions packages/fcl/src/discovery/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import {config} from "@onflow/config"
import {invariant} from "@onflow/util-invariant"
import {VERSION} from "../VERSION"

const asyncPipe = (...fns) => input => fns.reduce((chain, fn) => chain.then(fn), Promise.resolve(input))
const asyncPipe =
(...fns) =>
input =>
fns.reduce((chain, fn) => chain.then(fn), Promise.resolve(input))

async function addServices(services = []) {
const endpoint = await config.get("discovery.authn.endpoint")
invariant(Boolean(endpoint), `"discovery.authn.endpoint" in config must be defined.`)
invariant(
Boolean(endpoint),
`"discovery.authn.endpoint" in config must be defined.`
)

const include = await config.get("discovery.authn.include", [])
const url = new URL(endpoint)
Expand All @@ -18,10 +24,11 @@ async function addServices(services = []) {
},
body: JSON.stringify({
fclVersion: VERSION,
include
})
}).then(d => d.json())
.then(json => [...services, ...json])
include,
}),
})
.then(d => d.json())
.then(json => [...services, ...json])
}

function addExtensions(services = []) {
Expand All @@ -33,8 +40,5 @@ function filterServicesByType(services = [], type) {
return services.filter(service => service.type === type)
}

export const getServices = ({ type }) => asyncPipe(
addServices,
addExtensions,
s => filterServicesByType(s, type)
)([])
export const getServices = ({type}) =>
asyncPipe(addServices, addExtensions, s => filterServicesByType(s, type))([])
101 changes: 53 additions & 48 deletions packages/fcl/src/discovery/services.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,56 @@ import {getServices} from "./services"
import {config} from "@onflow/config"

const serviceOne = {
"f_type": "Service",
"f_vsn": "1.0.0",
"type": "authn",
"method": "IFRAME/RPC",
"uid": "walletone#authn",
"endpoint": "https://test.test",
"provider": {
"address": "0x1",
"name": "Wallet One"
}
f_type: "Service",
f_vsn: "1.0.0",
type: "authn",
method: "IFRAME/RPC",
uid: "walletone#authn",
endpoint: "https://test.test",
provider: {
address: "0x1",
name: "Wallet One",
},
}

const serviceTwo = {
"f_type": "Service",
"f_vsn": "1.0.0",
"type": "authz",
"method": "IFRAME/RPC",
"uid": "wallettwo#authn",
"endpoint": "https://test.test",
"provider": {
"address": "0x2",
"name": "Wallet Two"
}
f_type: "Service",
f_vsn: "1.0.0",
type: "authz",
method: "IFRAME/RPC",
uid: "wallettwo#authn",
endpoint: "https://test.test",
provider: {
address: "0x2",
name: "Wallet Two",
},
}

const serviceThree = {
"f_type": "Service",
"f_vsn": "1.0.0",
"type": "authn",
"method": "IFRAME/RPC",
"uid": "walletthree#authn",
"endpoint": "https://test.test",
"provider": {
"address": "0x3",
"name": "Wallet Three"
}
f_type: "Service",
f_vsn: "1.0.0",
type: "authn",
method: "IFRAME/RPC",
uid: "walletthree#authn",
endpoint: "https://test.test",
provider: {
address: "0x3",
name: "Wallet Three",
},
}

const serviceFour = {
"f_type": "Service",
"f_vsn": "1.0.0",
"type": "authn",
"method": "IFRAME/RPC",
"uid": "walletfour#authn",
"endpoint": "https://test.test",
"optIn": true,
"provider": {
"address": "0x4",
"name": "Wallet Four"
}
f_type: "Service",
f_vsn: "1.0.0",
type: "authn",
method: "IFRAME/RPC",
uid: "walletfour#authn",
endpoint: "https://test.test",
optIn: true,
provider: {
address: "0x4",
name: "Wallet Four",
},
}

describe("getServices", () => {
Expand All @@ -61,7 +61,10 @@ describe("getServices", () => {
beforeEach(() => {
windowSpy = jest.spyOn(window, "window", "get")
configRef = config()
configRef.put("discovery.authn.endpoint", "https://fcl-discovery.onflow.org/api/testnet/authn")
configRef.put(
"discovery.authn.endpoint",
"https://fcl-discovery.onflow.org/api/testnet/authn"
)
})

afterEach(() => {
Expand All @@ -73,16 +76,18 @@ describe("getServices", () => {
const mockData = [serviceOne, serviceTwo]

windowSpy.mockImplementation(() => ({
fcl_extensions: [serviceThree]
fcl_extensions: [serviceThree],
}))

global.fetch = jest.fn(() => Promise.resolve({
json: () => Promise.resolve(mockData)
}))
global.fetch = jest.fn(() =>
Promise.resolve({
json: () => Promise.resolve(mockData),
})
)

const response = await getServices({ type: "authn" })
const response = await getServices({type: "authn"})
const expectedResponse = [serviceThree, serviceOne] // returns extensions first
expect(response.length).toEqual(2)
expect(response).toEqual(expectedResponse)
})
})
})
18 changes: 14 additions & 4 deletions packages/fcl/src/discovery/services/authn.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import {spawn, subscriber, snapshoter, INIT, SUBSCRIBE, UNSUBSCRIBE} from "@onflow/util-actor"
import {
spawn,
subscriber,
snapshoter,
INIT,
SUBSCRIBE,
UNSUBSCRIBE,
} from "@onflow/util-actor"
import {getServices} from "../services"

const NAME = "authn"
Expand All @@ -23,8 +30,11 @@ const warn = (fact, msg) => {

const HANDLERS = {
[INIT]: async ctx => {
warn(typeof window === "undefined", '"fcl.discovery" is only available in the browser.')
const services = await getServices({ type: NAME })
warn(
typeof window === "undefined",
'"fcl.discovery" is only available in the browser.'
)
const services = await getServices({type: NAME})
ctx.put(RESULTS, services)
},
[SUBSCRIBE]: (ctx, letter) => {
Expand All @@ -39,7 +49,7 @@ const spawnProviders = () => spawn(HANDLERS, NAME)

const authn = {
subscribe: cb => subscriber(NAME, spawnProviders, cb),
snapshot: () => snapshoter(NAME, spawnProviders)
snapshot: () => snapshoter(NAME, spawnProviders),
}

export default authn
2 changes: 1 addition & 1 deletion packages/protobuf/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export * from "./generated/flow/entities/transaction_pb_service.js"
export * from "./generated/flow/entities/transaction_pb.js"

export * from "./generated/flow/execution/execution_pb_service.js"
export * from "./generated/flow/execution/execution_pb.js"
export * from "./generated/flow/execution/execution_pb.js"
5 changes: 2 additions & 3 deletions packages/protobuf/src/index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
test("placeholder", () => {
expect(1).toBe(1)
})

expect(1).toBe(1)
})
20 changes: 10 additions & 10 deletions packages/protobuf/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const path = require('path');
const path = require("path")

module.exports = {
entry: './src/index.js',
target: 'node',
devtool: 'source-map',
entry: "./src/index.js",
target: "node",
devtool: "source-map",
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'index.js',
library: '',
libraryTarget: 'commonjs-module'
}
}
path: path.resolve(__dirname, "dist"),
filename: "index.js",
library: "",
libraryTarget: "commonjs-module",
},
}
3 changes: 2 additions & 1 deletion packages/sdk/src/account/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function account(address, {height, id} = {}, opts) {
if (id) return send([getAccount(address), atBlockId(id)], opts).then(decode)

// Get account by height
if (height) return send([getAccount(address), atBlockHeight(height)], opts).then(decode)
if (height)
return send([getAccount(address), atBlockHeight(height)], opts).then(decode)

return send([getAccount(address)], opts).then(decode)
}
3 changes: 1 addition & 2 deletions packages/sdk/src/account/account.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
test("placeholder", () => {
expect(0).toBe(0)
expect(0).toBe(0)
})

3 changes: 2 additions & 1 deletion packages/sdk/src/block/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function block({sealed = false, id, height} = {}, opts = {}) {
if (id) return send([getBlock(), atBlockId(id)], opts).then(decode)

// Get block by height
if (height) return send([getBlock(), atBlockHeight(height)], opts).then(decode)
if (height)
return send([getBlock(), atBlockHeight(height)], opts).then(decode)

// Get latest block
return send([getBlock(sealed)], opts).then(decode)
Expand Down
3 changes: 1 addition & 2 deletions packages/sdk/src/build/build-arguments.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
test("placeholder", () => {
expect(0).toBe(0)
expect(0).toBe(0)
})

12 changes: 9 additions & 3 deletions packages/sdk/src/build/build-at-block-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ export function atBlockId(id) {
return Ok(ix)
},
validator((ix, {Ok, Bad}) => {
if (isGetAccount(ix)) return Bad(ix, "Unable to specify a block id with a Get Account interaction.")
if (typeof ix.block.isSealed === "boolean") return Bad(ix, "Unable to specify both block id and isSealed.")
if (ix.block.height) return Bad(ix, "Unable to specify both block id and block height.")
if (isGetAccount(ix))
return Bad(
ix,
"Unable to specify a block id with a Get Account interaction."
)
if (typeof ix.block.isSealed === "boolean")
return Bad(ix, "Unable to specify both block id and isSealed.")
if (ix.block.height)
return Bad(ix, "Unable to specify both block id and block height.")
return Ok(ix)
}),
])
Expand Down
Loading

0 comments on commit aa31496

Please sign in to comment.