Skip to content
Open
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
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["next/babel"],
"plugins": []
}
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
}
"extends": ["next/babel","next/core-web-vitals"]
}
1,145 changes: 1,034 additions & 111 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
"lint": "next lint"
},
"dependencies": {
"@blockshake/defly-connect": "^1.1.6",
"@daffiwallet/connect": "^1.0.3",
"@metamask/providers": "^11.1.0",
"@perawallet/connect": "^1.3.4",
"@txnlab/use-wallet": "^2.3.1",
"algosdk": "^2.7.0",
"aos": "^2.3.4",
"date-fns": "^2.30.0",
"eslint": "8.42.0",
"eslint-config-next": "13.4.4",
"ethers": "^6.6.4",
"ethers": "^6.10.0",
"next": "^14.0.4",
"next-auth": "^4.22.1",
"react": "18.2.0",
Expand Down
44 changes: 37 additions & 7 deletions pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,48 @@ import '../styles/style.css'
import '../styles/responsive.css'
import CustomScript from './custome';

import algosdk from 'algosdk';
import { WalletProvider, useInitializeProviders, PROVIDER_ID } from '@txnlab/use-wallet';
import { DeflyWalletConnect } from '@blockshake/defly-connect';
import { PeraWalletConnect } from '@perawallet/connect';
import { DaffiWalletConnect } from '@daffiwallet/connect';



function MyApp({ Component, pageProps }) {

return (
<>
<CustomScript/>
<Component {...pageProps} />
const providers = useInitializeProviders({
providers: [
// { id: PROVIDER_ID.DEFLY, clientStatic: DeflyWalletConnect },
{ id: PROVIDER_ID.PERA, clientStatic: PeraWalletConnect },
// { id: PROVIDER_ID.DAFFI, clientStatic: DaffiWalletConnect },
// { id: PROVIDER_ID.EXODUS }
],

nodeConfig: {
network: 'testnet',
nodeServer: 'https://testnet-api.algonode.cloud',
nodeToken: '',
nodePort: '443'
},
algosdkStatic: algosdk
})





return (
<>
<WalletProvider value={providers}>
<CustomScript/>
<Component {...pageProps} />
</WalletProvider>


</>

);
</>
);
}

export default MyApp;
5 changes: 5 additions & 0 deletions pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export default function Document() {
<body>
<Main />
<NextScript />

<script>
const global = globalThis

</script>
</body>
</Html>
)
Expand Down
41 changes: 39 additions & 2 deletions pages/auth.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ethers } from 'ethers';
import { useState } from 'react';
import { useRouter } from 'next/router';
import { useWallet } from "@txnlab/use-wallet";

const MetaMask = () => {
export default function MetaMask(){
const router = useRouter();
const [loading, setLoading] = useState(false);

Expand Down Expand Up @@ -53,4 +54,40 @@ const MetaMask = () => {
);
};

export default MetaMask;
;

export function AlgorandWallet() {
const router = useRouter();
const [loading, setLoading] = useState(false);
const { activeAccount,providers } = useWallet();


const connectWallet =()=>{
setLoading(true);
const provider = providers[0]

if (provider.isConnected) {
provider.disconnect().then(()=>{
setLoading(false);
})
} else {
provider.connect().then(()=>{
setLoading(false)
router.push('/dashboard');
});
provider.setActiveProvider();

}

}


return (
<>
<button className="btn btn_main" onClick={connectWallet} disabled={loading}>
{loading ? 'Connecting...' : activeAccount?.address? `${activeAccount.address.slice(0, 10)}.....` : 'Connect Wallet'}
</button>
</>
)
}

71 changes: 71 additions & 0 deletions pages/components/AlgorandWallet/ContractMethods/ABI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const ABI = {
"name": "bitsave",
"methods": [
{
"name": "create",
"args": [],
"returns": {
"type": "void"
}
},
{
"name": "update",
"args": [],
"returns": {
"type": "void"
}
},
{
"name": "delete",
"args": [],
"returns": {
"type": "void"
}
},
{
"name": "create_savings",
"args": [
{
"type": "pay",
"name": "pay_txn"
},
{
"type": "string",
"name": "name"
},
{
"type": "uint64",
"name": "end_time"
},
{
"type": "uint64",
"name": "penalty"
},
{
"type": "asset",
"name": "asset_id"
},
{
"type": "uint64",
"name": "interest"
},
{
"type": "uint8",
"name": "isOpted"
},
{
"type": "uint64",
"name": "charges"
}
],
"returns": {
"type": "uint64"
}
}
],
"networks": {},
"desc": "This is the bitsave parent protocol v2.0"
}


export default ABI
135 changes: 135 additions & 0 deletions pages/components/AlgorandWallet/ContractMethods/ContractCalls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import ABI from "./ABI";
import algosdk from "algosdk";
import { Buffer } from 'buffer';
import { sha512_256 } from "js-sha512";
import { TESTNET_CONFIG } from "./NodeConstants";



export const BITSAVE_CONTRACT_ID = 469459505;
export const BITSAVE_CONTRACT_ADDRESS = "X7VCPGAKFAEBLWPUEXBI6K6S5BMSTQYGYOI4SGYO4MBBCFMPO3BO53KEUA";


export const indexer = new algosdk.Indexer(TESTNET_CONFIG.NODE_TOKEN, TESTNET_CONFIG.NODE_BASEURL, TESTNET_CONFIG.NODE_PORT);
export const algodClient = new algosdk.Algodv2(TESTNET_CONFIG.NODE_TOKEN, TESTNET_CONFIG.NODE_BASEURL, TESTNET_CONFIG.NODE_PORT);



async function makeATCComposer() {
// example: ATC_CREATE
const atc = new algosdk.AtomicTransactionComposer();
return atc
}



export async function create_contract_method(sender,signer) {
const suggestedParams = await algodClient.getTransactionParams().do();
const atc = await makeATCComposer();
// ATC_CONTRACT_INIT
const contract = new algosdk.ABIContract(ABI);

//USING ATC CALL THE CREATE CONTRACT METHOD
atc.addMethodCall({
appID: BITSAVE_CONTRACT_ID,
method: contract.getMethodByName('create'),
methodArgs: [],
sender: sender,
signer: signer,
suggestedParams,
});

// example: ATC_RESULTS
const result = await atc.execute(algodClient, 4);
return(result?.methodResults)

}


export async function update_contract_method(sender,signer) {
const suggestedParams = await algodClient.getTransactionParams().do();
const atc = await makeATCComposer();
// ATC_CONTRACT_INIT
const contract = new algosdk.ABIContract(ABI);

//USING ATC CALL THE UPDATE CONTRACT METHOD
atc.addMethodCall({
appID: BITSAVE_CONTRACT_ID,
method: contract.getMethodByName('create'),
methodArgs: [],
sender: sender,
signer: signer,
suggestedParams,
});

// example: ATC_RESULTS
const result = await atc.execute(algodClient, 4);
return(result?.methodResults)

}


export async function delete_contract_method(sender,signer) {
const suggestedParams = await algodClient.getTransactionParams().do();
const atc = await makeATCComposer();
// ATC_CONTRACT_INIT
const contract = new algosdk.ABIContract(ABI);

//USING ATC CALL THE DELETE CONTRACT METHOD
atc.addMethodCall({
appID: BITSAVE_CONTRACT_ID,
method: contract.getMethodByName('create'),
methodArgs: [],
sender: sender,
signer: signer,
suggestedParams,
});

// example: ATC_RESULTS
const result = await atc.execute(algodClient, 4);
return(result?.methodResults)

}


// pay_txn,name,end_time,penalty,asset_id,interest,isOpted,charges
export async function create_savings_contract_method(sender,signer,name,deposit_amount,end_time,penalty,asset_id,interest,isOpted,charges) {
const suggestedParams = await algodClient.getTransactionParams().do();
const atc = await makeATCComposer();
// ATC_CONTRACT_INIT
const contract = new algosdk.ABIContract(ABI);

const pay_txn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({
from: sender,
suggestedParams,
to: BITSAVE_CONTRACT_ADDRESS,
amount: deposit_amount,
});

// add the transaction to the ATC with a signer
atc.addTransaction({ txn: pay_txn, signer: signer });

//USING ATC CALL THE CREATE SAVINGS CONTRACT METHOD
atc.addMethodCall({
appID: BITSAVE_CONTRACT_ID,
method: contract.getMethodByName('create'),
methodArgs: [
pay_txn,
name,
end_time,
penalty,
asset_id,
interest,
isOpted,
charges
],
sender: sender,
signer: signer,
suggestedParams,
});

// example: ATC_RESULTS
const result = await atc.execute(algodClient, 4);
return(result?.methodResults)

}
13 changes: 13 additions & 0 deletions pages/components/AlgorandWallet/ContractMethods/NodeConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const TESTNET_CONFIG = {
NODE_BASEURL : "https://testnet-api.algonode.network",
NODE_TOKEN : "",
NODE_PORT:"443",
NODE_NETWORK:"testnet"
}

export const MAINNET_CONFIG = {
NODE_BASEURL : "https://mainnet-api.algonode.cloud",
NODE_TOKEN : "",
NODE_PORT:"443",
NODE_NETWORK:"mainnet"
}
Loading