-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* display all flix templates * improve flix name formatting * format template source code * improve template filtering * run format * fix source detection * small refactor * show verified by flix ui, move flix hooks to hooks/flix * search interaction names in lowercase * wrap "open in ide" section in gray card * first pass at non-verified state * fix hidden trash icons due to long labels * fix emulator flix template retrieval onflowser/flow-interaction-template-service#4 * update comment * disable polling of flix templates * update to "any" network name * stop retrying on error * show argument descriptions * use interaction definition instead of template for searching flix * fix transformation to new import syntax * use flowser flix api url * update comment * consolidate verified/unverified layout
- Loading branch information
1 parent
dca4f84
commit af41c5d
Showing
16 changed files
with
412 additions
and
87 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,79 @@ | ||
import useSWR, { SWRResponse } from "swr"; | ||
|
||
// https://github.com/onflow/flips/blob/main/application/20220503-interaction-templates.md#interaction-interfaces | ||
export type FlixTemplate = { | ||
id: string; | ||
f_type: "InteractionTemplate"; | ||
f_version: string; | ||
data: { | ||
messages: FlixMessages; | ||
dependencies: Record<string, FlixDependency>; | ||
cadence: string; | ||
arguments: Record<string, FlixArgument>; | ||
}; | ||
}; | ||
|
||
export type FlixArgument = { | ||
index: number; | ||
type: string; | ||
messages: FlixMessages; | ||
} | ||
|
||
type FlixDependency = Record< | ||
string, | ||
{ | ||
mainnet: FlixDependencyOnNetwork; | ||
testnet: FlixDependencyOnNetwork; | ||
} | ||
>; | ||
|
||
type FlixDependencyOnNetwork = { | ||
address: string; | ||
fq_address: string; | ||
pin: string; | ||
pin_block_height: number; | ||
}; | ||
|
||
type FlixMessages = { | ||
title?: FlixI18nMessage; | ||
description?: FlixI18nMessage; | ||
}; | ||
|
||
type FlixI18nMessage = { | ||
i18n: { | ||
"en-US"?: string; | ||
}; | ||
}; | ||
|
||
export const FLOW_FLIX_URL = "https://flix.flow.com"; | ||
export const FLOWSER_FLIX_URL = "https://flowser-flix-368a32c94da2.herokuapp.com" | ||
|
||
export function useListFlixTemplates(): SWRResponse<FlixTemplate[]> { | ||
return useSWR(`flix/templates`, () => | ||
fetch(`${FLOWSER_FLIX_URL}/v1/templates`).then((res) => res.json()), | ||
); | ||
} | ||
|
||
export function useFlixSearch(options: { | ||
sourceCode: string; | ||
// Supports "any" network as of: | ||
// https://github.com/onflowser/flow-interaction-template-service/pull/4 | ||
network: "any" | "testnet" | "mainnet"; | ||
}): SWRResponse<FlixTemplate | undefined> { | ||
return useSWR(`flix/templates/${options.sourceCode}`, () => | ||
fetch(`${FLOWSER_FLIX_URL}/v1/templates/search`, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify({ | ||
cadence_base64: btoa(options.sourceCode), | ||
network: options.network | ||
}) | ||
}).then((res) => res.json()), | ||
{ | ||
refreshInterval: 0, | ||
shouldRetryOnError: false | ||
} | ||
); | ||
} |
This file contains 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 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 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.