Skip to content

Commit f972721

Browse files
authored
Add HTTP/POST backchannel support (#198)
1 parent c148803 commit f972721

33 files changed

Lines changed: 3328 additions & 700 deletions

.env.development

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# FCL Dev Wallet Base URL
2-
BASE_URL=http://localhost:8701
3-
41
# The FCL Dev Wallet requires a single account to use as a base/starting point.
52
# This account will be used to create and manage other accounts.
63
# We recommend to use the service account defined in the flow.json file your emulator is using.

.env.example

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# FCL Dev Wallet Base URL
2-
BASE_URL=http://localhost:8701
3-
41
# The FCL Dev Wallet requires a single account to use as a base/starting point.
52
# This account will be used to create and manage other accounts.
63
# We recommend to use the service account definied in the flow.json file your emulator is using.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ yarn-error.log*
3636
.vercel
3737

3838
.idea
39-
/.env
39+
/.env

components/AccountForm.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function AccountForm({
7272
onSubmitComplete(address)
7373
}
7474
} catch (error) {
75+
throw error
7576
// TODO: Fix error string
7677
// setErrors([error])
7778
setSubmitting(false)

components/AccountsListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {chooseAccount} from "src/accountAuth"
99
import {formattedBalance} from "src/balance"
1010
import {Flex, Themed} from "theme-ui"
1111
import {SXStyles} from "types"
12-
import useConfig from "hooks/useConfig"
12+
import {getBaseUrl} from "src/utils"
1313

1414
const styles: SXStyles = {
1515
accountListItem: {
@@ -107,7 +107,7 @@ export default function AccountsListItem({
107107
app: {title},
108108
},
109109
} = connectedAppConfig
110-
const {baseUrl} = useConfig()
110+
const baseUrl = getBaseUrl()
111111

112112
const [scopes, setScopes] = useState<Set<string>>(new Set(account.scopes))
113113
const {data: accountData} = useAccount(account.address)

components/Dialog.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {useRef} from "react"
66
import {Box, Button} from "theme-ui"
77
import {SXStyles} from "types"
88
import ExpandCollapseButton from "./ExpandCollapseButton"
9+
import {getBaseUrl, isBackchannel, updatePollingSession} from "src/utils"
910

1011
export const styles: SXStyles = {
1112
dialog: {
@@ -90,8 +91,23 @@ export default function Dialog({
9091
root?: boolean
9192
children: React.ReactNode
9293
}) {
94+
const baseUrl = getBaseUrl()
9395
const closeButtonRef = useRef<HTMLButtonElement>(null)
94-
const onClose = () => WalletUtils.close()
96+
const onClose = () => {
97+
const declineResponse = {
98+
f_type: "PollingResponse",
99+
f_vsn: "1.0.0",
100+
status: "DECLINED",
101+
reason: "User declined",
102+
data: null,
103+
}
104+
105+
if (isBackchannel()) {
106+
updatePollingSession(baseUrl, declineResponse)
107+
} else {
108+
WalletUtils.sendMsgToFCL("FCL:VIEW:RESPONSE", declineResponse)
109+
}
110+
}
95111
const {isExpanded, setCodePreview} = useAuthzContext()
96112

97113
return (

contexts/AuthnRefreshContext.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {createContext, useEffect, useState} from "react"
2-
import {WalletUtils} from "@onflow/fcl"
32
import {parseScopes} from "src/scopes"
3+
import {useFclData} from "hooks/useFclData"
44

55
type AuthnRefreshContextType = {
66
address: string
@@ -17,13 +17,14 @@ export function AuthnRefreshContextProvider({
1717
}: {
1818
children: React.ReactNode
1919
}) {
20+
const fclData: any = useFclData()
2021
const [value, setValue] = useState<any>(null)
2122

2223
useEffect(() => {
23-
function callback(data: any) {
24-
const {timestamp, appDomainTag} = data.body
24+
if (fclData) {
25+
const {timestamp, appDomainTag} = fclData.body
2526

26-
const service = data.service
27+
const service = fclData.service
2728
const address = service?.data?.address
2829
const keyId = service?.data?.keyId
2930
const scopes = new Set(parseScopes(service?.params?.scopes))
@@ -36,9 +37,7 @@ export function AuthnRefreshContextProvider({
3637
appDomainTag,
3738
})
3839
}
39-
40-
WalletUtils.ready(callback)
41-
}, [])
40+
}, [fclData])
4241

4342
return (
4443
<AuthnRefreshContext.Provider value={value}>

contexts/AuthzContext.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import * as fcl from "@onflow/fcl"
22
import useAccounts from "hooks/useAccounts"
33
import {ConnectedAppConfig} from "hooks/useConnectedAppConfig"
44
import {Account} from "src/accounts"
5-
import React, {createContext, useEffect, useMemo, useState} from "react"
6-
import {WalletUtils} from "@onflow/fcl"
5+
import React, {createContext, useMemo, useState} from "react"
6+
import {useFclData} from "hooks/useFclData"
77

88
type AuthzReadyData = {
99
type: string
@@ -92,19 +92,15 @@ export const AuthzContext = createContext<AuthzContextType>({
9292
})
9393

9494
export function AuthzContextProvider({children}: {children: React.ReactNode}) {
95-
const [signable, setSignable] = useState<AuthSignable | null>(null)
95+
const signable = useFclData<AuthSignable>({
96+
transformFrontchannel: (data: AuthzReadyData) => {
97+
return data.body
98+
},
99+
})
96100
const [codePreview, setCodePreview] = useState<CodePreview | null>(null)
97101

98102
const {data: accountsData} = useAccounts()
99103

100-
useEffect(() => {
101-
function callback(data: AuthzReadyData) {
102-
setSignable(data.body)
103-
}
104-
105-
WalletUtils.ready(callback)
106-
}, [])
107-
108104
const accounts = useMemo(() => {
109105
if (!accountsData) return {}
110106
const hash: Record<string, Account> = {}

contexts/ConfigContext.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {Spinner} from "../components/Spinner"
44

55
interface RuntimeConfig {
66
flowAvatarUrl: string
7-
baseUrl: string
87
contractFungibleToken: string
98
contractFlowToken: string
109
contractFUSD: string
@@ -20,7 +19,6 @@ interface RuntimeConfig {
2019

2120
const defaultConfig = {
2221
flowAvatarUrl: process.env.flowAvatarUrl || "",
23-
baseUrl: process.env.baseUrl || "",
2422
contractFungibleToken: process.env.contractFungibleToken || "",
2523
contractFlowToken: process.env.contractFlowToken || "",
2624
contractFUSD: process.env.contractFUSD || "",

go.mod

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,27 @@ module github.com/onflow/fcl-dev-wallet
22

33
go 1.18
44

5-
require github.com/joho/godotenv v1.4.0
5+
require (
6+
github.com/gorilla/mux v1.8.0
7+
github.com/joho/godotenv v1.4.0
8+
github.com/spf13/cobra v1.7.0
9+
github.com/spf13/viper v1.16.0
10+
)
11+
12+
require (
13+
github.com/fsnotify/fsnotify v1.6.0 // indirect
14+
github.com/hashicorp/hcl v1.0.0 // indirect
15+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
16+
github.com/magiconair/properties v1.8.7 // indirect
17+
github.com/mitchellh/mapstructure v1.5.0 // indirect
18+
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
19+
github.com/spf13/afero v1.9.5 // indirect
20+
github.com/spf13/cast v1.5.1 // indirect
21+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
22+
github.com/spf13/pflag v1.0.5 // indirect
23+
github.com/subosito/gotenv v1.4.2 // indirect
24+
golang.org/x/sys v0.8.0 // indirect
25+
golang.org/x/text v0.9.0 // indirect
26+
gopkg.in/ini.v1 v1.67.0 // indirect
27+
gopkg.in/yaml.v3 v3.0.1 // indirect
28+
)

0 commit comments

Comments
 (0)