Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added lint workflow #79

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = {
'react/jsx-filename-extension': 'off',
'react/jsx-props-no-spreading': 'off',
'import/no-extraneous-dependencies': 'off',
'import/prefer-default-export': 'off',
'prefer-destructuring': [
'error', {
VariableDeclarator: {
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Actions

on:
pull_request:

concurrency:
group: ${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
checks:
runs-on: ubuntu-latest

steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Install NodeJS
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: 'yarn'

- name: Install NPM Dependencies
run: yarn install

- name: Run Linting
run: yarn lint
4 changes: 0 additions & 4 deletions custom.d.ts

This file was deleted.

32 changes: 17 additions & 15 deletions src/components/AddDevice/AddDevice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { openToast } from '../../lib/Toast';
import { useAuthState } from '../../lib/useAuthState';
import { decodeIfTruthy, inIframe } from '../../utils';
import { basePath } from '../../utils/config';
import { checkFirestoreReady, firebaseAuth, getDomain } from '../../utils/firebase';
import { checkFirestoreReady, firebaseAuth } from '../../utils/firebase';
import { isValidEmail } from '../../utils/form-validation';

const StyledContainer = styled.div`
Expand Down Expand Up @@ -233,7 +233,7 @@ function SignInPage() {
return window.firestoreController.addDeviceCollection({
fakPublicKey: null,
lakPublicKey: public_key,
gateway: success_url,
gateway: success_url,
})
.then(() => {
const parsedUrl = new URL(success_url || window.location.origin);
Expand Down Expand Up @@ -325,20 +325,22 @@ function SignInPage() {
<InputContainer>
<label htmlFor="email">
Email
</label>
<input
{...register('email', {
required: 'Please enter a valid email address',
})}
onChange={(e) => {
setValue('email', e.target.value);
<input
{...register('email', {
required: 'Please enter a valid email address',
})}
onChange={(e) => {
setValue('email', e.target.value);
// eslint-disable-next-line
if (!isValidEmail(e.target.value)) return;
}}
placeholder="user_name@email.com"
type="email"
id="email"
required
/>
}}
placeholder="user_name@email.com"
type="email"
id="email"
required
/>
</label>

</InputContainer>

<Button type="submit" size="large" label="Continue" variant="affirmative" onClick={onSubmit} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/AuthCallback/AuthCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import FirestoreController from '../../lib/firestoreController';
import { openToast } from '../../lib/Toast';
import { decodeIfTruthy, inIframe } from '../../utils';
import { network, networkId } from '../../utils/config';
import { checkFirestoreReady, firebaseAuth, getDomain } from '../../utils/firebase';
import { checkFirestoreReady, firebaseAuth } from '../../utils/firebase';
import {
CLAIM, getAddKeyAction, getUserCredentialsFrpSignature, getDeleteKeysAction, getAddLAKAction
CLAIM, getAddKeyAction, getUserCredentialsFrpSignature, getAddLAKAction
} from '../../utils/mpc-service';

const StyledStatusMessage = styled.div`
Expand Down
1 change: 0 additions & 1 deletion src/components/CreateAccount/CreateAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function CreateAccount() {
const formValues = watch();
const navigate = useNavigate();
const [searchParams] = useSearchParams();


const createAccount = async (data: { email: string; username: string; }) => {
const success_url = searchParams.get('success_url');
Expand Down
1 change: 0 additions & 1 deletion src/components/Devices/Devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useAuthState } from '../../lib/useAuthState';
import { decodeIfTruthy } from '../../utils';
import { networkId } from '../../utils/config';
import { onSignIn } from '../AuthCallback/AuthCallback';
import { getDomain } from '../../utils/firebase';

const Title = styled.h1`
padding-bottom: 20px;
Expand Down
46 changes: 25 additions & 21 deletions src/components/Login/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { fetchSignInMethodsForEmail } from 'firebase/auth';
import React, { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { useNavigate, useSearchParams } from 'react-router-dom';

import { Button } from '../../lib/Button';
import { LoginWrapper, InputContainer } from './Login.style';
import { useForm } from 'react-hook-form';
import { fetchSignInMethodsForEmail } from 'firebase/auth';
import { Button } from '../../lib/Button';
import { openToast } from '../../lib/Toast';
import { firebaseAuth } from '../../utils/firebase';
import { isValidEmail } from '../../utils/form-validation';
import { openToast } from '../../lib/Toast';

function Login() {
const [currentSearchParams] = useSearchParams();
Expand All @@ -19,12 +19,12 @@ function Login() {
if (isRecovery === 'true') {
navigate({
pathname: '/add-device',
search: currentSearchParams.toString(),
search: currentSearchParams.toString(),
});
} else {
navigate({
pathname: '/create-account',
search: currentSearchParams.toString(),
search: currentSearchParams.toString(),
});
}
}
Expand All @@ -35,21 +35,22 @@ function Login() {
const emailCheck = async (params: any) => {
fetchSignInMethodsForEmail(firebaseAuth, params.email)
.then((result) => {
result.length === 0 &&
if (result.length === 0) {
navigate({
pathname: '/create-account',
search: `email=${params.email}`,
search: `email=${params.email}`,
});
result[0] == 'emailLink' &&
} else if (result[0] === 'emailLink') {
navigate({
pathname: '/add-device',
search: `email=${params.email}`,
search: `email=${params.email}`,
});
}
})
.catch((error: any) => {
console.error('error', error);
openToast({
type: 'ERROR',
type: 'ERROR',
title: error.message,
});
});
Expand All @@ -66,16 +67,19 @@ function Login() {
</header>

<InputContainer>
<label htmlFor="email">Email</label>
<input
onChange={(e) => {
setValue('email', e.target.value);
if (!isValidEmail(e.target.value)) return;
}}
placeholder="user_name@email.com"
type="email"
required
/>
<label htmlFor="email">
Email
<input
onChange={(e) => {
setValue('email', e.target.value);
// eslint-disable-next-line
if (!isValidEmail(e.target.value)) return;
}}
placeholder="user_name@email.com"
type="email"
required
/>
</label>
</InputContainer>

<Button
Expand Down
1 change: 0 additions & 1 deletion src/components/RpcRoute/RpcRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useEffect } from 'react';


function RpcRoute() {
useEffect(() => {
const listener = (e: MessageEvent) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sign/Sign.styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import styled from "styled-components";
import styled from 'styled-components';

export const ModalSignWrapper = styled.div`
max-width: 550px;
Expand Down
3 changes: 3 additions & 0 deletions src/components/Sign/Sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function Sign() {
const success_url = searchParams.get('success_url');
for (let i = 0; i < transactionDetails.transactions.length; i += 1) {
try {
// eslint-disable-next-line
const signed = await (
window as any
).fastAuthController.signDelegateAction(
Expand Down Expand Up @@ -228,6 +229,7 @@ function Sign() {
/>
</div>
</div>
{/* eslint-disable-next-line */}
<div
className="more-details"
onClick={() => setShowDetails(!showDetails)}
Expand All @@ -254,6 +256,7 @@ function Sign() {
<h4>Actions</h4>
{transactionDetails.actions.map((action, i) => (
<TableContent
// eslint-disable-next-line
key={i}
leftSide={transactionDetails.receiverId}
hasFunctionCall
Expand Down
23 changes: 11 additions & 12 deletions src/components/Sign/Values/fiatValueManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// @ts-ignore
import sendJson from './tmp_fetch_send_json';
import { stringifyUrl } from 'query-string';

// @ts-ignore
import sendJson from './tmp_fetch_send_json';

const COINGECKO_PRICE_URL = 'https://api.coingecko.com/api/v3/simple/price';
const ACCOUNT_ID_SUFFIX = 'mainnet';
const REF_FINANCE_API_ENDPOINT = `https://${ACCOUNT_ID_SUFFIX}-indexer.ref-finance.com/`;
Expand All @@ -11,35 +13,32 @@ export const fetchGeckoPrices = async (tokenIds) => {
const tokenFiatValues = await sendJson(
'GET',
stringifyUrl({
url: COINGECKO_PRICE_URL,
url: COINGECKO_PRICE_URL,
query: {
ids: tokenIds,
vs_currencies: 'usd',
ids: tokenIds,
vs_currencies: 'usd',
include_last_updated_at: true,
},
})
);
return tokenFiatValues;
} catch (error) {
console.error(`Failed to fetch coingecko prices: ${error}`);
return console.error(`Failed to fetch coingecko prices: ${error}`);
}
};



export const fetchRefFinancePrices = async () => {
try {
const refFinanceTokenFiatValues = await sendJson(
'GET',
REF_FINANCE_API_ENDPOINT + '/list-token-price'
`${REF_FINANCE_API_ENDPOINT}/list-token-price`
);
const [prices] = [refFinanceTokenFiatValues];

const last_updated_at = Date.now() / 1000;

const formattedValues =
refFinanceTokenFiatValues &&
Object.keys(prices).reduce((acc, curr) => {
const formattedValues = refFinanceTokenFiatValues
&& Object.keys(prices).reduce((acc, curr) => {
return {
...acc,
[curr]: {
Expand All @@ -53,6 +52,6 @@ export const fetchRefFinancePrices = async () => {
near: formattedValues['wrap.near'],
};
} catch (error) {
console.warn(`Failed to fetch ref-finance prices: ${error}`);
return console.warn(`Failed to fetch ref-finance prices: ${error}`);
}
};
22 changes: 11 additions & 11 deletions src/components/Sign/Values/formatNearAmount.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { utils} from 'near-api-js';
import { utils } from 'near-api-js';

const NEAR_FRACTIONAL_DIGITS = 5;

export const formatNearAmount = (amount) => {
amount = amount.toString();
if (amount === '0') {
return amount;
}
let formattedAmount = utils.format.formatNearAmount(amount, NEAR_FRACTIONAL_DIGITS);
if (formattedAmount === '0') {
return `< ${!NEAR_FRACTIONAL_DIGITS ? '0' : `0.${'0'.repeat((NEAR_FRACTIONAL_DIGITS || 1) - 1)}1`}`;
}
return formattedAmount;
};
amount = amount.toString();
if (amount === '0') {
return amount;
}
const formattedAmount = utils.format.formatNearAmount(amount, NEAR_FRACTIONAL_DIGITS);
if (formattedAmount === '0') {
return `< ${!NEAR_FRACTIONAL_DIGITS ? '0' : `0.${'0'.repeat((NEAR_FRACTIONAL_DIGITS || 1) - 1)}1`}`;
}
return formattedAmount;
};
10 changes: 6 additions & 4 deletions src/components/Sign/Values/store.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';

const store = (set) => ({
fiatValueUsd: '',
storeFetchedUsdValues: (fiatValueUsd) => set({ fiatValueUsd }),
});
const store = (set) => {
return {
fiatValueUsd: '',
storeFetchedUsdValues: (fiatValueUsd) => set({ fiatValueUsd }),
};
};

const fiatValuesStore = create(devtools(store));

Expand Down
Loading