0.13.53 • Published 3 years ago

@majorfi/web-lib v0.13.53

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Yearn Web Lib

Yearn web Lib is a library of standard components used through Yearn's Projects.
This library is made for React projects with the idea to be light, efficient and easy to use.
We are using React + Tailwindcss + ethersjs for the web3 package, and some contexts are available to correctly wrap your app.

How to install

Run the following command:

yarn add @majorfi/web-lib

Your project will also need React, React-Dom and TailwindCss

yarn add react
yarn add react-dom
yarn add tailwindcss

You will need to generate a Github Personal Access Token, to create or update the ~/.npmrc file with the following content:

registry=https://registry.npmjs.org/
@yearn:registry=https://npm.pkg.github.com
@majorfi:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=YOUR_ACCESS_TOKEN

This will link all repo named @yearn you will install to the correct Yearn organization

How to setup

Setup tsconfig

With TS config, you should add some paths to be sure to correctly link the web lib:

	"baseUrl": ".",
	"paths": {
		"@majorfi/web-lib/components": ["./node_modules/@majorfi/web-lib/dist/components/index.js"],
		"@majorfi/web-lib/contexts": ["./node_modules/@majorfi/web-lib/dist/contexts/index.js"],
		"@majorfi/web-lib/hooks": ["./node_modules/@majorfi/web-lib/dist/hooks/index.js"],
		"@majorfi/web-lib/icons": ["./node_modules/@majorfi/web-lib/dist/icons/index.js"],
		"@majorfi/web-lib/utils": ["./node_modules/@majorfi/web-lib/dist/utils/index.js"],
	},

Import the CSS

Create a default style.css file in your project root, and add that in it:

/* This will load Tailwindcss + all the overwrite from Yearn lib */
@import '@majorfi/web-lib/dist/style.css';

Then, setup your tailwind.config.js file to enable detection of your style and prod optimization:

const {join} = require('path');
module.exports = {
	presets: [
		require('@majorfi/web-lib/tailwind.plugin')
	],
	content: [
		join(__dirname, 'pages', '**', '*.{js,jsx,ts,tsx}'),
		join(__dirname, 'components', 'icons', '**', '*.{js,jsx,ts,tsx}'),
		join(__dirname, 'components', 'logo', '**', '*.{js,jsx,ts,tsx}'),
		join(__dirname, 'components', 'strategies', '**', '*.{js,jsx,ts,tsx}'),
		join(__dirname, 'components', 'vaults', '**', '*.{js,jsx,ts,tsx}'),
		join(__dirname, 'components', '**', '*.{js,jsx,ts,tsx}'),
		join(__dirname, 'node_modules', '@majorfi', 'web-lib', 'dist', 'layouts', '**', '*.js'),
		join(__dirname, 'node_modules', '@majorfi', 'web-lib', 'dist', 'components', '**', '*.js'),
		join(__dirname, 'node_modules', '@majorfi', 'web-lib', 'dist', 'contexts', '**', '*.js'),
		join(__dirname, 'node_modules', '@majorfi', 'web-lib', 'dist', 'icons', '**', '*.js'),
		join(__dirname, 'node_modules', '@majorfi', 'web-lib', 'dist', 'utils', '**', '*.js')
	],
	.....
};

Setup the env

Ensure your env are set. Here is the list of the stuff to set:

WEBSITE_URI: 'https://my-web3-app.major.farm',
WEBSITE_NAME: 'My awesome yWeb3 app',
WEBSITE_TITLE: 'My awesome yWeb3 app',
WEBSITE_DESCRIPTION: 'Welcome to my awesome Yearn Web3 app. This is a super description that will be used for the SEO stuffs',
PROJECT_GITHUB_URL: 'https://github.com/me/yweb3-awesome',
USE_PRICES: false,
USE_PRICE_TRI_CRYPTO: false,
CG_IDS: [
	'yearn-finance'
],
TOKENS: [
	['0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e', 18, 1]
],
RPC_URL: {
	1: process.env.RPC_URL_MAINNET,
	250: process.env.RPC_URL_FANTOM || 'https://rpc.ftm.tools',
	42161: process.env.RPC_URL_ARBITRUM || 'https://arbitrum.public-rpc.com'
}

How to use

Usage is way simpler. You first need to wrap you app with the WithYearn context, and then you can use the components from the library.

import	{WithYearn}		from	'@majorfi/web-lib';

function	MyApp(props: AppProps): ReactElement {
	const	{Component, pageProps} = props;
	
	return (
		<WithYearn>
			<AppWrapper
				Component={Component}
				pageProps={pageProps} />
		</WithYearn>
	);
}

Subpackage

This repository is organised in subpackages:

Components

Having everything in one file is not great for both code splitting and organisation. The components folder is used to split the code and build some shared components that we will use in our app. Sections, aka a large part of the UI, can be put in here but should be prefixed with Section to be easy to recognise. Group of components for the same usage could be wrapped in a subfolder.

import {Card, SearchBox, Switch, ...} from '@majorfi/web-lib/components';

Layouts

The layouts folder is used to build the layout of the app. Layout have kind of the same objectif as components but are focused on the display of big section and parts of the UI.

import {List, Header, Navbar, ...} from '@majorfi/web-lib/layouts';

Icons

The icons folder is used to build the icons of the app. Icons are SVG files transformed in JSX/TSX components. They accept any props by default and the default fill color is set to currentColor to enable fill personalization

import {Cross, AlertWarning, ...} from '@majorfi/web-lib/icons';

Contexts

The contexts are what some users could know as store. With react you have some state managements that will trigger the re-render and store data in your app. Theses states can be send to children and used by children if required. This is nice but when you have a grand-x10-child, passing the state as prop is not the best idea. Contexts are a way to store share state across your app. A contexts is defined for one specific reason and it's best to keep the contexts for one use case: it's best to have one for the web3 management and one for the theme than on big mix. This is where the most of the logic will be done. We need to fetch some balances we will use in multiple places? Context! We need to get the account and web3 provider? Context!

import {useUI, useWeb3, ...} from '@majorfi/web-lib/contexts';

Hooks

Hooks are a bunch of state-management style helper designed to work with react and to perform some specific stuff out of the box. This can be something like useLocalStorage, useIndexDB, useWindowInFocus, etc. They should be independant from the app logic and should handle one specific case, not related to what the app is doing

import {useClientEffect, useLocalStorage, ...} from '@majorfi/web-lib/hooks';

Utils

The utils are just some basics helpers or logic we will used across our app. This can be some ABIs, this can be a function to sum an array of object, some reducer, etc.

import {toAddress, format, parseMarkdown, ...} from '@majorfi/web-lib/utils';

Pull request and review Conventions

  • Each pull request mush have an explaination on why this PR is relevant.
  • Commit should be signed.
  • After a review, one commits should fix one issue at a time.
  • All comments should be resolved by the person who originally created the comment.
  • All comments should be resolved before merging.
  • Any comments with feedback should be responded to by the author with a comment including the commit hash where the feedback has been resolved, or a reason with why it will not be addressed.
  • PRs require one approving review by a contributor with write access before it can be merged.
0.13.41

3 years ago

0.13.40

3 years ago

0.13.45

3 years ago

0.13.44

3 years ago

0.13.43

3 years ago

0.13.42

3 years ago

0.13.46

3 years ago

0.13.52

3 years ago

0.13.51

3 years ago

0.13.50

3 years ago

0.13.53

3 years ago

0.13.29

3 years ago

0.13.30

3 years ago

0.13.34

3 years ago

0.13.33

3 years ago

0.13.32

3 years ago

0.13.31

3 years ago

0.13.38

3 years ago

0.13.37

3 years ago

0.13.36

3 years ago

0.13.35

3 years ago

0.13.39

3 years ago

0.0.184

3 years ago

0.0.183

3 years ago

0.0.182

3 years ago

0.0.180

3 years ago

0.0.179

3 years ago

0.0.177

3 years ago

0.0.176

3 years ago

0.0.175

3 years ago

0.0.174

3 years ago

0.0.173

3 years ago

0.0.171

3 years ago

0.0.170

3 years ago

0.0.169

3 years ago

0.0.167

3 years ago

0.0.166

3 years ago

0.0.165

3 years ago

0.0.164

3 years ago

0.0.163

3 years ago

0.0.162

3 years ago

0.0.161

3 years ago

0.0.160

3 years ago

0.0.159

3 years ago

0.0.158

3 years ago

0.0.157

3 years ago

0.0.156

3 years ago

0.0.155

3 years ago

0.0.154

3 years ago

0.0.153

3 years ago

0.0.152

3 years ago

0.0.151

3 years ago

0.0.150

3 years ago

0.0.149

3 years ago

0.0.148

3 years ago

0.0.147

3 years ago

0.0.146

3 years ago

0.0.145

3 years ago

0.0.144

3 years ago

0.0.143

3 years ago

0.0.141

3 years ago

0.0.138

3 years ago

0.0.136

3 years ago

0.0.135

3 years ago

0.0.134

3 years ago

0.0.133

3 years ago

0.0.132

3 years ago

0.0.131

3 years ago

0.0.130

3 years ago

0.0.129

3 years ago

0.0.128

3 years ago

0.0.127

3 years ago

0.0.126

3 years ago

0.0.125

3 years ago

0.0.124

3 years ago

0.0.123

3 years ago

0.0.122

3 years ago

0.0.121

3 years ago

0.0.111

3 years ago

0.0.110

3 years ago

0.0.109

3 years ago

0.0.108

3 years ago

0.0.107

3 years ago

0.0.106

3 years ago

0.0.105

3 years ago

0.0.104

3 years ago

0.0.103

3 years ago

0.0.102

3 years ago

0.0.101

3 years ago

0.0.100

3 years ago

0.0.99

3 years ago

0.0.98

3 years ago

0.0.97

3 years ago

0.0.96

3 years ago

0.0.95

3 years ago

0.0.94

3 years ago

0.0.93

3 years ago

0.0.92

3 years ago

0.0.91

3 years ago

0.0.90

3 years ago

0.0.89

3 years ago

0.0.88

3 years ago

0.0.87

3 years ago

0.0.86

3 years ago

0.0.85

3 years ago

0.0.84

3 years ago

0.0.83

3 years ago

0.0.82

3 years ago

0.0.81

3 years ago

0.0.80

3 years ago

0.0.79

3 years ago

0.0.78

3 years ago

0.0.77

3 years ago

0.0.76

3 years ago

0.0.75

3 years ago

0.0.74

3 years ago

0.0.73

3 years ago

0.0.72

3 years ago

0.0.71

3 years ago

0.0.70

3 years ago

0.0.69

3 years ago

0.0.68

3 years ago

0.0.67

3 years ago

0.0.66

3 years ago

0.0.65

3 years ago

0.0.64

3 years ago

0.0.63

3 years ago

0.0.62

3 years ago

0.0.61

3 years ago

0.0.60

3 years ago

0.0.59

3 years ago

0.0.58

3 years ago

0.0.57

3 years ago

0.0.56

3 years ago

0.0.55

3 years ago

0.0.54

3 years ago

0.0.53

3 years ago

0.0.52

3 years ago

0.0.51

3 years ago

0.0.50

3 years ago

0.0.49

3 years ago

0.0.48

3 years ago

0.0.47

3 years ago

0.0.46

3 years ago

0.0.45

3 years ago

0.0.44

3 years ago

0.0.43

3 years ago

0.0.42

3 years ago

0.0.41

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.38

3 years ago

0.0.37

3 years ago

0.0.36

3 years ago

0.0.35

3 years ago

0.0.34

3 years ago

0.0.33

3 years ago

0.0.32

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.24

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago