diff --git a/package-lock.json b/package-lock.json index f7ffbcfc3..bfcda4586 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5288,6 +5288,12 @@ "version": "2.0.3", "license": "MIT" }, + "node_modules/@types/uuid": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.6.tgz", + "integrity": "sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew==", + "dev": true + }, "node_modules/@types/yargs": { "version": "17.0.24", "dev": true, @@ -20453,6 +20459,7 @@ "devDependencies": { "@onflow/fcl-bundle": "^1.4.0-typescript.0", "@onflow/typedefs": "^1.2.0-typescript.0", + "@types/uuid": "^9.0.6", "eslint": "^8.35.0", "eslint-plugin-jsdoc": "^40.0.1", "jest": "^29.5.0", diff --git a/packages/sdk/package.json b/packages/sdk/package.json index ec29f38c2..e15a7b198 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -20,6 +20,7 @@ "devDependencies": { "@onflow/fcl-bundle": "^1.4.0-typescript.0", "@onflow/typedefs": "^1.2.0-typescript.0", + "@types/uuid": "^9.0.6", "eslint": "^8.35.0", "eslint-plugin-jsdoc": "^40.0.1", "jest": "^29.5.0", diff --git a/packages/sdk/src/interaction/interaction.ts b/packages/sdk/src/interaction/interaction.ts index f4c73c4d9..bff08fbf2 100644 --- a/packages/sdk/src/interaction/interaction.ts +++ b/packages/sdk/src/interaction/interaction.ts @@ -105,11 +105,11 @@ export const interaction = () => { return initInteraction() } -export const isNumber = d => typeof d === "number" -export const isArray = d => Array.isArray(d) -export const isObj = d => d !== null && typeof d === "object" -export const isNull = d => d == null -export const isFn = d => typeof d === "function" +export const isNumber = (d: any): d is number => typeof d === "number" +export const isArray = (d: any): d is any[] => Array.isArray(d) +export const isObj = (d: any): d is Record => d !== null && typeof d === "object" +export const isNull = (d: any): d is null => d == null +export const isFn = (d: any): d is Function => typeof d === "function" export const isInteraction = (ix: IIx) => { if (!isObj(ix) || isNull(ix) || isNumber(ix)) return false @@ -198,7 +198,7 @@ export const prepAccount = (acct: IAcct | IAcctFn, opts: IPrepAccountOpts = {}) return ix } -export const makeArgument = arg => ix => { +export const makeArgument = (arg: Record) => (ix: IIx) => { let tempId = uuidv4() ix.message.arguments.push(tempId) diff --git a/packages/sdk/src/resolve/resolve-accounts.ts b/packages/sdk/src/resolve/resolve-accounts.ts index 6101c1792..856fd10cb 100644 --- a/packages/sdk/src/resolve/resolve-accounts.ts +++ b/packages/sdk/src/resolve/resolve-accounts.ts @@ -25,9 +25,9 @@ const ROLES = { function debug() { const SPACE = " " const SPACE_COUNT_PER_INDENT = 4 - const DEBUG_MESSAGE = [] + const DEBUG_MESSAGE: string[] = [] return [ - function (msg, indent = 0) { + function (msg = '', indent = 0) { DEBUG_MESSAGE.push( Array(indent * SPACE_COUNT_PER_INDENT) .fill(SPACE) @@ -40,7 +40,7 @@ function debug() { ] } -function recurseFlatMap(el, depthLimit = 3) { +function recurseFlatMap(el: T, depthLimit = 3) { if (depthLimit <= 0) return el if (!Array.isArray(el)) return el return recurseFlatMap( @@ -67,12 +67,14 @@ export function buildPreSignable(acct: IAcct, ix: IIx) { } } -async function removeUnusedIxAccounts(ix: IIx) { +async function removeUnusedIxAccounts(ix: IIx, opts: Record) { const payerTempIds = Array.isArray(ix.payer) ? ix.payer : [ix.payer] const authorizersTempIds = Array.isArray(ix.authorizations) ? ix.authorizations : [ix.authorizations] - const proposerTempIds = Array.isArray(ix.proposer) + const proposerTempIds = ix.proposer === null + ? [] + : Array.isArray(ix.proposer) ? ix.proposer : [ix.proposer] @@ -115,7 +117,7 @@ function addAccountToIx(ix, newAccount) { return ix.accounts[newAccount.tempId] } -function uniqueAccountsFlatMap(accounts) { +function uniqueAccountsFlatMap(accounts: IAcct[]) { const flatMapped = recurseFlatMap(accounts) const seen = new Set() @@ -132,7 +134,7 @@ function uniqueAccountsFlatMap(accounts) { seen.add(accountId) return account }) - .filter(e => e !== null) + .filter(e => e !== null) as IAcct[] return uniqueAccountsFlatMapped } @@ -214,7 +216,7 @@ async function recurseResolveAccount( return account.tempId } -async function resolveAccountType(ix, type, {debugLogger}) { +async function resolveAccountType(ix: IIx, type, {debugLogger}) { invariant( ix && typeof ix === "object", "resolveAccountType Error: ix not defined" @@ -228,10 +230,10 @@ async function resolveAccountType(ix, type, {debugLogger}) { let accountTempIDs = Array.isArray(ix[type]) ? ix[type] : [ix[type]] - let allResolvedAccounts = [] + let allResolvedAccounts: IAcct[] = [] for (let accountId of accountTempIDs) { let account = ix.accounts[accountId] - invariant(account, `resolveAccountType Error: account not found`) + invariant(Boolean(account), `resolveAccountType Error: account not found`) let resolvedAccountTempIds = await recurseResolveAccount( ix, @@ -246,8 +248,8 @@ async function resolveAccountType(ix, type, {debugLogger}) { ? resolvedAccountTempIds : [resolvedAccountTempIds] - let resolvedAccounts = resolvedAccountTempIds.map( - resolvedAccountTempId => ix.accounts[resolvedAccountTempId] + let resolvedAccounts: IAcct[] = resolvedAccountTempIds.map( + (resolvedAccountTempId: string) => ix.accounts[resolvedAccountTempId] ) let flatResolvedAccounts = uniqueAccountsFlatMap(resolvedAccounts) @@ -295,7 +297,7 @@ async function resolveAccountType(ix, type, {debugLogger}) { } } -export async function resolveAccounts(ix: IIx, opts = {}) { +export async function resolveAccounts(ix: IIx, opts: Record = {}) { if (isTransaction(ix)) { if (!Array.isArray(ix.payer)) { log.deprecate({