Skip to content

Instantly share code, notes, and snippets.

☕️
Focusing

John O'Sullivan john-osullivan

☕️
Focusing
Block or report user

Report or block john-osullivan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@john-osullivan
john-osullivan / hidden-command.ts
Last active Nov 12, 2019
Dev Diaries #3 - Hidden yargs Commands
View hidden-command.ts
export const command = "onboarding";
export const desc = false;
@john-osullivan
john-osullivan / requireAuthData.tsx
Last active Nov 7, 2019
Dev Diary #3 - Require Auth Data with Middleware
View requireAuthData.tsx
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'."} />
@john-osullivan
john-osullivan / App-with-Refresh.tsx
Last active Nov 7, 2019
Dev Diaries #3 - Refresh w/ Hook
View App-with-Refresh.tsx
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);
},
@john-osullivan
john-osullivan / listDappsHandler.tsx
Created Nov 7, 2019
Dev Diaries #3 - ListDapps Handler
View listDappsHandler.tsx
export function handler(args: ArgShape) {
render(
<App args={args} renderFunc={({ API }) => {
return (
<PrettyRequest
operation={ApiMethodLabel(ListDapps.HTTP, ListDapps.Path)}
resource={() => API.private.listDapps.resource()} />
)
}} />
)
@john-osullivan
john-osullivan / listDapps-builderFxn.tsx
Created Nov 7, 2019
Dev Diary #3 - Mounting requireAuthData Middleware
View listDapps-builderFxn.tsx
export function builder(yargs: Argv<UniversalArgs>) {
yargs.middleware(requireAuthData);
}
@john-osullivan
john-osullivan / addDefaultAuthPath.ts
Last active Nov 7, 2019
Dev Diaries #3 - Middleware for Default Auth Path
View addDefaultAuthPath.ts
// 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
@john-osullivan
john-osullivan / CLI-App.tsx
Last active Nov 7, 2019
Dev Diaries #3 - Top-Level App component w/ renderFunc
View CLI-App.tsx
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.
@john-osullivan
john-osullivan / viewDapp.tsx
Created Nov 7, 2019
Dev Diary #3 - renderProps make easy handlers
View viewDapp.tsx
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)} />
)
}} />
@john-osullivan
john-osullivan / updateDapp.tsx
Last active Nov 7, 2019
Dev Diary #3 - Loading File via Arg Name
View updateDapp.tsx
export function builder(yargs:Argv<UniversalArgs>) {
yargs
.middleware(requireAuthData)
.options({
'AbiPath' : {
type: 'string'
},
...
});
}
@john-osullivan
john-osullivan / authStorage.ts
Created Nov 7, 2019
Dev Diary #3 - CLI authStorage
View authStorage.ts
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));
}
}
You can’t perform that action at this time.