Members
# constant fetchContLastMonth
Function used to fetch the number of contributors who performed any tranasaction over last 30 days from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchDonPerMonth
Function used to fetch a map containing the last 12 months with the number of donations associated to each month
from the features
object located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchMetaState
A function to return the state of the MetaMask connection state.
# constant fetchReceivers
Function used to fetch the number of receivers (occured in transactions where the address was declared as receiver) from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchReceiversLM
Function used to fetch the number of receivers (occured in transactions where the address was declared as receiver) over the last 30 days
from the features
object located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchRecMap
Function used to fetch a map containing the receivers with the number of transactions associated to each receiver
from the features
object located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchTopSenders
Function used to fetch the top senders from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchTotalSenders
Function used to fetch the number of senders from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchTotalUsers
Function used to fetch the number of unique users from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchTransCount
Function used to fetch the number of transactions stored in the contract from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
# constant fetchTransLastMonth
Function used to fetch the number of transactions performed over last 30 days from the features
object
located in the extractFeatures
function.
The processed data comes from the smart contract deployed on the blockchain network.
!IMPORTANT! If the the extractFeatures
function is not called before calling this function,
the data returned by this function will be outdated. (dating back to the last time the extractFeatures
function was called)
Methods
# App() → {ReactComponent}
React functional component to display the application, wrapped in a router to point to the different pages
the application component
ReactComponent
# authenticateUser(req, res)
Function used to authenticate the user by comparing the address provided with the address in the database.
If the function is called the nonce is changed regardless of whether the user is authenticated or not.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# checkStateFb() → {Object}
Function used to check if there is a saved state in session storage
the state if there is one, else the initialState
Object
# checkStateUser() → {Object}
Function used to check if there is a saved state in session storage
the state if there is one, else the initialState
Object
# checkUser(address) → {Promise.<Object>}
Function used to check if the user exists in the database
Parameters:
Name | Type | Description |
---|---|---|
address |
String
|
the address of the user to be checked |
a promise that resolves to the response from the database or rejects with an error
Promise.<Object>
# createfb(fbData) → {Promise.<Object>}
Function used to create a new foodbank in the database
Parameters:
Name | Type | Description |
---|---|---|
fbData |
Object
|
the data of the foodbank to be sent to the database |
a promise that resolves to the response from the database or rejects with an error if the foodbank already exists
Promise.<Object>
# createFb(req, res)
Function used to create a food bank in the database
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# createUser(req, res)
Function used to create a user in the database.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# extractFeatures() → {Promise.<Object>}
Function to extract features from the smart contract deployed on the blockchain network using Web3. This function is called when the app is loaded and it prepares the data to be consumed by various components. The data is fetched by calling additional functions.
- returns a promise that resolves to the features object or rejects with an error
Promise.<Object>
# FBProvider(children)
The provider to be used to handle the global state of foodbanks to be used in any component of the application
Parameters:
Name | Type | Description |
---|---|---|
children |
ReactComponent
|
the children provider will be wrapped around |
- See:
-
- https://reactjs.org/docs/hooks-reference.html#usecontext for more information the useContext hook
# fbReducers(state, action) → {Object}
The reducer function used to interact with the global state of foodbanks
Parameters:
Name | Type | Description |
---|---|---|
state |
Object
|
the passed state |
action |
String
|
the action to be performed |
- See:
-
- https://reactjs.org/docs/hooks-reference.html#usereducer for more information the reducer hook
if the action is not recognised
Error
the new state
Object
# fetchInventory(req, res)
Function used to fetch the inventory of a user in the database.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# findUser(req, res)
Function used to find a user in the database based on the address.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# generateNonce() → {String}
Function used to generate a unique nonce to be asssigned to a user in the database. The nonce is a 16 character string containing upper and lower case letters and numbers.
a uniquely generated nonce
String
# getData() → {Promise.<object>}
Function used to extract the elements needed from the web 3 instance
the promise that resolves to the web3Elements
object or rejects with an error
Promise.<object>
# getfb() → {Promise.<Object>}
Function used to fetch all the foodbanks from the database
a promise that resolves to the response from the database with all the foobanks found or rejects with an error
Promise.<Object>
# getFoodBanks(res)
Function used to fetch the food banks from the database
Parameters:
Name | Type | Description |
---|---|---|
res |
Object
|
the response object from the server |
# getOneFb(req, res)
Function used to fetch one food bank from the database
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# getWeb3() → {Promise.<Web3>}
Function the fetch the web 3 instance based on the enviroment the application is opened in.
!IMPORTANT: If using a local provider (e.g. ganache-cli, truffle), make sure to update the address in the provider
variable
The promise that resolves to the web 3 instance or rejects with an error
Promise.<Web3>
# getWeb3Http() → {Promise.<object>}
Function used to fetch the web 3 elements from a http rpc provider regardless of browser instance
!IMPORTANT: If using a local provider (e.g. ganache-cli, truffle), make sure to update the address in the provider
variable
the promise that resolves to the web3Elements
object or rejects with an error
Promise.<object>
# LoginLogic() → {function}
The function used to handle the Web3 authentication logic using MetaMask
!IMPORTANT! The user must use MetaMask for the function to work as it is entirely dependent on the fetchData
function
handleLogin
the function to be called when authentication is attempted
function
# loginUser(req, res)
Function used to login the user and compare the address provided with the address in the database.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# sendData(addressIn, contentIn) → {object|null}
Function to send the data to initaite the transaction on blockchain
- The page will be refreshed after each transaction attempt to avoid the user to send the same data twice and refresh the web3 instance
- If the transaction is succesfull it will generate an alert with the transaction hash
Parameters:
Name | Type | Description |
---|---|---|
addressIn |
String
|
the address of the receiver |
contentIn |
String
|
the content of the transaction (the goods) |
the transaction error object or null if the transaction was successful
object
|
null
# StateProvider(children)
The provider to be used to handle the global state of the user to be used in any component of the application
Parameters:
Name | Type | Description |
---|---|---|
children |
ReactComponent
|
the children provider will be wrapped around |
- See:
-
- https://reactjs.org/docs/hooks-reference.html#usecontext for more information the useContext hook
# updateFb(fbData) → {Promise.<Object>}
Function used to update the foodbank's data in the database
Parameters:
Name | Type | Description |
---|---|---|
fbData |
Object
|
the data of the foodbank to be sent to the database |
a promise that resolves to the response from the database or rejects with an error
Promise.<Object>
# updateFB(req, res)
Function used to update one food bank in the database
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# updateInventory(items, address) → {Promise.<Object>}
Function used to handle the update of user's inventory in the database
Parameters:
Name | Type | Description |
---|---|---|
items |
Array.<Object>
|
array of items to be sent to the database |
address |
String
|
the address of the user holding the items |
a promise that resolves to the response from the database or rejects with an error
Promise.<Object>
# updateUser(req, res)
Function used to update the inventory of a user in the database.
Parameters:
Name | Type | Description |
---|---|---|
req |
Object
|
the request object from the front end |
res |
Object
|
the response object from the server |
# useEdit(validate) → {Object}
The function used to handle the logic of the EditFoodBank
component
makes the api call to update the foodbank using the updateFb
function
makes the api call to create a new foodbank using the createfb
function
Parameters:
Name | Type | Description |
---|---|---|
validate |
function
|
the function to validate the input |
the object containing the functions and data to be used in the main component
Object
# useForm(callback, validate) → {Object}
The function the handle the logic of the transfer form and the validation of the data before attepmting to submit the transaction to the blockchain
Parameters:
Name | Type | Description |
---|---|---|
callback |
function
|
the callback function used to fetch the submission state from the parent component |
validate |
function
|
the function to validate the inputs |
the functions required by the TransferFill component
Object
# useHorizontalScroll() → {RefObject}
The function used to enable horisontal scrolling on the showcase component
the refrence to be used in the component
RefObject
# useList(validate)
Holds the functions needed during user interaction i.e. adding, deleting.. and makes api call to update the list if the used is logged in.
Parameters:
Name | Type | Description |
---|---|---|
validate |
function
|
the function used to validate the inputs of the form |
the functions needed during filling with the item list and the error list
# userReducers(state, action) → {Object}
The reducer function used to interact with the state
Parameters:
Name | Type | Description |
---|---|---|
state |
Object
|
the passed state |
action |
String
|
the action to be performed |
- See:
-
- https://reactjs.org/docs/hooks-reference.html#usereducer for more information the reducer hook
if the action is not recognised
Error
the new state
Object
# useSearch(error) → {function|Array|Boolean|Boolean}
The function to hadle the logic behind the search transaction feature. The data is fetched by calling
the getWeb3Http
and extracting all the transactions from the response
Parameters:
Name | Type | Description |
---|---|---|
error |
String
|
the error generated after the validation of the input |
handleSearch - the function that handles the search transaction
function
results - the array of the results of the search
Array
isFetching - the boolean that indicates if the search is being executed
Boolean
found - the boolean that indicates if the search was successful
Boolean
# validateEdit(values)
Function used to validate the input of the edit foodbank form EditFoodBank
Parameters:
Name | Type | Description |
---|---|---|
values |
Object
|
the values to be validated |
an array of errors
# validateInfo(values) → {Array}
Function used to validate the input of the list form from the ListFill component
Parameters:
Name | Type | Description |
---|---|---|
values |
Object
|
the input to be validated |
the array of errors found
Array
# validateInput(value) → {Array}
Function used to validate the input of the list form from the ListFill component
Parameters:
Name | Type | Description |
---|---|---|
value |
Object
|
the input to be validated |
- the array of errors found
Array
# validateRegister(values) → {Array}
Function used to validate the user input of the register form
Parameters:
Name | Type | Description |
---|---|---|
values |
Object
|
the values to be validated |
the array of errors found
Array
# validateSearch(value)
Function to validate the input of the search field
Parameters:
Name | Type | Description |
---|---|---|
value |
Object
|
the input to be validated |