@ -2,7 +2,30 @@ import React from 'react'
import { bufferToHex } from '@ethereumjs/util'
import { bufferToHex } from '@ethereumjs/util'
import { hash } from '@remix-project/remix-lib'
import { hash } from '@remix-project/remix-lib'
import axios , { AxiosResponse } from 'axios'
import axios , { AxiosResponse } from 'axios'
import { addInputFieldSuccess , cloneRepositoryFailed , cloneRepositoryRequest , cloneRepositorySuccess , createWorkspaceError , createWorkspaceRequest , createWorkspaceSuccess , displayNotification , displayPopUp , fetchWorkspaceDirectoryError , fetchWorkspaceDirectoryRequest , fetchWorkspaceDirectorySuccess , hideNotification , setCurrentWorkspace , setCurrentWorkspaceBranches , setCurrentWorkspaceCurrentBranch , setDeleteWorkspace , setMode , setReadOnlyMode , setRenameWorkspace , setCurrentWorkspaceIsGitRepo , setGitConfig } from './payload'
import {
addInputFieldSuccess ,
cloneRepositoryFailed ,
cloneRepositoryRequest ,
cloneRepositorySuccess ,
createWorkspaceError ,
createWorkspaceRequest ,
createWorkspaceSuccess ,
displayNotification ,
displayPopUp ,
fetchWorkspaceDirectoryError ,
fetchWorkspaceDirectoryRequest ,
fetchWorkspaceDirectorySuccess ,
hideNotification ,
setCurrentWorkspace ,
setCurrentWorkspaceBranches ,
setCurrentWorkspaceCurrentBranch ,
setDeleteWorkspace ,
setMode ,
setReadOnlyMode ,
setRenameWorkspace ,
setCurrentWorkspaceIsGitRepo ,
setGitConfig ,
} from './payload'
import { addSlash , checkSlash , checkSpecialChars } from '@remix-ui/helper'
import { addSlash , checkSlash , checkSpecialChars } from '@remix-ui/helper'
import { FileTree , JSONStandardInput , WorkspaceTemplate } from '../types'
import { FileTree , JSONStandardInput , WorkspaceTemplate } from '../types'
@ -16,14 +39,15 @@ import { AppModal, ModalTypes } from '@remix-ui/app'
import { contractDeployerScripts , etherscanScripts } from '@remix-project/remix-ws-templates'
import { contractDeployerScripts , etherscanScripts } from '@remix-project/remix-ws-templates'
declare global {
declare global {
interface Window { remixFileSystemCallback : IndexedDBStorage ; }
interface Window {
remixFileSystemCallback : IndexedDBStorage
}
}
}
const LOCALHOST = ' - connect to localhost - '
const LOCALHOST = ' - connect to localhost - '
const NO_WORKSPACE = ' - none - '
const NO_WORKSPACE = ' - none - '
const queryParams = new QueryParams ( )
const queryParams = new QueryParams ( )
const _paq = window . _paq = window . _paq || [ ] //eslint-disable-line
const _paq = ( window . _paq = window . _paq || [ ] ) //eslint-disable-line
let plugin , dispatch : React.Dispatch < any >
let plugin , dispatch : React.Dispatch < any >
export const setPlugin = ( filePanelPlugin , reducerDispatch ) = > {
export const setPlugin = ( filePanelPlugin , reducerDispatch ) = > {
@ -70,19 +94,29 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?:
} )
} )
} )
} )
promise . then ( ( files ) = > {
promise
. then ( ( files ) = > {
dispatch ( addInputFieldSuccess ( path , files , type ) )
dispatch ( addInputFieldSuccess ( path , files , type ) )
} ) . catch ( ( error ) = > {
} )
. catch ( ( error ) = > {
console . error ( error )
console . error ( error )
} )
} )
return promise
return promise
}
}
const removeSlash = ( s : string ) = > {
const removeSlash = ( s : string ) = > {
return s . replace ( /^\/+/ , "" )
return s . replace ( /^\/+/ , '' )
}
}
export const createWorkspace = async ( workspaceName : string , workspaceTemplateName : WorkspaceTemplate , opts = null , isEmpty = false , cb ? : ( err : Error , result? : string | number | boolean | Record < string , any > ) = > void , isGitRepo : boolean = false , createCommit : boolean = true ) = > {
export const createWorkspace = async (
workspaceName : string ,
workspaceTemplateName : WorkspaceTemplate ,
opts = null ,
isEmpty = false ,
cb ? : ( err : Error , result? : string | number | boolean | Record < string , any > ) = > void ,
isGitRepo : boolean = false ,
createCommit : boolean = true
) = > {
await plugin . fileManager . closeAllFiles ( )
await plugin . fileManager . closeAllFiles ( )
const promise = createWorkspaceTemplate ( workspaceName , workspaceTemplateName )
const promise = createWorkspaceTemplate ( workspaceName , workspaceTemplateName )
dispatch ( createWorkspaceRequest ( ) )
dispatch ( createWorkspaceRequest ( ) )
@ -121,7 +155,7 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
await plugin . call ( 'dGitProvider' , 'commit' , {
await plugin . call ( 'dGitProvider' , 'commit' , {
author : {
author : {
name ,
name ,
email
email ,
} ,
} ,
message : ` Initial commit: remix template ${ workspaceTemplateName } ` ,
message : ` Initial commit: remix template ${ workspaceTemplateName } ` ,
} )
} )
@ -138,7 +172,6 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
}
}
if ( workspaceTemplateName === 'semaphore' ) {
if ( workspaceTemplateName === 'semaphore' ) {
const isCircomActive = await plugin . call ( 'manager' , 'isActive' , 'circuit-compiler' )
const isCircomActive = await plugin . call ( 'manager' , 'isActive' , 'circuit-compiler' )
if ( ! isCircomActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'circuit-compiler' )
if ( ! isCircomActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'circuit-compiler' )
}
}
// this call needs to be here after the callback because it calls dGitProvider which also calls this function and that would cause an infinite loop
// this call needs to be here after the callback because it calls dGitProvider which also calls this function and that would cause an infinite loop
@ -153,18 +186,17 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
export const createWorkspaceTemplate = async ( workspaceName : string , template : WorkspaceTemplate = 'remixDefault' ) = > {
export const createWorkspaceTemplate = async ( workspaceName : string , template : WorkspaceTemplate = 'remixDefault' ) = > {
if ( ! workspaceName ) throw new Error ( 'workspace name cannot be empty' )
if ( ! workspaceName ) throw new Error ( 'workspace name cannot be empty' )
if ( checkSpecialChars ( workspaceName ) || checkSlash ( workspaceName ) ) throw new Error ( 'special characters are not allowed' )
if ( checkSpecialChars ( workspaceName ) || checkSlash ( workspaceName ) ) throw new Error ( 'special characters are not allowed' )
if ( await workspaceExists ( workspaceName ) && template === 'remixDefault' ) throw new Error ( 'workspace already exists' )
if ( ( await workspaceExists ( workspaceName ) ) && template === 'remixDefault' ) throw new Error ( 'workspace already exists' )
else {
else {
const workspaceProvider = plugin . fileProviders . workspace
const workspaceProvider = plugin . fileProviders . workspace
await workspaceProvider . createWorkspace ( workspaceName )
await workspaceProvider . createWorkspace ( workspaceName )
}
}
}
}
export type UrlParametersType = {
export type UrlParametersType = {
gist : string ,
gist : string
code : string ,
code : string
url : string ,
url : string
language : string
language : string
}
}
@ -176,7 +208,8 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
case 'code-template' :
case 'code-template' :
// creates a new workspace code-sample and loads code from url params.
// creates a new workspace code-sample and loads code from url params.
try {
try {
let path = '' ; let content
let path = ''
let content
if ( params . code ) {
if ( params . code ) {
const hashed = bufferToHex ( hash . keccakFromString ( params . code ) )
const hashed = bufferToHex ( hash . keccakFromString ( params . code ) )
@ -193,7 +226,7 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
try {
try {
content = JSON . parse ( content ) as any
content = JSON . parse ( content ) as any
if ( content . language && content . language === "Solidity" && content . sources ) {
if ( content . language && content . language === 'Solidity' && content . sources ) {
const standardInput : JSONStandardInput = content as JSONStandardInput
const standardInput : JSONStandardInput = content as JSONStandardInput
for ( const [ fname , source ] of Object . entries ( standardInput . sources ) ) {
for ( const [ fname , source ] of Object . entries ( standardInput . sources ) ) {
await workspaceProvider . set ( fname , source . content )
await workspaceProvider . set ( fname , source . content )
@ -221,7 +254,18 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
const data = response . data as { files : any }
const data = response . data as { files : any }
if ( ! data . files ) {
if ( ! data . files ) {
return dispatch ( displayNotification ( 'Gist load error' , 'No files found' , 'OK' , null , ( ) = > { dispatch ( hideNotification ( ) ) } , null ) )
return dispatch (
displayNotification (
'Gist load error' ,
'No files found' ,
'OK' ,
null ,
( ) = > {
dispatch ( hideNotification ( ) )
} ,
null
)
)
}
}
const obj = { }
const obj = { }
@ -232,11 +276,22 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
} )
} )
plugin . fileManager . setBatchFiles ( obj , 'workspace' , true , ( errorLoadingFile ) = > {
plugin . fileManager . setBatchFiles ( obj , 'workspace' , true , ( errorLoadingFile ) = > {
if ( errorLoadingFile ) {
if ( errorLoadingFile ) {
dispatch ( displayNotification ( '' , errorLoadingFile . message || errorLoadingFile , 'OK' , null , ( ) = > { } , null ) )
dispatch ( displayNotification ( '' , errorLoadingFile . message || errorLoadingFile , 'OK' , null , ( ) = > { } , null ) )
}
}
} )
} )
} catch ( e ) {
} catch ( e ) {
dispatch ( displayNotification ( 'Gist load error' , e . message , 'OK' , null , ( ) = > { dispatch ( hideNotification ( ) ) } , null ) )
dispatch (
displayNotification (
'Gist load error' ,
e . message ,
'OK' ,
null ,
( ) = > {
dispatch ( hideNotification ( ) )
} ,
null
)
)
console . error ( e )
console . error ( e )
}
}
break
break
@ -256,7 +311,18 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
}
}
}
}
} catch ( e ) {
} catch ( e ) {
dispatch ( displayNotification ( 'Workspace load error' , e . message , 'OK' , null , ( ) = > { dispatch ( hideNotification ( ) ) } , null ) )
dispatch (
displayNotification (
'Workspace load error' ,
e . message ,
'OK' ,
null ,
( ) = > {
dispatch ( hideNotification ( ) )
} ,
null
)
)
console . error ( e )
console . error ( e )
}
}
break
break
@ -277,15 +343,16 @@ export const fetchWorkspaceDirectory = async (path: string) => {
const promise : Promise < FileTree > = new Promise ( ( resolve ) = > {
const promise : Promise < FileTree > = new Promise ( ( resolve ) = > {
provider . resolveDirectory ( path , ( error , fileTree : FileTree ) = > {
provider . resolveDirectory ( path , ( error , fileTree : FileTree ) = > {
if ( error ) console . error ( error )
if ( error ) console . error ( error )
resolve ( fileTree )
resolve ( fileTree )
} )
} )
} )
} )
dispatch ( fetchWorkspaceDirectoryRequest ( ) )
dispatch ( fetchWorkspaceDirectoryRequest ( ) )
promise . then ( ( fileTree ) = > {
promise
. then ( ( fileTree ) = > {
dispatch ( fetchWorkspaceDirectorySuccess ( path , fileTree ) )
dispatch ( fetchWorkspaceDirectorySuccess ( path , fileTree ) )
} ) . catch ( ( error ) = > {
} )
. catch ( ( error ) = > {
dispatch ( fetchWorkspaceDirectoryError ( error . message ) )
dispatch ( fetchWorkspaceDirectoryError ( error . message ) )
} )
} )
return promise
return promise
@ -295,6 +362,7 @@ export const renameWorkspace = async (oldName: string, workspaceName: string, cb
await renameWorkspaceFromProvider ( oldName , workspaceName )
await renameWorkspaceFromProvider ( oldName , workspaceName )
await dispatch ( setRenameWorkspace ( oldName , workspaceName ) )
await dispatch ( setRenameWorkspace ( oldName , workspaceName ) )
await plugin . setWorkspace ( { name : workspaceName , isLocalhost : false } )
await plugin . setWorkspace ( { name : workspaceName , isLocalhost : false } )
await plugin . deleteWorkspace ( oldName )
await plugin . workspaceRenamed ( oldName , workspaceName )
await plugin . workspaceRenamed ( oldName , workspaceName )
cb && cb ( null , workspaceName )
cb && cb ( null , workspaceName )
}
}
@ -319,7 +387,9 @@ export const deleteWorkspace = async (workspaceName: string, cb?: (err: Error, r
}
}
export const deleteAllWorkspaces = async ( ) = > {
export const deleteAllWorkspaces = async ( ) = > {
await ( await getWorkspaces ( ) ) . map ( async workspace = > {
await (
await getWorkspaces ( )
) . map ( async ( workspace ) = > {
await deleteWorkspaceFromProvider ( workspace . name )
await deleteWorkspaceFromProvider ( workspace . name )
await dispatch ( setDeleteWorkspace ( workspace . name ) )
await dispatch ( setDeleteWorkspace ( workspace . name ) )
plugin . workspaceDeleted ( workspace . name )
plugin . workspaceDeleted ( workspace . name )
@ -356,7 +426,6 @@ export const switchToWorkspace = async (name: string) => {
if ( isGitRepo ) {
if ( isGitRepo ) {
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
}
}
dispatch ( setMode ( 'browser' ) )
dispatch ( setMode ( 'browser' ) )
@ -370,18 +439,18 @@ const loadFile = (name, file, provider, cb?): void => {
fileReader . onload = async function ( event ) {
fileReader . onload = async function ( event ) {
if ( checkSpecialChars ( file . name ) ) {
if ( checkSpecialChars ( file . name ) ) {
return dispatch ( displayNotification ( 'File Upload Failed' , 'Special characters are not allowed' , 'Close' , null , async ( ) = > { } ) )
return dispatch ( displayNotification ( 'File Upload Failed' , 'Special characters are not allowed' , 'Close' , null , async ( ) = > { } ) )
}
}
try {
try {
await provider . set ( name , event . target . result )
await provider . set ( name , event . target . result )
} catch ( error ) {
} catch ( error ) {
return dispatch ( displayNotification ( 'File Upload Failed' , 'Failed to create file ' + name , 'Close' , null , async ( ) = > { } ) )
return dispatch ( displayNotification ( 'File Upload Failed' , 'Failed to create file ' + name , 'Close' , null , async ( ) = > { } ) )
}
}
const config = plugin . registry . get ( 'config' ) . api
const config = plugin . registry . get ( 'config' ) . api
const editor = plugin . registry . get ( 'editor' ) . api
const editor = plugin . registry . get ( 'editor' ) . api
if ( ( config . get ( 'currentFile' ) === name ) && ( editor . currentContent ( ) !== event . target . result ) ) {
if ( config . get ( 'currentFile' ) === name && editor . currentContent ( ) !== event . target . result ) {
editor . setText ( name , event . target . result )
editor . setText ( name , event . target . result )
}
}
}
}
@ -394,11 +463,11 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
// the files module. Please ask the user here if they want to overwrite
// the files module. Please ask the user here if they want to overwrite
// a file and then just use `files.add`. The file explorer will
// a file and then just use `files.add`. The file explorer will
// pick that up via the 'fileAdded' event from the files module.
// pick that up via the 'fileAdded' event from the files module.
[ . . . target . files ] . forEach ( async ( file ) = > {
; [ . . . target . files ] . forEach ( async ( file ) = > {
const workspaceProvider = plugin . fileProviders . workspace
const workspaceProvider = plugin . fileProviders . workspace
const name = targetFolder === '/' ? file . name : ` ${ targetFolder } / ${ file . name } `
const name = targetFolder === '/' ? file . name : ` ${ targetFolder } / ${ file . name } `
if ( ! await workspaceProvider . exists ( name ) ) {
if ( ! ( await workspaceProvider . exists ( name ) ) ) {
loadFile ( name , file , workspaceProvider , cb )
loadFile ( name , file , workspaceProvider , cb )
} else {
} else {
const modalContent : AppModal = {
const modalContent : AppModal = {
@ -412,7 +481,7 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
loadFile ( name , file , workspaceProvider , cb )
loadFile ( name , file , workspaceProvider , cb )
} ,
} ,
cancelFn : ( ) = > { } ,
cancelFn : ( ) = > { } ,
hideFn : ( ) = > { }
hideFn : ( ) = > { } ,
}
}
plugin . call ( 'notification' , 'modal' , modalContent )
plugin . call ( 'notification' , 'modal' , modalContent )
}
}
@ -420,10 +489,10 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
}
}
export const uploadFolder = async ( target , targetFolder : string , cb ? : ( err : Error , result? : string | number | boolean | Record < string , any > ) = > void ) = > {
export const uploadFolder = async ( target , targetFolder : string , cb ? : ( err : Error , result? : string | number | boolean | Record < string , any > ) = > void ) = > {
for ( const file of [ . . . target . files ] ) {
for ( const file of [ . . . target . files ] ) {
const workspaceProvider = plugin . fileProviders . workspace
const workspaceProvider = plugin . fileProviders . workspace
const name = targetFolder === '/' ? file . webkitRelativePath : ` ${ targetFolder } / ${ file . webkitRelativePath } `
const name = targetFolder === '/' ? file . webkitRelativePath : ` ${ targetFolder } / ${ file . webkitRelativePath } `
if ( ! await workspaceProvider . exists ( name ) ) {
if ( ! ( await workspaceProvider . exists ( name ) ) ) {
loadFile ( name , file , workspaceProvider , cb )
loadFile ( name , file , workspaceProvider , cb )
} else {
} else {
const modalContent : AppModal = {
const modalContent : AppModal = {
@ -437,23 +506,24 @@ export const uploadFolder = async (target, targetFolder: string, cb?: (err: Erro
loadFile ( name , file , workspaceProvider , cb )
loadFile ( name , file , workspaceProvider , cb )
} ,
} ,
cancelFn : ( ) = > { } ,
cancelFn : ( ) = > { } ,
hideFn : ( ) = > { }
hideFn : ( ) = > { } ,
}
}
plugin . call ( 'notification' , 'modal' , modalContent )
plugin . call ( 'notification' , 'modal' , modalContent )
}
}
}
}
}
}
export const getWorkspaces = async ( ) : Promise < { name : string , isGitRepo : boolean , branches ? : { remote : any ; name : string ; } [ ] , currentBranch? : string } [ ] > | undefined = > {
export const getWorkspaces = async ( ) : Promise < { name : string ; isGitRepo : boolean ; branches ? : { remote : any ; name : string } [ ] ; currentBranch? : string } [ ] > | undefined = > {
try {
try {
const workspaces : { name : string , isGitRepo : boolean , branches ? : { remote : any ; name : string ; } [ ] , currentBranch? : string } [ ] = await new Promise ( ( resolve , reject ) = > {
const workspaces : { name : string ; isGitRepo : boolean ; branches ? : { remote : any ; name : string } [ ] ; currentBranch? : string } [ ] = await new Promise ( ( resolve , reject ) = > {
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
plugin . fileProviders . browser . resolveDirectory ( '/' + workspacesPath , ( error , items ) = > {
plugin . fileProviders . browser . resolveDirectory ( '/' + workspacesPath , ( error , items ) = > {
if ( error ) {
if ( error ) {
return reject ( error )
return reject ( error )
}
}
Promise . all ( Object . keys ( items )
Promise . all (
Object . keys ( items )
. filter ( ( item ) = > items [ item ] . isDirectory )
. filter ( ( item ) = > items [ item ] . isDirectory )
. map ( async ( folder ) = > {
. map ( async ( folder ) = > {
const isGitRepo : boolean = await plugin . fileProviders . browser . exists ( '/' + folder + '/.git' )
const isGitRepo : boolean = await plugin . fileProviders . browser . exists ( '/' + folder + '/.git' )
@ -468,20 +538,21 @@ export const getWorkspaces = async (): Promise<{ name: string, isGitRepo: boolea
name : folder.replace ( workspacesPath + '/' , '' ) ,
name : folder.replace ( workspacesPath + '/' , '' ) ,
isGitRepo ,
isGitRepo ,
branches ,
branches ,
currentBranch
currentBranch ,
}
}
} else {
} else {
return {
return {
name : folder.replace ( workspacesPath + '/' , '' ) ,
name : folder.replace ( workspacesPath + '/' , '' ) ,
isGitRepo
isGitRepo ,
}
}
}
}
} ) ) . then ( workspacesList = > resolve ( workspacesList ) )
} )
) . then ( ( workspacesList ) = > resolve ( workspacesList ) )
} )
} )
} )
} )
await plugin . setWorkspaces ( workspaces )
await plugin . setWorkspaces ( workspaces )
return workspaces
return workspaces
} catch ( e ) { }
} catch ( e ) { }
}
}
export const cloneRepository = async ( url : string ) = > {
export const cloneRepository = async ( url : string ) = > {
@ -496,7 +567,8 @@ export const cloneRepository = async (url: string) => {
const promise = plugin . call ( 'dGitProvider' , 'clone' , repoConfig , repoName , true )
const promise = plugin . call ( 'dGitProvider' , 'clone' , repoConfig , repoName , true )
dispatch ( cloneRepositoryRequest ( ) )
dispatch ( cloneRepositoryRequest ( ) )
promise . then ( async ( ) = > {
promise
. then ( async ( ) = > {
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
@ -509,11 +581,13 @@ export const cloneRepository = async (url: string) => {
dispatch ( setCurrentWorkspaceCurrentBranch ( currentBranch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( currentBranch ) )
dispatch ( cloneRepositorySuccess ( ) )
dispatch ( cloneRepositorySuccess ( ) )
} ) . catch ( ( ) = > {
} )
. catch ( ( ) = > {
const cloneModal = {
const cloneModal = {
id : 'cloneGitRepository' ,
id : 'cloneGitRepository' ,
title : 'Clone Git Repository' ,
title : 'Clone Git Repository' ,
message : 'An error occurred: Please check that you have the correct URL for the repo. If the repo is private, you need to add your github credentials (with the valid token permissions) in Settings plugin' ,
message :
'An error occurred: Please check that you have the correct URL for the repo. If the repo is private, you need to add your github credentials (with the valid token permissions) in Settings plugin' ,
modalType : 'modal' ,
modalType : 'modal' ,
okLabel : 'OK' ,
okLabel : 'OK' ,
okFn : async ( ) = > {
okFn : async ( ) = > {
@ -523,7 +597,7 @@ export const cloneRepository = async (url: string) => {
hideFn : async ( ) = > {
hideFn : async ( ) = > {
await deleteWorkspace ( repoName )
await deleteWorkspace ( repoName )
dispatch ( cloneRepositoryFailed ( ) )
dispatch ( cloneRepositoryFailed ( ) )
}
} ,
}
}
plugin . call ( 'notification' , 'modal' , cloneModal )
plugin . call ( 'notification' , 'modal' , cloneModal )
} )
} )
@ -540,7 +614,6 @@ export const checkGit = async () => {
dispatch ( setCurrentWorkspaceCurrentBranch ( currentBranch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( currentBranch ) )
}
}
export const getRepositoryTitle = async ( url : string ) = > {
export const getRepositoryTitle = async ( url : string ) = > {
const urlArray = url . split ( '/' )
const urlArray = url . split ( '/' )
let name = urlArray . length > 0 ? urlArray [ urlArray . length - 1 ] : ''
let name = urlArray . length > 0 ? urlArray [ urlArray . length - 1 ] : ''
@ -561,25 +634,24 @@ export const getRepositoryTitle = async (url: string) => {
}
}
export const getGitRepoBranches = async ( workspacePath : string ) = > {
export const getGitRepoBranches = async ( workspacePath : string ) = > {
const gitConfig : { fs : IndexedDBStorage , dir : string } = {
const gitConfig : { fs : IndexedDBStorage ; dir : string } = {
fs : window.remixFileSystemCallback ,
fs : window.remixFileSystemCallback ,
dir : addSlash ( workspacePath )
dir : addSlash ( workspacePath ) ,
}
}
const branches : { remote : any ; name : string ; } [ ] = await plugin . call ( 'dGitProvider' , 'branches' , { . . . gitConfig } )
const branches : { remote : any ; name : string } [ ] = await plugin . call ( 'dGitProvider' , 'branches' , { . . . gitConfig } )
return branches
return branches
}
}
export const getGitRepoCurrentBranch = async ( workspaceName : string ) = > {
export const getGitRepoCurrentBranch = async ( workspaceName : string ) = > {
const gitConfig : { fs : IndexedDBStorage , dir : string } = {
const gitConfig : { fs : IndexedDBStorage ; dir : string } = {
fs : window.remixFileSystemCallback ,
fs : window.remixFileSystemCallback ,
dir : addSlash ( workspaceName )
dir : addSlash ( workspaceName ) ,
}
}
const currentBranch : string = await plugin . call ( 'dGitProvider' , 'currentbranch' , { . . . gitConfig } )
const currentBranch : string = await plugin . call ( 'dGitProvider' , 'currentbranch' , { . . . gitConfig } )
return currentBranch
return currentBranch
}
}
export const showAllBranches = async ( ) = > {
export const showAllBranches = async ( ) = > {
console . log ( 'showAllBranches' )
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
const isActive = await plugin . call ( 'manager' , 'isActive' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
if ( ! isActive ) await plugin . call ( 'manager' , 'activatePlugin' , 'dgit' )
plugin . call ( 'menuicons' , 'select' , 'dgit' )
plugin . call ( 'menuicons' , 'select' , 'dgit' )
@ -618,26 +690,32 @@ export const switchBranch = async (branch: string) => {
okLabel : 'Force Checkout' ,
okLabel : 'Force Checkout' ,
okFn : async ( ) = > {
okFn : async ( ) = > {
dispatch ( cloneRepositoryRequest ( ) )
dispatch ( cloneRepositoryRequest ( ) )
plugin . call ( 'dGitProvider' , 'checkout' , { ref : branch , force : true } , false ) . then ( async ( ) = > {
plugin
. call ( 'dGitProvider' , 'checkout' , { ref : branch , force : true } , false )
. then ( async ( ) = > {
await fetchWorkspaceDirectory ( ROOT_PATH )
await fetchWorkspaceDirectory ( ROOT_PATH )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( cloneRepositorySuccess ( ) )
dispatch ( cloneRepositorySuccess ( ) )
} ) . catch ( ( ) = > {
} )
. catch ( ( ) = > {
dispatch ( cloneRepositoryFailed ( ) )
dispatch ( cloneRepositoryFailed ( ) )
} )
} )
} ,
} ,
cancelLabel : 'Cancel' ,
cancelLabel : 'Cancel' ,
cancelFn : ( ) = > { } ,
cancelFn : ( ) = > { } ,
hideFn : ( ) = > { }
hideFn : ( ) = > { } ,
}
}
plugin . call ( 'notification' , 'modal' , cloneModal )
plugin . call ( 'notification' , 'modal' , cloneModal )
} else {
} else {
dispatch ( cloneRepositoryRequest ( ) )
dispatch ( cloneRepositoryRequest ( ) )
plugin . call ( 'dGitProvider' , 'checkout' , { ref : branch , force : true } , false ) . then ( async ( ) = > {
plugin
. call ( 'dGitProvider' , 'checkout' , { ref : branch , force : true } , false )
. then ( async ( ) = > {
await fetchWorkspaceDirectory ( ROOT_PATH )
await fetchWorkspaceDirectory ( ROOT_PATH )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( cloneRepositorySuccess ( ) )
dispatch ( cloneRepositorySuccess ( ) )
} ) . catch ( ( ) = > {
} )
. catch ( ( ) = > {
dispatch ( cloneRepositoryFailed ( ) )
dispatch ( cloneRepositoryFailed ( ) )
} )
} )
}
}
@ -647,7 +725,8 @@ export const createNewBranch = async (branch: string) => {
const promise = plugin . call ( 'dGitProvider' , 'branch' , { ref : branch , checkout : true } , false )
const promise = plugin . call ( 'dGitProvider' , 'branch' , { ref : branch , checkout : true } , false )
dispatch ( cloneRepositoryRequest ( ) )
dispatch ( cloneRepositoryRequest ( ) )
promise . then ( async ( ) = > {
promise
. then ( async ( ) = > {
await fetchWorkspaceDirectory ( ROOT_PATH )
await fetchWorkspaceDirectory ( ROOT_PATH )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
@ -656,7 +735,8 @@ export const createNewBranch = async (branch: string) => {
dispatch ( setCurrentWorkspaceBranches ( branches ) )
dispatch ( setCurrentWorkspaceBranches ( branches ) )
dispatch ( cloneRepositorySuccess ( ) )
dispatch ( cloneRepositorySuccess ( ) )
} ) . catch ( ( ) = > {
} )
. catch ( ( ) = > {
dispatch ( cloneRepositoryFailed ( ) )
dispatch ( cloneRepositoryFailed ( ) )
} )
} )
return promise
return promise
@ -665,30 +745,29 @@ export const createNewBranch = async (branch: string) => {
export const createSolidityGithubAction = async ( ) = > {
export const createSolidityGithubAction = async ( ) = > {
const path = '.github/workflows/run-solidity-unittesting.yml'
const path = '.github/workflows/run-solidity-unittesting.yml'
await plugin . call ( 'fileManager' , 'writeFile' , path , solTestYml )
await plugin . call ( 'fileManager' , 'writeFile' , path , solTestYml )
plugin . call ( 'fileManager' , 'open' , path )
plugin . call ( 'fileManager' , 'open' , path )
}
}
export const createTsSolGithubAction = async ( ) = > {
export const createTsSolGithubAction = async ( ) = > {
const path = '.github/workflows/run-js-test.yml'
const path = '.github/workflows/run-js-test.yml'
await plugin . call ( 'fileManager' , 'writeFile' , path , tsSolTestYml )
await plugin . call ( 'fileManager' , 'writeFile' , path , tsSolTestYml )
plugin . call ( 'fileManager' , 'open' , path )
plugin . call ( 'fileManager' , 'open' , path )
}
}
export const createSlitherGithubAction = async ( ) = > {
export const createSlitherGithubAction = async ( ) = > {
const path = '.github/workflows/run-slither-action.yml'
const path = '.github/workflows/run-slither-action.yml'
await plugin . call ( 'fileManager' , 'writeFile' , path , slitherYml )
await plugin . call ( 'fileManager' , 'writeFile' , path , slitherYml )
plugin . call ( 'fileManager' , 'open' , path )
plugin . call ( 'fileManager' , 'open' , path )
}
}
const scriptsRef = {
const scriptsRef = {
'deployer' : contractDeployerScripts ,
deployer : contractDeployerScripts ,
'etherscan' : etherscanScripts
etherscan : etherscanScripts ,
}
}
export const createHelperScripts = async ( script : string ) = > {
export const createHelperScripts = async ( script : string ) = > {
if ( ! scriptsRef [ script ] ) return
if ( ! scriptsRef [ script ] ) return
await scriptsRef [ script ] ( plugin )
await scriptsRef [ script ] ( plugin )
plugin . call ( 'notification' , 'toast' , 'scripts added in the "scripts" folder' )
plugin . call ( 'notification' , 'toast' , 'scripts added in the "scripts" folder' )
@ -708,7 +787,9 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
okLabel : 'Force Checkout' ,
okLabel : 'Force Checkout' ,
okFn : async ( ) = > {
okFn : async ( ) = > {
dispatch ( cloneRepositoryRequest ( ) )
dispatch ( cloneRepositoryRequest ( ) )
plugin . call ( 'dGitProvider' , 'checkout' , { ref : branch , remote , force : true } , false ) . then ( async ( ) = > {
plugin
. call ( 'dGitProvider' , 'checkout' , { ref : branch , remote , force : true } , false )
. then ( async ( ) = > {
await fetchWorkspaceDirectory ( ROOT_PATH )
await fetchWorkspaceDirectory ( ROOT_PATH )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
@ -717,18 +798,21 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
dispatch ( setCurrentWorkspaceBranches ( branches ) )
dispatch ( setCurrentWorkspaceBranches ( branches ) )
dispatch ( cloneRepositorySuccess ( ) )
dispatch ( cloneRepositorySuccess ( ) )
} ) . catch ( ( ) = > {
} )
. catch ( ( ) = > {
dispatch ( cloneRepositoryFailed ( ) )
dispatch ( cloneRepositoryFailed ( ) )
} )
} )
} ,
} ,
cancelLabel : 'Cancel' ,
cancelLabel : 'Cancel' ,
cancelFn : ( ) = > { } ,
cancelFn : ( ) = > { } ,
hideFn : ( ) = > { }
hideFn : ( ) = > { } ,
}
}
plugin . call ( 'notification' , 'modal' , cloneModal )
plugin . call ( 'notification' , 'modal' , cloneModal )
} else {
} else {
dispatch ( cloneRepositoryRequest ( ) )
dispatch ( cloneRepositoryRequest ( ) )
plugin . call ( 'dGitProvider' , 'checkout' , { ref : branch , remote , force : true } , false ) . then ( async ( ) = > {
plugin
. call ( 'dGitProvider' , 'checkout' , { ref : branch , remote , force : true } , false )
. then ( async ( ) = > {
await fetchWorkspaceDirectory ( ROOT_PATH )
await fetchWorkspaceDirectory ( ROOT_PATH )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
dispatch ( setCurrentWorkspaceCurrentBranch ( branch ) )
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
const workspacesPath = plugin . fileProviders . workspace . workspacesPath
@ -737,7 +821,8 @@ export const checkoutRemoteBranch = async (branch: string, remote: string) => {
dispatch ( setCurrentWorkspaceBranches ( branches ) )
dispatch ( setCurrentWorkspaceBranches ( branches ) )
dispatch ( cloneRepositorySuccess ( ) )
dispatch ( cloneRepositorySuccess ( ) )
} ) . catch ( ( ) = > {
} )
. catch ( ( ) = > {
dispatch ( cloneRepositoryFailed ( ) )
dispatch ( cloneRepositoryFailed ( ) )
} )
} )
}
}