mirror of
https://github.com/FlipsideCrypto/user_metrics.git
synced 2026-02-06 03:07:03 +00:00
Dynamic Integration for Flow (#19)
* first start * dynamic button works and posts to server, but gotta clean up * Cleanup * updating keys and last round of cleanup * package bundle * removing unused yarn files
This commit is contained in:
parent
fffef8486b
commit
c54bcfc559
6
apps/flow/dynamicWidget/.Rbuildignore
Normal file
6
apps/flow/dynamicWidget/.Rbuildignore
Normal file
@ -0,0 +1,6 @@
|
||||
^node_modules$
|
||||
^srcjs$
|
||||
^app\.R$
|
||||
^package\.json$
|
||||
^webpack\.config\.js$
|
||||
^yarn\.lock$
|
||||
1
apps/flow/dynamicWidget/.gitignore
vendored
Normal file
1
apps/flow/dynamicWidget/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
||||
16
apps/flow/dynamicWidget/DESCRIPTION
Normal file
16
apps/flow/dynamicWidget/DESCRIPTION
Normal file
@ -0,0 +1,16 @@
|
||||
Package: dynamicWidget
|
||||
Title: What the Package Does (One Line, Title Case)
|
||||
Version: 0.0.0.9000
|
||||
Authors@R:
|
||||
person("First", "Last", , "first.last@example.com", role = c("aut", "cre"),
|
||||
comment = c(ORCID = "YOUR-ORCID-ID"))
|
||||
Description: What the package does (one paragraph).
|
||||
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
|
||||
license
|
||||
Encoding: UTF-8
|
||||
Roxygen: list(markdown = TRUE)
|
||||
RoxygenNote: 7.2.3
|
||||
Imports:
|
||||
htmltools,
|
||||
reactR,
|
||||
shiny
|
||||
7
apps/flow/dynamicWidget/NAMESPACE
Normal file
7
apps/flow/dynamicWidget/NAMESPACE
Normal file
@ -0,0 +1,7 @@
|
||||
# Generated by roxygen2: do not edit by hand
|
||||
|
||||
export(dynamic_buttonInput)
|
||||
export(updateDynamic_buttonInput)
|
||||
importFrom(htmltools,htmlDependency)
|
||||
importFrom(htmltools,tags)
|
||||
importFrom(reactR,createReactShinyInput)
|
||||
34
apps/flow/dynamicWidget/R/dynamic_button.R
Normal file
34
apps/flow/dynamicWidget/R/dynamic_button.R
Normal file
@ -0,0 +1,34 @@
|
||||
#' Dynamic Button
|
||||
#'
|
||||
#' React Button for multi-wallet connect using Dynamic SDK
|
||||
#'
|
||||
#' @importFrom reactR createReactShinyInput
|
||||
#' @importFrom htmltools htmlDependency tags
|
||||
#'
|
||||
#' @export
|
||||
dynamic_buttonInput <- function(inputId) {
|
||||
reactR::createReactShinyInput(
|
||||
inputId,
|
||||
"dynamic_button",
|
||||
htmltools::htmlDependency(
|
||||
name = "dynamic_button-input",
|
||||
version = "1.0.0",
|
||||
src = "www/dynamicWidget/dynamic_button",
|
||||
package = "dynamicWidget",
|
||||
script = "dynamic_button.js"
|
||||
),
|
||||
"",
|
||||
list(), htmltools::tags$div
|
||||
)
|
||||
}
|
||||
|
||||
#' Dyanamic Button
|
||||
#'
|
||||
#' React Button for multi-wallet connect using Dynamic SDK
|
||||
#'
|
||||
#' @export
|
||||
updateDynamic_buttonInput <- function(session, inputId, value, configuration = NULL) {
|
||||
message <- list(value = value)
|
||||
if (!is.null(configuration)) message$configuration <- configuration
|
||||
session$sendInputMessage(inputId, message)
|
||||
}
|
||||
58
apps/flow/dynamicWidget/README.md
Normal file
58
apps/flow/dynamicWidget/README.md
Normal file
@ -0,0 +1,58 @@
|
||||
## setup:
|
||||
|
||||
1. Install R and dependencies
|
||||
|
||||
```
|
||||
brew install R
|
||||
brew install libgit2
|
||||
brew install freetype
|
||||
brew install harfbuzz fribidi
|
||||
brew install libtiff
|
||||
```
|
||||
|
||||
|
||||
2. Install required packages by running
|
||||
|
||||
```
|
||||
Rscript setup.R
|
||||
```
|
||||
|
||||
3. in the terminal create an R project with react?
|
||||
|
||||
```
|
||||
~ R
|
||||
> path <- file.path(getwd(), "flowAttestR")
|
||||
> usethis::create_package(path)
|
||||
> reactR::scaffoldReactShinyInput(
|
||||
"wallet_connect",
|
||||
list(
|
||||
"reactstrap" = "^8.9.0"
|
||||
)
|
||||
)
|
||||
> quit()
|
||||
Save workspace image? [y/n/c]: n
|
||||
yarn install
|
||||
|
||||
```
|
||||
## "exporting"
|
||||
|
||||
R doesn't call it that but that's what we're doing
|
||||
|
||||
```
|
||||
|
||||
cd <my library to export>
|
||||
yarn run webpack --mode=development
|
||||
R
|
||||
devtools::document()
|
||||
devtools::load_all()
|
||||
-or-
|
||||
devtools::install()
|
||||
```
|
||||
|
||||
|
||||
## Running
|
||||
|
||||
```
|
||||
cd <this directory>
|
||||
R -e "shiny::runApp('.')"
|
||||
```
|
||||
16
apps/flow/dynamicWidget/app.R
Normal file
16
apps/flow/dynamicWidget/app.R
Normal file
@ -0,0 +1,16 @@
|
||||
library(shiny)
|
||||
library(dynamicWidget)
|
||||
|
||||
ui <- fluidPage(
|
||||
titlePanel("reactR Input Example"),
|
||||
dynamic_buttonInput("textInput"),
|
||||
textOutput("textOutput")
|
||||
)
|
||||
|
||||
server <- function(input, output, session) {
|
||||
output$textOutput <- renderText({
|
||||
sprintf("You entered: %s", input$textInput)
|
||||
})
|
||||
}
|
||||
|
||||
shinyApp(ui, server)
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
11
apps/flow/dynamicWidget/man/dynamic_buttonInput.Rd
Normal file
11
apps/flow/dynamicWidget/man/dynamic_buttonInput.Rd
Normal file
@ -0,0 +1,11 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/dynamic_button.R
|
||||
\name{dynamic_buttonInput}
|
||||
\alias{dynamic_buttonInput}
|
||||
\title{Dynamic Button}
|
||||
\usage{
|
||||
dynamic_buttonInput(inputId)
|
||||
}
|
||||
\description{
|
||||
React Button for multi-wallet connect using Dynamic SDK
|
||||
}
|
||||
11
apps/flow/dynamicWidget/man/updateDynamic_buttonInput.Rd
Normal file
11
apps/flow/dynamicWidget/man/updateDynamic_buttonInput.Rd
Normal file
@ -0,0 +1,11 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/dynamic_button.R
|
||||
\name{updateDynamic_buttonInput}
|
||||
\alias{updateDynamic_buttonInput}
|
||||
\title{Dyanamic Button}
|
||||
\usage{
|
||||
updateDynamic_buttonInput(session, inputId, value, configuration = NULL)
|
||||
}
|
||||
\description{
|
||||
React Button for multi-wallet connect using Dynamic SDK
|
||||
}
|
||||
22
apps/flow/dynamicWidget/package.json
Normal file
22
apps/flow/dynamicWidget/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@dynamic-labs/sdk-react": "^0.15.0",
|
||||
"react": "^18.2.0",
|
||||
"reactstrap": "^8.9.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.2.0",
|
||||
"@babel/preset-env": "^7.2.0",
|
||||
"@babel/preset-react": "^7.0.0",
|
||||
"babel-loader": "^8.0.4",
|
||||
"css-loader": "^5.0.1",
|
||||
"style-loader": "^2.0.0",
|
||||
"webpack": "^4.27.1",
|
||||
"webpack-cli": "^3.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"watch": "webpack --watch",
|
||||
"build": "webpack"
|
||||
}
|
||||
}
|
||||
6
apps/flow/dynamicWidget/setup.R
Normal file
6
apps/flow/dynamicWidget/setup.R
Normal file
@ -0,0 +1,6 @@
|
||||
install.packages("languageserver", repos = "http://cran.us.r-project.org")
|
||||
install.packages("shiny", repos = "http://cran.us.r-project.org")
|
||||
install.packages("reactR", repos = "http://cran.us.r-project.org")
|
||||
install.packages("usethis", repos = "http://cran.us.r-project.org")
|
||||
install.packages("devtools", repos = "http://cran.us.r-project.org")
|
||||
install.packages("here", repos = "http://cran.us.r-project.org")
|
||||
26
apps/flow/dynamicWidget/srcjs/DynamicAppUser.jsx
Normal file
26
apps/flow/dynamicWidget/srcjs/DynamicAppUser.jsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { useDynamicContext } from "@dynamic-labs/sdk-react";
|
||||
import { Button } from "reactstrap";
|
||||
|
||||
const DynamicAppUser = (props) => {
|
||||
const { user } = useDynamicContext();
|
||||
|
||||
return (
|
||||
<>
|
||||
{user ? (
|
||||
<Button
|
||||
onClick={() =>
|
||||
props.setNewValue(
|
||||
user?.verifiedCredentials?.map((wallet) => wallet.address)
|
||||
)
|
||||
}
|
||||
>
|
||||
Update Score
|
||||
</Button>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default DynamicAppUser;
|
||||
39
apps/flow/dynamicWidget/srcjs/dynamic_button.jsx
Normal file
39
apps/flow/dynamicWidget/srcjs/dynamic_button.jsx
Normal file
@ -0,0 +1,39 @@
|
||||
import { reactShinyInput } from "reactR";
|
||||
import { DynamicContextProvider, DynamicWidget } from "@dynamic-labs/sdk-react";
|
||||
import DynamicAppUser from "./DynamicAppUser.jsx";
|
||||
import { Button } from "reactstrap";
|
||||
|
||||
const TextInput = ({ configuration, value, setValue }) => {
|
||||
return (
|
||||
<DynamicContextProvider
|
||||
settings={{
|
||||
appName: "FlowScored",
|
||||
multiWallet: true,
|
||||
environmentId: "c6ef9d8c-6b8d-441a-9f67-72b728cef538",
|
||||
eventsCallbacks: {
|
||||
onAuthSuccess: (args) => {
|
||||
console.log("onAuthSuccess was called", args);
|
||||
if (args?.isAuthenticated) {
|
||||
setValue(
|
||||
args?.user?.verifiedCredentials?.map((wallet) => wallet.address)
|
||||
);
|
||||
}
|
||||
},
|
||||
onLinkSuccess: (args) => {
|
||||
console.log("onLinkSuccess was called", args);
|
||||
if (args?.isAuthenticated) {
|
||||
setValue(
|
||||
args?.user?.verifiedCredentials?.map((wallet) => wallet.address)
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
<DynamicWidget />
|
||||
<DynamicAppUser setNewValue={setValue} />
|
||||
</DynamicContextProvider>
|
||||
);
|
||||
};
|
||||
|
||||
reactShinyInput(".dynamic_button", "dynamicWidget.dynamic_button", TextInput);
|
||||
34
apps/flow/dynamicWidget/webpack.config.js
Normal file
34
apps/flow/dynamicWidget/webpack.config.js
Normal file
@ -0,0 +1,34 @@
|
||||
var path = require('path');
|
||||
|
||||
module.exports = {
|
||||
entry: path.join(__dirname, 'srcjs', 'dynamic_button.jsx'),
|
||||
output: {
|
||||
path: path.join(__dirname, 'inst/www/dynamicWidget/dynamic_button'),
|
||||
filename: 'dynamic_button.js'
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.jsx?$/,
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env', '@babel/preset-react']
|
||||
}
|
||||
},
|
||||
// For CSS so that import "path/style.css"; works
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: ['style-loader', 'css-loader']
|
||||
}
|
||||
]
|
||||
},
|
||||
externals: {
|
||||
'react': 'window.React',
|
||||
'react-dom': 'window.ReactDOM',
|
||||
'reactR': 'window.reactR'
|
||||
},
|
||||
stats: {
|
||||
colors: true
|
||||
},
|
||||
devtool: 'source-map'
|
||||
};
|
||||
7620
apps/flow/dynamicWidget/yarn.lock
Normal file
7620
apps/flow/dynamicWidget/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
BIN
apps/flow/dynamicWidget_0.0.0.9000.tar.gz
Normal file
BIN
apps/flow/dynamicWidget_0.0.0.9000.tar.gz
Normal file
Binary file not shown.
16
apps/flow/shinyapp/app.R
Normal file
16
apps/flow/shinyapp/app.R
Normal file
@ -0,0 +1,16 @@
|
||||
library(shiny)
|
||||
library(dynamicWidget)
|
||||
|
||||
|
||||
ui <- fluidPage(
|
||||
titlePanel("dynamic test"),
|
||||
dynamic_buttonInput("my_wallet")
|
||||
)
|
||||
|
||||
# Define server logic to plot various variables against mpg ----
|
||||
server <- function(input, output) {
|
||||
observeEvent(input$my_wallet, {
|
||||
print(input$my_wallet)
|
||||
})
|
||||
}
|
||||
shinyApp(ui, server)
|
||||
@ -23,4 +23,4 @@ WalletHandler <- function(inputId, chainId, default = "") {
|
||||
),
|
||||
htmltools::tags$div
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user