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
export function handler(args: ArgShape) { | |
render( | |
<App args={args} renderFunc={({ API }) => { | |
return ( | |
<PrettyRequest | |
operation={ApiMethodLabel(ListDapps.HTTP, ListDapps.Path)} | |
resource={() => API.private.listDapps.resource()} /> | |
) | |
}} /> | |
) |
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
export function builder(yargs: Argv<UniversalArgs>) { | |
yargs.middleware(requireAuthData); | |
} |
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
// Middleware defined in a service file | |
export function addDefaultAuthPath(args:ArgShape): ArgShape { | |
if (args.authPath) return args; | |
args.authPath = AUTH_FILE_PATH; | |
initAuthFile(); | |
return args; | |
} | |
// Then used in cli.tsx |
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
import User from "@eximchain/dappbot-types/spec/user"; | |
export const requireAuthData:MiddlewareFunction<UniversalArgs> = (args) => { | |
// This function will show the user an error and then | |
// exit the process, preventing the command handler | |
// from ever actually being called. | |
function authErr() { | |
render( | |
<ErrorBox errMsg={"This command requires you to log in; please call 'dappbot signup' or 'dappbot login'."} /> |
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
export function App<Additional extends AdditionalArgs>(props: AppProps<Additional>): ReactElement { | |
const { args, renderFunc } = props; | |
const [authData, setAuthData] = useState(JSON.parse(args.authFile as string)); | |
const API = new DappbotAPI({ | |
authData, | |
setAuthData: (auth) => { | |
setAuthData(auth); | |
saveAuthToFile(auth); | |
}, |
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
import DappbotAPI from '@eximchain/dappbot-api-client'; | |
export function function App<Additional extends AdditionalArgs>(props: AppProps<Additional>): ReactElement { | |
// We destructure App's two props; the args from | |
// the command, and the renderFunc. | |
const { args, renderFunc } = props; | |
// We use the authFile argument to initialize the | |
// authData, as it will safely default. |
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
export function handler(args: ArgShape<DappNameArg>) { | |
fastRender( | |
<App args={args} renderFunc={({ API }) => { | |
const DappName = args.DappName; | |
return ( | |
<PrettyRequest | |
operation={ApiMethodLabel(ViewDapp.HTTP, ViewDapp.Path(DappName))} | |
resource={() => API.public.viewDapp.resource(DappName)} /> | |
) | |
}} /> |
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
export function builder(yargs:Argv<UniversalArgs>) { | |
yargs | |
.middleware(requireAuthData) | |
.options({ | |
'AbiPath' : { | |
type: 'string' | |
}, | |
... | |
}); | |
} |
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
import { AuthData, newAuthData } from '@eximchain/dappbot-types/spec/user'; | |
export const AUTH_FILENAME = 'dappbotAuthData.json'; | |
export const AUTH_FILE_PATH = path.resolve(__dirname, `./${AUTH_FILENAME}`); | |
export function initAuthFile() { | |
if (!fs.existsSync(AUTH_FILE_PATH)) { | |
fs.writeFileSync(AUTH_FILE_PATH, JSON.stringify(newAuthData(), null, 2)); | |
} | |
} |
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
/** | |
* Middlware: Listen for any options whose name ends in "Path", and if found, | |
* read the file's contents as a string and add it as an argument | |
* whose name ends in "File". For instance, "authPath" will yield | |
* an "authFile" string, which can be JSON.parse()d to get the | |
* actual authData. | |
* @param args | |
*/ | |
export function loadFileFromPath(args:ArgShape): ArgShape { | |
const pathKeys = Object.keys(args).filter(key => key.indexOf('Path') > -1); |
NewerOlder