├── src ├── dbank_frontend │ ├── src │ │ ├── vite-env.d.ts │ │ ├── index.scss │ │ ├── main.js │ │ └── logo2.svg │ ├── assets │ │ ├── favicon.ico │ │ ├── dbank_logo.png │ │ ├── .ic-assets.json5 │ │ └── main.css │ ├── tsconfig.json │ ├── package.json │ ├── index.html │ └── vite.config.js └── dbank_backend │ └── main.mo ├── tsconfig.json ├── .gitignore ├── package.json ├── dfx.json └── README.md /src/dbank_frontend/src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/dbank_frontend/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softenrj/Dbank--Dapp-/HEAD/src/dbank_frontend/assets/favicon.ico -------------------------------------------------------------------------------- /src/dbank_frontend/assets/dbank_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/softenrj/Dbank--Dapp-/HEAD/src/dbank_frontend/assets/dbank_logo.png -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "strict": true, 4 | "target": "ES2020", 5 | "experimentalDecorators": true, 6 | "strictPropertyInitialization": false, 7 | "moduleResolution": "node", 8 | "allowJs": true, 9 | "outDir": "HACK_BECAUSE_OF_ALLOW_JS" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Various IDEs and Editors 2 | .vscode/ 3 | .idea/ 4 | **/*~ 5 | 6 | # Mac OSX temporary files 7 | .DS_Store 8 | **/.DS_Store 9 | 10 | # dfx temporary files 11 | .dfx/ 12 | 13 | # generated files 14 | **/declarations/ 15 | 16 | # rust 17 | target/ 18 | 19 | # frontend code 20 | node_modules/ 21 | dist/ 22 | .svelte-kit/ 23 | 24 | # environment variables 25 | .env 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "engines": { 3 | "node": ">=16.0.0", 4 | "npm": ">=7.0.0" 5 | }, 6 | "name": "dbank", 7 | "scripts": { 8 | "build": "npm run build --workspaces --if-present", 9 | "prebuild": "npm run prebuild --workspaces --if-present", 10 | "pretest": "npm run prebuild --workspaces --if-present", 11 | "start": "npm start --workspaces --if-present", 12 | "test": "npm test --workspaces --if-present" 13 | }, 14 | "type": "module", 15 | "workspaces": [ 16 | "src/dbank_frontend" 17 | ] 18 | } -------------------------------------------------------------------------------- /dfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "canisters": { 3 | "dbank_backend": { 4 | "main": "src/dbank_backend/main.mo", 5 | "type": "motoko" 6 | }, 7 | "dbank_frontend": { 8 | "dependencies": [ 9 | "dbank_backend" 10 | ], 11 | "source": [ 12 | "src/dbank_frontend/dist" 13 | ], 14 | "type": "assets", 15 | "workspace": "dbank_frontend" 16 | } 17 | }, 18 | "defaults": { 19 | "build": { 20 | "args": "", 21 | "packtool": "" 22 | } 23 | }, 24 | "output_env_file": ".env", 25 | "version": 1 26 | } -------------------------------------------------------------------------------- /src/dbank_frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": ["DOM", "DOM.Iterable", "ESNext"], 6 | "allowJs": false, 7 | "skipLibCheck": true, 8 | "esModuleInterop": false, 9 | "allowSyntheticDefaultImports": true, 10 | "strict": true, 11 | "forceConsistentCasingInFileNames": true, 12 | "module": "ESNext", 13 | "moduleResolution": "Node", 14 | "resolveJsonModule": true, 15 | "isolatedModules": true, 16 | "noEmit": true, 17 | "jsx": "react-jsx", 18 | "types": ["vite/client"] 19 | }, 20 | "include": ["src"] 21 | } 22 | -------------------------------------------------------------------------------- /src/dbank_frontend/src/index.scss: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | font-size: 1.5rem; 4 | } 5 | 6 | img { 7 | max-width: 50vw; 8 | max-height: 25vw; 9 | display: block; 10 | margin: auto; 11 | } 12 | 13 | form { 14 | display: flex; 15 | justify-content: center; 16 | gap: 0.5em; 17 | flex-flow: row wrap; 18 | max-width: 40vw; 19 | margin: auto; 20 | align-items: baseline; 21 | } 22 | 23 | button[type="submit"] { 24 | padding: 5px 20px; 25 | margin: 10px auto; 26 | float: right; 27 | } 28 | 29 | #greeting { 30 | margin: 10px auto; 31 | padding: 10px 60px; 32 | border: 1px solid #222; 33 | } 34 | 35 | #greeting:empty { 36 | display: none; 37 | } 38 | -------------------------------------------------------------------------------- /src/dbank_frontend/assets/.ic-assets.json5: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "match": "**/*", 4 | 5 | // Provides a base set of security headers that will work for most dapps. 6 | // Any headers you manually specify will override the headers provided by the policy. 7 | // See 'dfx info security-policy' to see the policy and for advice on how to harden the headers. 8 | // Once you improved the headers for your dapp, set the security policy to "hardened" to disable the warning. 9 | // Options are: "hardened" | "standard" | "disabled". 10 | "security_policy": "standard", 11 | 12 | // Uncomment to disable the warning about using the 13 | // standard security policy, if you understand the risk 14 | // "disable_security_policy_warning": true, 15 | 16 | // Uncomment to redirect all requests from .raw.icp0.io to .icp0.io 17 | // "allow_raw_access": false 18 | }, 19 | ] 20 | -------------------------------------------------------------------------------- /src/dbank_frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dbank_frontend", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "setup": "npm i && dfx canister create dbank_backend && dfx generate dbank_backend && dfx deploy", 8 | "start": "vite --port 3000", 9 | "prebuild": "dfx generate", 10 | "build": "tsc && vite build", 11 | "format": "prettier --write \"src/**/*.{json,js,jsx,ts,tsx,css,scss}\"" 12 | }, 13 | "devDependencies": { 14 | "@testing-library/jest-dom": "^5.16.5", 15 | "cross-fetch": "^3.1.6", 16 | "dotenv": "^16.3.1", 17 | "sass": "^1.63.6", 18 | "typescript": "^5.1.3", 19 | "vite": "^4.3.9", 20 | "vite-plugin-environment": "^1.1.3", 21 | "vitest": "^0.32.2" 22 | }, 23 | "dependencies": { 24 | "@dfinity/agent": "^1.4.0", 25 | "@dfinity/candid": "^1.4.0", 26 | "@dfinity/principal": "^1.4.0", 27 | "lit-html": "^2.8.0" 28 | } 29 | } -------------------------------------------------------------------------------- /src/dbank_frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DBank 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | DBank logo 15 |

Current Balance: $234

16 |
17 |
18 |

Amount to Top Up

19 | 20 |

Amount to Withdraw

21 | 22 | 23 |
24 |
25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/dbank_frontend/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import { fileURLToPath, URL } from 'url'; 3 | import environment from 'vite-plugin-environment'; 4 | import dotenv from 'dotenv'; 5 | 6 | dotenv.config({ path: '../../.env' }); 7 | 8 | export default defineConfig({ 9 | build: { 10 | emptyOutDir: true, 11 | }, 12 | optimizeDeps: { 13 | esbuildOptions: { 14 | define: { 15 | global: "globalThis", 16 | }, 17 | }, 18 | }, 19 | server: { 20 | proxy: { 21 | "/api": { 22 | target: "http://127.0.0.1:4943", 23 | changeOrigin: true, 24 | }, 25 | }, 26 | }, 27 | publicDir: "assets", 28 | plugins: [ 29 | environment("all", { prefix: "CANISTER_" }), 30 | environment("all", { prefix: "DFX_" }), 31 | ], 32 | resolve: { 33 | alias: [ 34 | { 35 | find: "declarations", 36 | replacement: fileURLToPath( 37 | new URL("../declarations", import.meta.url) 38 | ), 39 | }, 40 | ], 41 | }, 42 | }); 43 | -------------------------------------------------------------------------------- /src/dbank_backend/main.mo: -------------------------------------------------------------------------------- 1 | import Time "mo:base/Time"; 2 | import Float "mo:base/Float"; 3 | import Debug "mo:base/Debug"; 4 | actor dbank{ 5 | var currValue:Float = 300; 6 | currValue := 100; 7 | 8 | stable var start_time = Time.now(); 9 | start_time := Time.now(); 10 | 11 | public func topup(amount: Float){ 12 | currValue += amount; 13 | }; 14 | 15 | public func withdrow(amount:Float){ 16 | var tp = amount; 17 | if(tp > 0){ 18 | currValue -= amount; 19 | }else{ 20 | Debug.print("Amount is not be zero or negative"); 21 | } 22 | }; 23 | 24 | public func compound(){ 25 | let currentTime = Time.now(); 26 | let timeElapsedNS = currentTime - start_time; 27 | let timeElapsedS = timeElapsedNS / 1000000000; 28 | currValue := currValue * (1.01 ** Float.fromInt(timeElapsedS)); 29 | start_time := currentTime; 30 | }; 31 | 32 | public query func checkbalance(): async Float{ 33 | return currValue; 34 | }; 35 | 36 | public func reset(){ 37 | currValue := 0; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /src/dbank_frontend/src/main.js: -------------------------------------------------------------------------------- 1 | import { dbank_backend } from "../../declarations/dbank_backend"; 2 | window.addEventListener("load",async function(){ 3 | update(); 4 | }) 5 | 6 | async function update(){ 7 | const currAmount = await dbank_backend.checkbalance(); 8 | console.log(currAmount); 9 | document.getElementById("value").innerText = Math.round(currAmount * 100) / 100; 10 | } 11 | 12 | document.querySelector("form").addEventListener("submit",async function (e){ 13 | e.preventDefault(); 14 | const button = e.target.querySelector("#submit-btn"); 15 | 16 | const inputAmount = parseFloat(document.getElementById("input-amount").value); 17 | const outputAmount = parseFloat(document.getElementById("withdrawal-amount").value); 18 | 19 | button.setAttribute("disabled", true); 20 | 21 | if (document.getElementById("input-amount").value.length != 0) { 22 | await dbank_backend.topup(inputAmount); 23 | } 24 | 25 | if (document.getElementById("withdrawal-amount").value.length != 0) { 26 | await dbank_backend.withdrow(outputAmount); 27 | } 28 | 29 | await dbank_backend.compound(); 30 | 31 | update() 32 | 33 | document.getElementById("input-amount").value = ""; 34 | document.getElementById("withdrawal-amount").value = ""; 35 | 36 | button.removeAttribute("disabled"); 37 | 38 | }) 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `Dbank - Decentralized Banking Application` 2 | 3 | Dbank is a decentralized banking application (DApp) built on the Internet Computer platform. It allows users to manage their finances through a simple and secure interface. Users can perform actions such as depositing, withdrawing, and compounding their funds. 4 | 5 | ## Features 6 | 7 | - **Check Balance**: Users can view their current balance. 8 | - **Top Up**: Deposit funds into their account. 9 | - **Withdraw**: Withdraw funds from their account. 10 | - **Compound Interest**: Automatically add interest to their account balance. 11 | 12 | ## Technologies Used 13 | 14 | - **Frontend**: HTML, CSS, JavaScript, Vite 15 | - **Backend**: Motoko (Internet Computer) 16 | - **Development Tools**: DFX, npm 17 | 18 | ## Installation 19 | 20 | 1. Clone the repository: 21 | ```bash 22 | git clone https://github.com/softenrj/Dbank--Dapp-.git 23 | 24 | 2. Navigate to the project directory: 25 | ```bash 26 | cd dbank 27 | 28 | 3. Install dependencies:: 29 | ```bash 30 | npm i 31 | 32 | ## Running the Application 33 | 1. Start the local DFX server: 34 | ```bash 35 | dfx start 36 | 37 | 2. Build and deploy the canisters: 38 | ```bash 39 | dfx deploy 40 | 3. ```bash 41 | npm start 42 | 43 | 4. Open your browser and navigate to the provided URL (usually http://localhost:3000). 44 | 45 | ## Usage 46 | 1. Open the application in your browser. 47 | 2. Use the provided interface to check your balance, top up, withdraw, or compound your funds. 48 | 49 | ## Contributing 50 | Contributions are welcome! If you'd like to contribute to Dbank, please fork the repository and create a pull request. 51 | 52 | ## License 53 | This project is licensed under the MIT License - see the LICENSE file for details. 54 | 55 | ## Acknowledgments 56 | 57 | - **[Internet Computer](https://internetcomputer.org/)** 58 | - **[Vite](https://vitejs.dev/)** 59 | - **[Motoko](https://internetcomputer.org/docs/current/motoko/main/writing-motoko/writing-intro)** 60 | 61 | -------------------------------------------------------------------------------- /src/dbank_frontend/assets/main.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | background-color: #211F2B; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; 5 | -webkit-font-smoothing: antialiased; 6 | -moz-osx-font-smoothing: grayscale; 7 | text-align: center; 8 | } 9 | 10 | h1, 11 | h2 { 12 | margin: 0; 13 | } 14 | 15 | h1 { 16 | color: white; 17 | font-size: 16px; 18 | font-weight: 500; 19 | margin-top: 10px; 20 | } 21 | 22 | h2 { 23 | color: rgba(255, 255, 255, 0.5); 24 | font-size: 14px; 25 | font-weight: 500; 26 | margin-bottom: 10px; 27 | } 28 | 29 | form { 30 | margin: 0; 31 | padding: 0; 32 | width: 100%; 33 | } 34 | 35 | .divider { 36 | width: 100px; 37 | height: 3px; 38 | margin: 20px auto; 39 | background-color: #617BFF; 40 | } 41 | 42 | input, 43 | textarea { 44 | position: relative; 45 | text-align: center; 46 | display: block; 47 | margin: 0; 48 | border-radius: 7px; 49 | border: 2px white solid; 50 | background-color: white; 51 | padding: 10px 20px; 52 | width: 100%; 53 | color: #1E1C29; 54 | margin-bottom: 20px; 55 | box-sizing: border-box; 56 | transition: all 0.2s; 57 | } 58 | 59 | input:focus, 60 | textarea:focus { 61 | outline: none; 62 | border: 2px #617BFF solid; 63 | } 64 | 65 | .container { 66 | background-color: rgba(255, 255, 255, 0.1); 67 | width: 300px; 68 | margin: 0 auto; 69 | border-radius: 14px; 70 | padding: 30px 30px 20px 30px; 71 | margin-top: 50px; 72 | } 73 | 74 | input[name="amount"] { 75 | font-size: 20px; 76 | font-weight: 600; 77 | } 78 | 79 | input[type=number]::-webkit-inner-spin-button, 80 | input[type=number]::-webkit-outer-spin-button { 81 | -webkit-appearance: none; 82 | margin: 0; 83 | } 84 | 85 | #submit-btn { 86 | display: block; 87 | text-decoration: none; 88 | border-radius: 7px; 89 | margin-bottom: 10px; 90 | cursor: pointer; 91 | font-size: 20px; 92 | font-weight: 600; 93 | border: 2px #617BFF solid; 94 | color: white; 95 | background-color: #617BFF; 96 | padding: 15px; 97 | transition: all 0.2s; 98 | } 99 | 100 | #submit-btn:hover { 101 | border: 2px #8095FF solid; 102 | background-color: #8095FF; 103 | } 104 | 105 | #submit-btn:disabled { 106 | border: 2px rgba(255, 255, 255, 0.1) solid; 107 | background-color: rgba(255, 255, 255, 0.1); 108 | } 109 | 110 | textarea[name="address"] { 111 | resize: none; 112 | font-size: 16px; 113 | font-weight: 600; 114 | padding: 10px 2.7rem; 115 | font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace; 116 | } -------------------------------------------------------------------------------- /src/dbank_frontend/src/logo2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | --------------------------------------------------------------------------------