-
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 1 commit
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 {string} addr Flow Address | ||
* @param {number} keyId Key ID | ||
* @param {string} 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 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import {encodeAccountProof} from "./encode-account-proof.js" | ||
import {encodeAccountProof} from "./encode-account-proof" | ||
|
||
const address = "0xABC123DEF456" | ||
const appIdentifier = "AWESOME-APP-ID" | ||
|
@@ -22,14 +22,14 @@ describe("encode account proof", () => { | |
test("encode account proof with missing address", () => { | ||
expect.assertions(1) | ||
expect(() => { | ||
encodeAccountProof({nonce, appIdentifier}) | ||
encodeAccountProof({nonce, appIdentifier} as any) | ||
}).toThrow(Error) | ||
}) | ||
|
||
test("encode account proof with missing appIdentifier", () => { | ||
expect.assertions(1) | ||
expect(() => { | ||
encodeAccountProof({address, nonce}) | ||
encodeAccountProof({address, nonce} as any) | ||
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. Is this not 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. Updated and set AccountProofData with optional properties |
||
}).toThrow(Error) | ||
}) | ||
|
||
|
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,14 +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 | ||||
* @param {string} type Message type | ||||
* @param {PollingResponse} msg Message object | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
* @returns {void} | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
* | ||||
* @example | ||||
|
@@ -22,7 +28,10 @@ import {URL} from "../utils/url" | |||
* data: data, | ||||
* }) | ||||
*/ | ||||
export const sendMsgToFCL = (type, msg = {}) => { | ||||
export const sendMsgToFCL = ( | ||||
type: string, | ||||
msg: PollingResponse = {} as PollingResponse | ||||
jribbink marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
): void => { | ||||
const data = {...msg, type} | ||||
|
||||
const urlParams = new URLSearchParams(window.location.search) | ||||
|
@@ -41,75 +50,73 @@ 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 | ||||
* @param {Function} cb Callback function | ||||
* @param {PollingResponse} msg Message object | ||||
* @returns {void} | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
*/ | ||||
export const ready = (cb, msg = {}) => { | ||||
export const ready = ( | ||||
cb: (data: any, context: {origin: string}) => void, | ||||
msg: PollingResponse = {} 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.
Suggested change
Looks like 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. 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? |
||||
): void => { | ||||
onMessageFromFCL("FCL:VIEW:READY:RESPONSE", cb) | ||||
sendMsgToFCL("FCL:VIEW:READY") | ||||
} | ||||
|
||||
/** | ||||
* @description | ||||
* Sends "FCL:VIEW:CLOSE" | ||||
* @description Sends "FCL:VIEW:CLOSE" | ||||
* | ||||
* @returns {void} | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
*/ | ||||
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 | ||||
* @param {object} data Data object | ||||
* @returns {void} | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
*/ | ||||
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 | ||||
* @param {string} reason Reason for declining | ||||
* @returns {void} | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
*/ | ||||
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 | ||||
* @param {object} data Data object | ||||
* @returns {void} | ||||
mfbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
*/ | ||||
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) | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.