This repository has been archived by the owner on Jan 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Dhaiwat10/restrictions
Add withdrawal restrictions (#1)
- Loading branch information
Showing
7 changed files
with
744 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
ROPSTEN_PRIVATE_KEY= | ||
INFURA_API_KEY= | ||
NEXT_PUBLIC_CONTRACT_ADDRESS= | ||
CALLER_SECRET= | ||
CALLER_SECRET= | ||
FIREBASE_API_KEY= | ||
FIREBASE_AUTH_DOMAIN= | ||
FIREBASE_PROJECT_ID= | ||
FIREBASE_STORAGE_BUCKET= | ||
FIREBASE_MESSAGING_ID= | ||
FIREBASE_APP_ID= | ||
FIREBASE_MEASUREMENT_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0xEccA7BF722455A94b9e759247aB86E2e1559c871 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { firebase } from './firebase'; | ||
|
||
export const validateRequest = async (address: string): Promise<boolean> => { | ||
try { | ||
const ref = firebase.database().ref('addresses/'); | ||
const currentTime = Date.now(); | ||
|
||
const snapshot = await ref.child(address).get(); | ||
|
||
if (snapshot.exists()) { | ||
// Previous record exists | ||
|
||
// Validate request | ||
if (currentTime - snapshot.val() < 8.64e7) { | ||
// Cooldown not over yet | ||
return false; | ||
} else { | ||
// Cooldown over | ||
return true; | ||
} | ||
} else { | ||
// Allow withdrawal | ||
return true; | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
}; | ||
|
||
export const createRecord = async (address: string): Promise<boolean> => { | ||
try { | ||
const currentTime = Date.now(); | ||
const ref = firebase.database().ref('addresses/' + address); | ||
await ref.set(currentTime); | ||
return true; | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import firebase from 'firebase/app'; | ||
import 'firebase/firebase-database'; | ||
|
||
const firebaseConfig = { | ||
apiKey: process.env.FIREBASE_API_KEY, | ||
authDomain: process.env.FIREBASE_AUTH_DOMAIN, | ||
projectId: process.env.FIREBASE_PROJECT_ID, | ||
storageBucket: process.env.FIREBASE_STORAGE_BUCKET, | ||
messagingSenderId: process.env.FIREBASE_MESSAGING_ID, | ||
appId: process.env.FIREBASE_APP_ID, | ||
measurementId: process.env.FIREBASE_MEASUREMENT_ID, | ||
}; | ||
|
||
if (typeof window !== 'undefined' && !firebase.apps.length) { | ||
firebase.initializeApp(firebaseConfig); | ||
firebase.database(); | ||
} | ||
|
||
export { firebase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91d7dde
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: