-
Notifications
You must be signed in to change notification settings - Fork 128
Refactored fcl-core wallet-utils folder files to TypeScript #2478
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
Changes from 17 commits
3a6fcf5
1c0e12f
3d1d0a0
028adb5
5a3407a
923ee29
31831f7
4e716db
f89b10d
147b83e
c98d8d6
464dd57
dffc739
95817c7
70b5533
53d48f4
b66361a
b0cdbd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {withPrefix} from "@onflow/util-address" | ||
import {COMPOSITE_SIGNATURE_PRAGMA} from "../normalizers/service/__vsn" | ||
|
||
/** | ||
* @description Constructs a new CompositeSignature instance. | ||
* | ||
* @param addr Flow Address | ||
* @param keyId Key ID | ||
* @param signature Signature as a hex string | ||
*/ | ||
export class CompositeSignature { | ||
f_type: string | ||
f_vsn: string | ||
addr: string | ||
keyId: number | ||
signature: string | ||
|
||
constructor(addr: string, keyId: number | string, signature: string) { | ||
this.f_type = COMPOSITE_SIGNATURE_PRAGMA.f_type | ||
this.f_vsn = COMPOSITE_SIGNATURE_PRAGMA.f_vsn | ||
this.addr = withPrefix(addr) | ||
this.keyId = Number(keyId) | ||
this.signature = signature | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export { | ||
sendMsgToFCL, | ||
ready, | ||
close, | ||
approve, | ||
decline, | ||
redirect, | ||
} from "./send-msg-to-fcl" | ||
export {onMessageFromFCL} from "./on-message-from-fcl" | ||
export {encodeMessageFromSignable} from "@onflow/sdk" | ||
export {CompositeSignature} from "./CompositeSignature" | ||
export {encodeAccountProof} from "./encode-account-proof" | ||
export {injectExtService} from "./inject-ext-service" |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type {Service} from "@onflow/typedefs" | ||
|
||
export function injectExtService(service: Service): void { | ||
if (service.type === "authn" && service.endpoint != null) { | ||
if (!Array.isArray((window as any).fcl_extensions)) { | ||
;(window as any).fcl_extensions = [] | ||
} | ||
;(window as any).fcl_extensions.push(service) | ||
} else { | ||
console.warn("Authn service is required") | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,20 @@ import { | |
FCL_RESPONSE_PARAM_NAME, | ||
} from "../utils/constants" | ||
import {onMessageFromFCL} from "./on-message-from-fcl" | ||
import {URL} from "../utils/url" | ||
|
||
export interface PollingResponse { | ||
f_type: "PollingResponse" | ||
f_vsn: "1.0.0" | ||
status: "APPROVED" | "DECLINED" | "REDIRECT" | ||
reason: string | null | ||
data: any | ||
} | ||
|
||
/** | ||
* @description | ||
* Sends message to FCL window | ||
* @description Sends message to FCL window | ||
* | ||
* @param {string} type - Message type | ||
* @param {object} msg - Message object | ||
* @returns {void} | ||
* @param type Message type | ||
* @param msg Message object | ||
* | ||
* @example | ||
* sendMsgToFCL("FCL:VIEW:RESPONSE", { | ||
|
@@ -22,7 +27,7 @@ import {URL} from "../utils/url" | |
* data: data, | ||
* }) | ||
*/ | ||
export const sendMsgToFCL = (type, msg = {}) => { | ||
export const sendMsgToFCL = (type: string, msg?: PollingResponse): void => { | ||
const data = {...msg, type} | ||
|
||
const urlParams = new URLSearchParams(window.location.search) | ||
|
@@ -41,75 +46,67 @@ export const sendMsgToFCL = (type, msg = {}) => { | |
} | ||
|
||
/** | ||
* @description | ||
* Listens for "FCL:VIEW:READY:RESPONSE" and sends "FCL:VIEW:READY" | ||
* @description Listens for "FCL:VIEW:READY:RESPONSE" and sends "FCL:VIEW:READY" | ||
* | ||
* @param {Function} cb - Callback function | ||
* @param {object} msg - Message object | ||
* @returns {void} | ||
* @param cb Callback function | ||
* @param msg Message object | ||
*/ | ||
export const ready = (cb, msg = {}) => { | ||
export const ready = ( | ||
cb: (data: any, context: {origin: string}) => void, | ||
msg: PollingResponse = {} as PollingResponse | ||
): void => { | ||
onMessageFromFCL("FCL:VIEW:READY:RESPONSE", cb) | ||
sendMsgToFCL("FCL:VIEW:READY") | ||
} | ||
|
||
/** | ||
* @description | ||
* Sends "FCL:VIEW:CLOSE" | ||
* | ||
* @returns {void} | ||
* @description Sends "FCL:VIEW:CLOSE" | ||
*/ | ||
export const close = () => { | ||
export const close = (): void => { | ||
sendMsgToFCL("FCL:VIEW:CLOSE") | ||
} | ||
|
||
/** | ||
* @description | ||
* Sends "FCL:VIEW:RESPONSE" with status "APPROVED" | ||
* @description Sends "FCL:VIEW:RESPONSE" with status "APPROVED" | ||
* | ||
* @param {object} data - Data object | ||
* @returns {void} | ||
* @param data Data object | ||
*/ | ||
export const approve = data => { | ||
export const approve = (data: any): void => { | ||
sendMsgToFCL("FCL:VIEW:RESPONSE", { | ||
f_type: "PollingResponse", | ||
f_vsn: "1.0.0", | ||
status: "APPROVED", | ||
reason: null, | ||
data: data, | ||
}) | ||
} as PollingResponse) | ||
} | ||
|
||
/** | ||
* @description | ||
* Sends "FCL:VIEW:RESPONSE" with status "DECLINED" | ||
* @description Sends "FCL:VIEW:RESPONSE" with status "DECLINED" | ||
* | ||
* @param {string} reason - Reason for declining | ||
* @returns {void} | ||
* @param reason Reason for declining | ||
*/ | ||
export const decline = reason => { | ||
export const decline = (reason: string): void => { | ||
sendMsgToFCL("FCL:VIEW:RESPONSE", { | ||
f_type: "PollingResponse", | ||
f_vsn: "1.0.0", | ||
status: "DECLINED", | ||
reason: reason, | ||
data: null, | ||
}) | ||
} as PollingResponse) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these type assertions necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore, removed! |
||
} | ||
|
||
/** | ||
* @description | ||
* Sends "FCL:VIEW:RESPONSE" with status "REDIRECT" | ||
* @description Sends "FCL:VIEW:RESPONSE" with status "REDIRECT" | ||
* | ||
* @param {object} data - Data object | ||
* @returns {void} | ||
* @param data Data object | ||
*/ | ||
export const redirect = data => { | ||
export const redirect = (data: any): void => { | ||
sendMsgToFCL("FCL:VIEW:RESPONSE", { | ||
f_type: "PollingResponse", | ||
f_vsn: "1.0.0", | ||
status: "REDIRECT", | ||
reason: null, | ||
data: data, | ||
}) | ||
} as PollingResponse) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
msg
is unused here. IMO we should maybe just take this opportunity to drop it. The risk is that users could get type errors for this if they were passing an (unused) msg arg here, but functionally this should not break anything so I think it's worth it for the long term.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes to me it makes completely sense because it's useless. If we want to maintain backward compatibility we could still leave it but make it optional like it is done in the sendMsgToFCL method. What do you think?