-
Notifications
You must be signed in to change notification settings - Fork 128
Refactored fcl-core interaction-template-utils folder files to TypeScript #2474
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
Open
mfbz
wants to merge
5
commits into
feature/typescript-fcl-core
Choose a base branch
from
mfbz/refactor-fcl-core-interaction-utils
base: feature/typescript-fcl-core
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0b3a90a
Completed refactoring of interaction-template-utils folder
mfbz 9731c62
Update packages/fcl-core/src/interaction-template-utils/generate-temp…
mfbz c619636
Merge branch 'feature/typescript-fcl-core' into mfbz/refactor-fcl-cor…
mfbz bc4c854
Improved dependency pin test
mfbz 9e6b330
Merge branch 'feature/typescript-fcl-core' into mfbz/refactor-fcl-cor…
mfbz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 0 additions & 49 deletions
49
...c/interaction-template-utils/derive-cadence-by-network/derive-cadence-by-network-1.0.0.js
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
...c/interaction-template-utils/derive-cadence-by-network/derive-cadence-by-network-1.0.0.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import {invariant} from "@onflow/util-invariant" | ||
import type {InteractionTemplate100} from "../interaction-template" | ||
|
||
export interface DeriveCadenceByNetwork100Params { | ||
network: string | ||
template: InteractionTemplate100 | ||
} | ||
|
||
/** | ||
* @description Fills import addresses in Cadence for network | ||
* | ||
* @param {DeriveCadenceByNetwork100Params} params | ||
* @param {string} params.network Network to derive Cadence for | ||
* @param {InteractionTemplate100} params.template Interaction Template to derive Cadence from | ||
* @returns {Promise<string>} Promise that resolves with the derived Cadence code | ||
*/ | ||
export async function deriveCadenceByNetwork100({ | ||
network, | ||
template, | ||
}: DeriveCadenceByNetwork100Params): Promise<string> { | ||
invariant( | ||
template.f_version === "1.0.0", | ||
"deriveCadenceByNetwork100({ template }) -- template must be version 1.0.0" | ||
) | ||
|
||
const networkDependencies: [string, string][] = Object.keys( | ||
template?.data?.dependencies | ||
).map((dependencyPlaceholder: string): [string, string] => { | ||
const dependencyNetworkContracts = Object.values( | ||
template?.data?.dependencies?.[dependencyPlaceholder] | ||
) | ||
|
||
invariant( | ||
dependencyNetworkContracts !== undefined, | ||
`deriveCadenceByNetwork100 -- Could not find contracts for dependency placeholder: ${dependencyPlaceholder}` | ||
) | ||
|
||
invariant( | ||
dependencyNetworkContracts.length > 0, | ||
`deriveCadenceByNetwork100 -- Could not find contracts for dependency placeholder: ${dependencyPlaceholder}` | ||
) | ||
|
||
const dependencyContract = dependencyNetworkContracts[0] | ||
const dependencyContractForNetwork = dependencyContract?.[network] | ||
|
||
invariant( | ||
dependencyContractForNetwork as any, | ||
`deriveCadenceByNetwork100 -- Could not find ${network} network information for dependency: ${dependencyPlaceholder}` | ||
) | ||
|
||
return [dependencyPlaceholder, dependencyContractForNetwork?.address] | ||
}) | ||
|
||
return networkDependencies.reduce( | ||
(cadence: string, [placeholder, address]: [string, string]) => { | ||
const regex = new RegExp("(\\b" + placeholder + "\\b)", "g") | ||
return cadence.replace(regex, address) | ||
}, | ||
template.data.cadence | ||
) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 16 additions & 7 deletions
23
...e-by-network/derive-cadence-by-network.js → ...e-by-network/derive-cadence-by-network.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.