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

Stage #90

Merged
merged 35 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
098f878
check invalid beneficiary
myanzik Feb 7, 2022
113dc1b
linting fix
myanzik Feb 8, 2022
dd10c95
backup and restore with google
Rasil07 Feb 9, 2022
bcf2f33
merged master
Rasil07 Feb 9, 2022
477c575
merged upstream stage
Rasil07 Feb 9, 2022
7634e66
Merge pull request #60 from myanzik/stage
myanzik Feb 9, 2022
dbef522
Merge pull request #62 from Rasil07/stage
myanzik Feb 9, 2022
8298b9a
Merge remote-tracking branch 'upstream/stage' into stage
myanzik Feb 9, 2022
04fb4ce
added package version in setup page, syncDb bug fixes
Rasil07 Feb 9, 2022
c4fc73c
Replaced Gitter with Discord for communication
nishu-rumsan Feb 9, 2022
4e9ce29
Merge pull request #63 from Rasil07/stage
myanzik Feb 10, 2022
a5b0246
Merge pull request #65 from Nishubade/stage
myanzik Feb 10, 2022
037fb4f
Merge remote-tracking branch 'upstream/stage' into stage
myanzik Feb 10, 2022
e1800f6
refactored wallet setup + restore processes and cleaned up all codes …
Rasil07 Feb 11, 2022
5a12b9b
Merge pull request #66 from Rasil07/stage
myanzik Feb 11, 2022
2345c25
home page now shows total package balance
Rasil07 Feb 14, 2022
e5c136d
saves transcation when package or token redeemed
Rasil07 Feb 14, 2022
81e3b6f
Merge pull request #67 from Rasil07/stage
myanzik Feb 15, 2022
accd758
transfer package feature added
Rasil07 Feb 15, 2022
ef027de
Merge pull request #75 from Rasil07/stage
myanzik Feb 16, 2022
5d8e8c1
transaction details shows NFT details if tokenId present
Rasil07 Feb 16, 2022
488f4df
setup process cleanups
Rasil07 Feb 17, 2022
bafe648
Merge pull request #76 from Rasil07/stage
myanzik Feb 17, 2022
0f4a898
merged to stage
myanzik Feb 23, 2022
b1e7e95
Merge pull request #78 from myanzik/stage
myanzik Feb 23, 2022
941408d
Updated Discord Channel
nishu-rumsan Feb 28, 2022
31848b7
Merge pull request #83 from Nishubade/stage
myanzik Feb 28, 2022
597b9f2
fix contract assets
myanzik Mar 9, 2022
9af7e6f
Merge pull request #85 from myanzik/stage
myanzik Mar 9, 2022
4cf29ba
fix contract assets
myanzik Mar 9, 2022
7f81798
Merge pull request #86 from myanzik/stage
myanzik Mar 9, 2022
6d0dc32
redirect to tx hostory after charging
myanzik Mar 9, 2022
c736c70
Merge pull request #87 from myanzik/stage
myanzik Mar 9, 2022
4658195
linting
myanzik Mar 9, 2022
b7627fa
Merge pull request #88 from myanzik/stage
myanzik Mar 9, 2022
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ To deploy this software on production
This repository uses eslint to enforce air-bnb coding styles.

# Contributing
Everyone is very welcome to contribute on the codebase of Rahat. Please reach us in [Gitter](https://gitter.im/bockies/community?utm_source=badge&utm_medium=badge&utm_content=badge) in case of any query/feedback/suggestion.
Everyone is very welcome to contribute on the codebase of Rahat. Please reach us in [Discord](https://discord.gg/AV5j2T94VR) in case of any query/feedback/suggestion.

For more information on the contributing procedure, see [Contribution](https://github.com/esatya/rahat-vendor/blob/master/CONTRIBUTING.md).
For more information on the contributing procedure, see [Contribution](https://docs.rahat.io/docs/next/Contribution-Guidelines).
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"axios": "^0.24.0",
"axios": "^0.25.0",
"bootstrap": "^4.5.1",
"crypto-js": "^4.0.0",
"dexie": "^3.0.3",
Expand Down
3 changes: 2 additions & 1 deletion src/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module.exports = {
SET_SCANNED_DATA: 'set_scanned_eth_address',
SET_APP_PASSCODE: 'set_app_passcode',
SET_BALANCE: 'set_balance',
ADD_RECENT_TX: 'add_recent_tx'
ADD_RECENT_TX: 'add_recent_tx',
SET_LOADING: 'set_loading'
};
8 changes: 7 additions & 1 deletion src/actionsheets/sheets/ChargeDetails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { useContext } from 'react';
import { useHistory } from 'react-router-dom';
import { Form } from 'react-bootstrap';
Expand All @@ -9,6 +8,7 @@ import Swal from 'sweetalert2';
// import { AppContext } from '../../contexts/AppContext';
import { ActionSheetContext } from '../../contexts/ActionSheetContext';
import ActionSheet from './ActionSheet';
import { checkBeneficiary } from '../../services';

export default function ChargeDetails(props) {
const history = useHistory();
Expand All @@ -19,6 +19,12 @@ export default function ChargeDetails(props) {

const chargeCustomer = async () => {
showLoading('Charging customer account...');
const isBeneficiary = await checkBeneficiary(data.phone);
if (!isBeneficiary.data) {
setActiveSheet('null');
showLoading(null);
return Swal.fire('Error', `${isBeneficiary.message || 'Invalid Beneficiary'}`, 'error');
}
try {
// const agency = await DataService.getDefaultAgency();
// const rahat = RahatService(agency.address, wallet);
Expand Down
File renamed without changes.
99 changes: 51 additions & 48 deletions src/assets/custom/styles.css
Original file line number Diff line number Diff line change
@@ -1,64 +1,67 @@
.circleSelfie {
border-radius: 50%!important;
width : 250px;
height: 250px;
object-fit: cover;
border: 5px solid #958d9e;
border-radius: 50% !important;
width: 250px;
height: 250px;
object-fit: cover;
border: 5px solid #958d9e;
}

.selfieWrapper {
/* width: 100%; */
height: auto;
/* width: 100%; */
height: auto;
}
.loading_text {
color: #e27a2a;
}

.idCardWrapper {
width: 100%;
height: 350px;
width: 100%;
height: 350px;
}

.idCardSnapper {
border-radius: 10%;
height: 350px;
object-fit: cover;
border: 3px solid #958d9e;
border-radius: 10%;
height: 350px;
object-fit: cover;
border: 3px solid #958d9e;
}

.button-link {
background-color: transparent;
border: none;
cursor: pointer;
text-decoration: none;
display: inline;
margin: 0;
padding: 0;
background-color: transparent;
border: none;
cursor: pointer;
text-decoration: none;
display: inline;
margin: 0;
padding: 0;
}

.button-link:hover,
.button-link:focus {
text-decoration: none;
}
.button-link:hover,
.button-link:focus {
text-decoration: none;
}

.btn-shutter{
width: 80px;
height: 80px;
/* border: 2px solid #958d9e; */
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
background-color: #2b7ec1;
}
.btn-shutter-icon{
width: 40px;
height: 40px;
color: white;
}
.btn-faceChange{
width: 50px;
height: 50px;
border-radius: 50%;
background-color: white;
display: flex;
justify-content: center;
align-items: center;
}
.btn-shutter {
width: 80px;
height: 80px;
/* border: 2px solid #958d9e; */
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
background-color: #2b7ec1;
}
.btn-shutter-icon {
width: 40px;
height: 40px;
color: white;
}
.btn-faceChange {
width: 50px;
height: 50px;
border-radius: 50%;
background-color: white;
display: flex;
justify-content: center;
align-items: center;
}
19 changes: 11 additions & 8 deletions src/constants/api.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const server_url = process.env.REACT_APP_DEFAULT_AGENCY_API;
const base_url = server_url + '/api/v1';

module.exports = {
REGISTER: base_url + '/vendors/register',
NFT: server_url + '/nft',
SERVER_URL: server_url
};
const server_url = process.env.REACT_APP_DEFAULT_AGENCY_API;
const base_url = server_url + '/api/v1';

module.exports = {
REGISTER: base_url + '/vendors/register',
NFT: base_url + '/nft',
VENDORS: base_url + '/vendors',
SERVER_URL: server_url,
APP: base_url + '/app',
BASE_URL: base_url
};
10 changes: 7 additions & 3 deletions src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module.exports = {
APP_CONSTANTS: {
VERSION: 1,
PASSCODE_LENGTH: 6,
PASSCODE_LENGTH: 10,
SCAN_DELAY: 600,
CHARGE_TYPES: {
TOKEN: 'token',
NFT: 'nft',
TOKEN_RECIEVED: 'tokenRecieved',
TOKEN_SENT: 'tokenSent',
NFT_RECIEVED: 'nftRecieved',
NFT_SENT: 'nftSent'
NFT_SENT: 'nftSent',
REDEEMED_TOKEN: 'tokenRedeemed',
REDEEMED_PACKAGE: 'packageRedeemed',
TOKEN_TRANSFER: 'tokenTransfer',
PAKCAGE_TRANSFER: 'packageTransfer'
},
DEFAULT_NFT_CHARGE: 1,
SCANNER_PREVIEW_STYLE: {
Expand All @@ -21,7 +25,7 @@ module.exports = {
},
BACKUP: {
PASSPHRASE_RULE: '"^(?=.*[a-zA-Z])(?=.*[0-9])(?=.{12,})"',
GDRIVE_FOLDERNAME: 'RumsanWalletBackups'
GDRIVE_FOLDERNAME: 'VendorBackups'
},
DB: {
NAME: 'db_wallet',
Expand Down
65 changes: 46 additions & 19 deletions src/contexts/AppContext.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,80 @@
import React, { createContext, useState, useReducer, useCallback } from 'react';
import React, { createContext, useReducer, useCallback } from 'react';
import appReduce from '../reducers/appReducer';
import APP_ACTIONS from '../actions/appActions';
import DataService from '../services/db';
import { TokenService } from '../services/chain';
import { APP_CONSTANTS, DEFAULT_TOKEN } from '../constants';
import { ethers } from 'ethers';

const initialState = {
contextLoading: false,
address: null,
agency: null,
network: null,
wallet: null,
profile: null,
hasWallet: true,
hasWallet: false,
hasBackedUp: false,
tokenBalance: 0,
scannedEthAddress: '',
scannedAmount: null
scannedAmount: null,
hasSynchronized: false,
recentTx: []
};

export const AppContext = createContext(initialState);
export const AppContextProvider = ({ children }) => {
const [state, dispatch] = useReducer(appReduce, initialState);
const [recentTx, setRecentTx] = useState([]);
const toggleLoading = useCallback((loading = false) => {
dispatch({ type: APP_ACTIONS.SET_LOADING, data: loading });
}, []);
const initialize_index_db = useCallback(async () => {
DataService.dbInstance
.open()
.then(async () => {
console.log('Dexie succesfully opened');
await DataService.addDefaultAsset(DEFAULT_TOKEN.SYMBOL, DEFAULT_TOKEN.NAME);
await DataService.save('version', APP_CONSTANTS.VERSION);
})
.catch(err => {
console.log('Cannot open dexie', err);
});
}, []);

const initApp = useCallback(async () => {
DataService.addDefaultAsset(DEFAULT_TOKEN.SYMBOL, DEFAULT_TOKEN.NAME);
toggleLoading(true);
//TODO: in future check version and add action if the version is different.
DataService.save('version', APP_CONSTANTS.VERSION);
await initialize_index_db();
let data = await DataService.initAppData();
data.profile = await DataService.getProfile();
data.hasWallet = data.wallet === null ? false : true;
if (!data.hasWallet) {
localStorage.removeItem('address');
} else {
let agency = await DataService.getDefaultAgency();
if (!agency) return;
const balance = await TokenService(agency.address).getBalance();
let balance;
try {
if (!agency) throw Error('No agency');
const blcs = await TokenService(agency.address).getBalance();
balance = blcs;
} catch (err) {
balance = ethers.BigNumber.from(0);
}
data.balance = balance.toNumber();
data.agency = agency;
}
dispatch({ type: APP_ACTIONS.INIT_APP, data });
}, [dispatch]);
toggleLoading(false);
}, [toggleLoading, initialize_index_db]);

async function setAgency(agency) {
if (!agency) agency = await DataService.getDefaultAgency();
dispatch({ type: APP_ACTIONS.SET_AGENCY, data: agency });
}

async function setTokenBalance(tokenBalance) {
const setTokenBalance = useCallback(tokenBalance => {
dispatch({ type: APP_ACTIONS.SET_BALANCE, data: tokenBalance });
}
}, []);

function setHasWallet(hasWallet) {
dispatch({ type: APP_ACTIONS.SET_HASWALLET, data: hasWallet });
Expand All @@ -66,12 +92,9 @@ export const AppContextProvider = ({ children }) => {
dispatch({ type: APP_ACTIONS.SET_SCANNED_DATA, data });
}

function addRecentTx(tx) {
setRecentTx([]);
if (!Array.isArray(tx)) tx = [tx];
const arr = [...tx, ...recentTx];
setRecentTx(arr.slice(0, 3));
}
const addRecentTx = useCallback(tx => {
dispatch({ type: APP_ACTIONS.ADD_RECENT_TX, data: tx });
}, []);

return (
<AppContext.Provider
Expand All @@ -82,9 +105,12 @@ export const AppContextProvider = ({ children }) => {
scannedEthAddress: state.scannedEthAddress,
scannedAmount: state.scannedAmount,
hasWallet: state.hasWallet,
hasBackedUp: state.hasBackedUp,
contextLoading: state.contextLoading,
hasSynchronized: state.hasSynchronized,
network: state.network,
wallet: state.wallet,
recentTx,
recentTx: state.recentTx,
initApp,
setAgency,
setTokenBalance,
Expand All @@ -93,7 +119,8 @@ export const AppContextProvider = ({ children }) => {
setNetwork,
setWallet,
dispatch,
addRecentTx
addRecentTx,
toggleLoading
}}
>
{children}
Expand Down
17 changes: 17 additions & 0 deletions src/hooks/useSignature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useState, useEffect, useCallback } from 'react';

function useAuthSignature(wallet) {
const [sign, setSign] = useState(null);
const getSign = useCallback(async () => {
if (!wallet) return;
const data = Date.now().toString();
let signature = await wallet.signMessage(data);
signature = `${data}.${signature}`;
setSign(signature);
}, [wallet]);
useEffect(getSign, [getSign]);

return sign;
}

export default useAuthSignature;
Loading