From 4403545e6c246f8bf5cfea6f7de912f00b0f61a5 Mon Sep 17 00:00:00 2001 From: MarvyNwaokobia Date: Fri, 26 Apr 2024 19:53:30 +0100 Subject: [PATCH 1/2] feat: made burner wallet and modals functional --- frontend/.eslintrc.json | 4 +- frontend/.gitignore | 2 +- frontend/package-lock.json | 9 + frontend/package.json | 1 + frontend/public/abi/strk_abi.json | 1122 +++++++++++++++++ .../src/app/components/AssetTransferModal.tsx | 71 +- frontend/src/app/components/Burner/Burner.tsx | 12 +- .../components/BurnerWallet/BurnerWallet.tsx | 128 +- .../src/app/components/ConnectionModal.tsx | 35 +- .../src/app/components/StarknetProvider.tsx | 14 +- frontend/yarn.lock | 21 +- 11 files changed, 1333 insertions(+), 86 deletions(-) create mode 100644 frontend/public/abi/strk_abi.json diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index bffb357..32d9e5e 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -1,3 +1,3 @@ { - "extends": "next/core-web-vitals" -} + "extends": "next/core-web-vitals" + } \ No newline at end of file diff --git a/frontend/.gitignore b/frontend/.gitignore index 00bba9b..86f0706 100644 --- a/frontend/.gitignore +++ b/frontend/.gitignore @@ -34,4 +34,4 @@ yarn-error.log* # typescript *.tsbuildinfo -next-env.d.ts +next-env.d.ts \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 832b4e2..9fc0c25 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -15,6 +15,7 @@ "@starknet-react/core": "^2.6.0", "@tanstack/react-table": "^8.12.0", "@types/react-blockies": "^1.4.4", + "bignumber.js": "^9.1.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "cmdk": "^0.2.1", @@ -2187,6 +2188,14 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/bignumber.js": { + "version": "9.1.2", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", + "integrity": "sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==", + "engines": { + "node": "*" + } + }, "node_modules/binary-extensions": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", diff --git a/frontend/package.json b/frontend/package.json index 7608f5a..f802e13 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -16,6 +16,7 @@ "@starknet-react/core": "^2.6.0", "@tanstack/react-table": "^8.12.0", "@types/react-blockies": "^1.4.4", + "bignumber.js": "^9.1.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "cmdk": "^0.2.1", diff --git a/frontend/public/abi/strk_abi.json b/frontend/public/abi/strk_abi.json new file mode 100644 index 0000000..a9af211 --- /dev/null +++ b/frontend/public/abi/strk_abi.json @@ -0,0 +1,1122 @@ +[ + { + "type": "impl", + "name": "LockingContract", + "interface_name": "src::mintable_lock_interface::ILockingContract" + }, + { + "type": "interface", + "name": "src::mintable_lock_interface::ILockingContract", + "items": [ + { + "type": "function", + "name": "set_locking_contract", + "inputs": [ + { + "name": "locking_contract", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "get_locking_contract", + "inputs": [], + "outputs": [ + { + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "LockAndDelegate", + "interface_name": "src::mintable_lock_interface::ILockAndDelegate" + }, + { + "type": "struct", + "name": "core::integer::u256", + "members": [ + { + "name": "low", + "type": "core::integer::u128" + }, + { + "name": "high", + "type": "core::integer::u128" + } + ] + }, + { + "type": "interface", + "name": "src::mintable_lock_interface::ILockAndDelegate", + "items": [ + { + "type": "function", + "name": "lock_and_delegate", + "inputs": [ + { + "name": "delegatee", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "lock_and_delegate_by_sig", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "delegatee", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + }, + { + "name": "nonce", + "type": "core::felt252" + }, + { + "name": "expiry", + "type": "core::integer::u64" + }, + { + "name": "signature", + "type": "core::array::Array::" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "impl", + "name": "MintableToken", + "interface_name": "src::mintable_token_interface::IMintableToken" + }, + { + "type": "interface", + "name": "src::mintable_token_interface::IMintableToken", + "items": [ + { + "type": "function", + "name": "permissioned_mint", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "permissioned_burn", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "impl", + "name": "MintableTokenCamelImpl", + "interface_name": "src::mintable_token_interface::IMintableTokenCamel" + }, + { + "type": "interface", + "name": "src::mintable_token_interface::IMintableTokenCamel", + "items": [ + { + "type": "function", + "name": "permissionedMint", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "permissionedBurn", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "impl", + "name": "Replaceable", + "interface_name": "src::replaceability_interface::IReplaceable" + }, + { + "type": "struct", + "name": "core::array::Span::", + "members": [ + { + "name": "snapshot", + "type": "@core::array::Array::" + } + ] + }, + { + "type": "struct", + "name": "src::replaceability_interface::EICData", + "members": [ + { + "name": "eic_hash", + "type": "core::starknet::class_hash::ClassHash" + }, + { + "name": "eic_init_data", + "type": "core::array::Span::" + } + ] + }, + { + "type": "enum", + "name": "core::option::Option::", + "variants": [ + { + "name": "Some", + "type": "src::replaceability_interface::EICData" + }, + { + "name": "None", + "type": "()" + } + ] + }, + { + "type": "enum", + "name": "core::bool", + "variants": [ + { + "name": "False", + "type": "()" + }, + { + "name": "True", + "type": "()" + } + ] + }, + { + "type": "struct", + "name": "src::replaceability_interface::ImplementationData", + "members": [ + { + "name": "impl_hash", + "type": "core::starknet::class_hash::ClassHash" + }, + { + "name": "eic_data", + "type": "core::option::Option::" + }, + { + "name": "final", + "type": "core::bool" + } + ] + }, + { + "type": "interface", + "name": "src::replaceability_interface::IReplaceable", + "items": [ + { + "type": "function", + "name": "get_upgrade_delay", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u64" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "get_impl_activation_time", + "inputs": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData" + } + ], + "outputs": [ + { + "type": "core::integer::u64" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "add_new_implementation", + "inputs": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "remove_implementation", + "inputs": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "replace_to", + "inputs": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "impl", + "name": "AccessControlImplExternal", + "interface_name": "src::access_control_interface::IAccessControl" + }, + { + "type": "interface", + "name": "src::access_control_interface::IAccessControl", + "items": [ + { + "type": "function", + "name": "has_role", + "inputs": [ + { + "name": "role", + "type": "core::felt252" + }, + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "get_role_admin", + "inputs": [ + { + "name": "role", + "type": "core::felt252" + } + ], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "RolesImpl", + "interface_name": "src::roles_interface::IMinimalRoles" + }, + { + "type": "interface", + "name": "src::roles_interface::IMinimalRoles", + "items": [ + { + "type": "function", + "name": "is_governance_admin", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "is_upgrade_governor", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "register_governance_admin", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "remove_governance_admin", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "register_upgrade_governor", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "remove_upgrade_governor", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "external" + }, + { + "type": "function", + "name": "renounce", + "inputs": [ + { + "name": "role", + "type": "core::felt252" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "impl", + "name": "ERC20Impl", + "interface_name": "openzeppelin::token::erc20::interface::IERC20" + }, + { + "type": "interface", + "name": "openzeppelin::token::erc20::interface::IERC20", + "items": [ + { + "type": "function", + "name": "name", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "symbol", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "decimals", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u8" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "total_supply", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "balance_of", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "allowance", + "inputs": [ + { + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "transfer", + "inputs": [ + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "transfer_from", + "inputs": [ + { + "name": "sender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "approve", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + } + ] + }, + { + "type": "impl", + "name": "ERC20CamelOnlyImpl", + "interface_name": "openzeppelin::token::erc20::interface::IERC20CamelOnly" + }, + { + "type": "interface", + "name": "openzeppelin::token::erc20::interface::IERC20CamelOnly", + "items": [ + { + "type": "function", + "name": "totalSupply", + "inputs": [], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "balanceOf", + "inputs": [ + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [ + { + "type": "core::integer::u256" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "transferFrom", + "inputs": [ + { + "name": "sender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "amount", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + } + ] + }, + { + "type": "constructor", + "name": "constructor", + "inputs": [ + { + "name": "name", + "type": "core::felt252" + }, + { + "name": "symbol", + "type": "core::felt252" + }, + { + "name": "decimals", + "type": "core::integer::u8" + }, + { + "name": "initial_supply", + "type": "core::integer::u256" + }, + { + "name": "recipient", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "permitted_minter", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "provisional_governance_admin", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "upgrade_delay", + "type": "core::integer::u64" + } + ] + }, + { + "type": "function", + "name": "increase_allowance", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "added_value", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "decrease_allowance", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "subtracted_value", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "increaseAllowance", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "addedValue", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "function", + "name": "decreaseAllowance", + "inputs": [ + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress" + }, + { + "name": "subtractedValue", + "type": "core::integer::u256" + } + ], + "outputs": [ + { + "type": "core::bool" + } + ], + "state_mutability": "external" + }, + { + "type": "event", + "name": "src::strk::erc20_lockable::ERC20Lockable::Transfer", + "kind": "struct", + "members": [ + { + "name": "from", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "to", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "value", + "type": "core::integer::u256", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::strk::erc20_lockable::ERC20Lockable::Approval", + "kind": "struct", + "members": [ + { + "name": "owner", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "spender", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "value", + "type": "core::integer::u256", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::replaceability_interface::ImplementationAdded", + "kind": "struct", + "members": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::replaceability_interface::ImplementationRemoved", + "kind": "struct", + "members": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::replaceability_interface::ImplementationReplaced", + "kind": "struct", + "members": [ + { + "name": "implementation_data", + "type": "src::replaceability_interface::ImplementationData", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::replaceability_interface::ImplementationFinalized", + "kind": "struct", + "members": [ + { + "name": "impl_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::access_control_interface::RoleGranted", + "kind": "struct", + "members": [ + { + "name": "role", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "sender", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::access_control_interface::RoleRevoked", + "kind": "struct", + "members": [ + { + "name": "role", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "account", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "sender", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::access_control_interface::RoleAdminChanged", + "kind": "struct", + "members": [ + { + "name": "role", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "previous_admin_role", + "type": "core::felt252", + "kind": "data" + }, + { + "name": "new_admin_role", + "type": "core::felt252", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::roles_interface::GovernanceAdminAdded", + "kind": "struct", + "members": [ + { + "name": "added_account", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "added_by", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::roles_interface::GovernanceAdminRemoved", + "kind": "struct", + "members": [ + { + "name": "removed_account", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "removed_by", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::roles_interface::UpgradeGovernorAdded", + "kind": "struct", + "members": [ + { + "name": "added_account", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "added_by", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::roles_interface::UpgradeGovernorRemoved", + "kind": "struct", + "members": [ + { + "name": "removed_account", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + }, + { + "name": "removed_by", + "type": "core::starknet::contract_address::ContractAddress", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "src::strk::erc20_lockable::ERC20Lockable::Event", + "kind": "enum", + "variants": [ + { + "name": "Transfer", + "type": "src::strk::erc20_lockable::ERC20Lockable::Transfer", + "kind": "nested" + }, + { + "name": "Approval", + "type": "src::strk::erc20_lockable::ERC20Lockable::Approval", + "kind": "nested" + }, + { + "name": "ImplementationAdded", + "type": "src::replaceability_interface::ImplementationAdded", + "kind": "nested" + }, + { + "name": "ImplementationRemoved", + "type": "src::replaceability_interface::ImplementationRemoved", + "kind": "nested" + }, + { + "name": "ImplementationReplaced", + "type": "src::replaceability_interface::ImplementationReplaced", + "kind": "nested" + }, + { + "name": "ImplementationFinalized", + "type": "src::replaceability_interface::ImplementationFinalized", + "kind": "nested" + }, + { + "name": "RoleGranted", + "type": "src::access_control_interface::RoleGranted", + "kind": "nested" + }, + { + "name": "RoleRevoked", + "type": "src::access_control_interface::RoleRevoked", + "kind": "nested" + }, + { + "name": "RoleAdminChanged", + "type": "src::access_control_interface::RoleAdminChanged", + "kind": "nested" + }, + { + "name": "GovernanceAdminAdded", + "type": "src::roles_interface::GovernanceAdminAdded", + "kind": "nested" + }, + { + "name": "GovernanceAdminRemoved", + "type": "src::roles_interface::GovernanceAdminRemoved", + "kind": "nested" + }, + { + "name": "UpgradeGovernorAdded", + "type": "src::roles_interface::UpgradeGovernorAdded", + "kind": "nested" + }, + { + "name": "UpgradeGovernorRemoved", + "type": "src::roles_interface::UpgradeGovernorRemoved", + "kind": "nested" + } + ] + } +] diff --git a/frontend/src/app/components/AssetTransferModal.tsx b/frontend/src/app/components/AssetTransferModal.tsx index 0f4760e..291e45d 100644 --- a/frontend/src/app/components/AssetTransferModal.tsx +++ b/frontend/src/app/components/AssetTransferModal.tsx @@ -4,21 +4,41 @@ import starknetLogo from "../../../public/starknetlogo.svg"; import Image from "next/image"; import rightArr from "../../../public/assets/right-arr.svg"; import { useEffect, useState } from "react"; -import { useAccount, useBalance } from "@starknet-react/core"; import downChevron from "../../../public/assets/down-chevron.svg"; import ethLogo from "../../../public/assets/ethereumLogo2.svg"; +import { Call, Contract, RpcProvider, Uint256, cairo } from "starknet"; +import strk_abi from "./../../../public/abi/strk_abi.json"; type Props = { isOpen: boolean; onClose: () => void; + strkBalance: string | undefined; + ethBalance: string | undefined; + wallet: { + address: string; + privateKey: string; + publicKey: string; + }; + account: any; }; -function AssetTransferModal({ isOpen, onClose }: Props) { - const { address } = useAccount(); - const { isLoading, isError, error, data } = useBalance({ - address, - watch: true, +function AssetTransferModal({ + isOpen, + onClose, + strkBalance, + ethBalance, + wallet, + account, +}: Props) { + const provider = new RpcProvider({ + nodeUrl: + "https://starknet-sepolia.infura.io/v3/b935e660d34f48469cb740bfa2cfb1c0", }); + const starknet_contract = new Contract( + strk_abi, + "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", + provider + ); // Form Data const [walletAddress, setWalletAddress] = useState(""); @@ -30,7 +50,6 @@ function AssetTransferModal({ isOpen, onClose }: Props) { const [assetDropDownIsOpen, setAssetDropDownIsOpen] = useState(false); const closeModal = (e: React.MouseEvent) => { - e.stopPropagation(); setAnimate(false); setTimeout(() => { onClose(); @@ -51,6 +70,27 @@ function AssetTransferModal({ isOpen, onClose }: Props) { setAssetDropDownIsOpen(false); } + async function handleTransfer() { + try { + if (!walletAddress.length && !amount) { + return; + } + const toTransferTk: Uint256 = cairo.uint256(amount); + const transferCallData: Call = starknet_contract.populate("transfer", { + recipient: walletAddress, + amount: toTransferTk, + }); + starknet_contract.connect(account); + await starknet_contract.transfer(transferCallData.calldata); + } catch (err: any) { + console.log(err.message); + } finally { + setTimeout(() => { + onClose(); + }, 400); + } + } + return ( - {/* {isLoading && ( - spinner - )} - {data && ( -
- {Number(data.value).toFixed(4).toString()} -
- )} */} - 2.0000 + {activeToken === "strk" + ? Number(strkBalance).toFixed(4) + : Number(ethBalance).toFixed(4)} { + e.preventDefault(); + await handleTransfer(); + }} > Send right arrow diff --git a/frontend/src/app/components/Burner/Burner.tsx b/frontend/src/app/components/Burner/Burner.tsx index 9bb7b8a..bafe580 100644 --- a/frontend/src/app/components/Burner/Burner.tsx +++ b/frontend/src/app/components/Burner/Burner.tsx @@ -76,6 +76,7 @@ const Burners: React.FC = () => { if (burnerWalletDeployer) { const newWallet = await generateWallet(burnerWalletDeployer); setWallets([...wallets, newWallet]); + console.log(newWallet); } else { console.error("Burner wallet deployer is undefined."); } @@ -104,17 +105,10 @@ const Burners: React.FC = () => {
- +

Burner Wallets:

{wallets.map((wallet, index) => ( -
-

- Burner {index + 1} -

-

Private Key: {wallet.privateKey}

-

Public Key: {wallet.publicKey}

-

Account Address: {wallet.address}

-
+ ))} - - +
+ {isConnected ? ( + <> + + + + ) : ( + + )}
); diff --git a/frontend/src/app/components/ConnectionModal.tsx b/frontend/src/app/components/ConnectionModal.tsx index 991b602..6848d24 100644 --- a/frontend/src/app/components/ConnectionModal.tsx +++ b/frontend/src/app/components/ConnectionModal.tsx @@ -5,13 +5,15 @@ import { useEffect, useState } from "react"; type Props = { isOpen: boolean; onClose: () => void; + handleConnect: () => void; + wallet: { + privateKey: string; + address: string; + publicKey: string; + }; }; -function ConnectionModal({ isOpen, onClose }: Props) { - // Form Data - const [accountAddress, setAccountAddress] = useState(""); - const [privateKey, setPrivateKey] = useState(""); - +function ConnectionModal({ isOpen, onClose, handleConnect, wallet }: Props) { // useState Variables const [animate, setAnimate] = useState(false); @@ -36,7 +38,7 @@ function ConnectionModal({ isOpen, onClose }: Props) { isOpen={isOpen} onClose={closeModal} animate={animate} - className={`w-[90vw] mx-auto md:h-fit md:w-[45rem] text-white py-4 px-5 relative bg-black`} + className={`w-[90vw] mx-auto bg-white md:h-fit md:w-[45rem] text-white py-4 px-5 relative dark:bg-black`} >
-

Connect Account

+

Connect Account

-
+

Private Key

setPrivateKey(e.target.value)} + className="w-full p-2 rounded dark:text-white text-black outline-none focus:border-[#3b81f6] border-[2px] disabled:cursor-not-allowed" + value={wallet.privateKey} + disabled={true} />
@@ -78,14 +80,17 @@ function ConnectionModal({ isOpen, onClose }: Props) { setAccountAddress(e.target.value)} + className="w-full p-2 rounded dark:text-white text-black outline-none focus:border-[#3b81f6] border-[2px] disabled:cursor-not-allowed" + value={wallet.address} + disabled={true} />
-
diff --git a/frontend/src/app/components/StarknetProvider.tsx b/frontend/src/app/components/StarknetProvider.tsx index bf00aba..b3eec51 100644 --- a/frontend/src/app/components/StarknetProvider.tsx +++ b/frontend/src/app/components/StarknetProvider.tsx @@ -34,20 +34,16 @@ export function StarknetProvider({ children }: StarknetProviderProps) { const apiKey = process.env.NEXT_API_KEY!; const nodeProvider = process.env.NEXT_PROVIDER!; - let provider + let provider; if (nodeProvider == "infura") { provider = infuraProvider({ apiKey }); - } - else if(nodeProvider == "alchemy") { + } else if (nodeProvider == "alchemy") { provider = alchemyProvider({ apiKey }); - } - else if(nodeProvider == "lava") { + } else if (nodeProvider == "lava") { provider = lavaProvider({ apiKey }); - } - else if(nodeProvider == "nethermind") { + } else if (nodeProvider == "nethermind") { provider = nethermindProvider({ apiKey }); - } - else { + } else { provider = reddioProvider({ apiKey }); } diff --git a/frontend/yarn.lock b/frontend/yarn.lock index f00633c..0ac4df7 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -158,10 +158,10 @@ dependencies: glob "7.1.7" -"@next/swc-darwin-x64@14.0.4": +"@next/swc-win32-x64-msvc@14.0.4": version "14.0.4" - resolved "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.4.tgz" - integrity sha512-IZQ3C7Bx0k2rYtrZZxKKiusMTM9WWcK5ajyhOZkYYTCc8xytmwSzR1skU7qLgVT/EY9xtXDG0WhY6fyujnI3rw== + resolved "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.4.tgz" + integrity sha512-yEh2+R8qDlDCjxVpzOTEpBLQTEFAcP2A8fUFLaWNap9GitYKkKv1//y2S6XY6zsR4rCOPRpU7plYDR+az2n30A== "@noble/curves@~1.3.0": version "1.3.0" @@ -205,6 +205,11 @@ micromatch "^4.0.5" napi-wasm "^1.1.0" +"@parcel/watcher-win32-x64@2.3.0": + version "2.3.0" + resolved "https://registry.npmjs.org/@parcel/watcher-win32-x64/-/watcher-win32-x64-2.3.0.tgz" + integrity sha512-dLx+0XRdMnVI62kU3wbXvbIRhLck4aE28bIGKbRGS7BJNt54IIj9+c/Dkqb+7DJEbHUZAX1bwaoM8PqVlHJmCA== + "@parcel/watcher@^2.3.0": version "2.3.0" resolved "https://registry.npmjs.org/@parcel/watcher/-/watcher-2.3.0.tgz" @@ -1317,6 +1322,11 @@ balanced-match@^1.0.0: resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +bignumber.js@^9.1.2: + version "9.1.2" + resolved "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz" + integrity sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug== + binary-extensions@^2.0.0: version "2.2.0" resolved "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz" @@ -2146,11 +2156,6 @@ fs.realpath@^1.0.0: resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz" integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw== -fsevents@~2.3.2: - version "2.3.3" - resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz" - integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw== - function-bind@^1.1.1, function-bind@^1.1.2: version "1.1.2" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz" From fe9bd2a7b1c149628d06085d6bd1abf5f352ac3e Mon Sep 17 00:00:00 2001 From: MarvyNwaokobia Date: Sat, 27 Apr 2024 07:40:30 +0100 Subject: [PATCH 2/2] feat: added copy feature for addresses and keys --- .../components/BurnerWallet/BurnerWallet.tsx | 23 ++++------ .../src/app/components/ConnectionModal.tsx | 14 ++++-- frontend/src/app/components/CopyButton.tsx | 46 +++++++++++++++++++ 3 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 frontend/src/app/components/CopyButton.tsx diff --git a/frontend/src/app/components/BurnerWallet/BurnerWallet.tsx b/frontend/src/app/components/BurnerWallet/BurnerWallet.tsx index 18198e5..b784f33 100644 --- a/frontend/src/app/components/BurnerWallet/BurnerWallet.tsx +++ b/frontend/src/app/components/BurnerWallet/BurnerWallet.tsx @@ -5,6 +5,7 @@ import AssetTransferModal from "../AssetTransferModal"; import ConnectionModal from "../ConnectionModal"; import { useAccount, useBalance } from "@starknet-react/core"; import { Account, RpcProvider } from "starknet"; +import CopyButton from "../CopyButton"; interface IWallet { address: string; @@ -36,11 +37,6 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) { token: "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d", }); - useEffect(() => { - console.log("eth balance.....", ethBalance); - console.log("strk balance....", strkBalance); - }, [ethBalance, strkBalance]); - function handleConnect() { const provider = new RpcProvider({ nodeUrl: @@ -54,8 +50,6 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) { setAccount(account); setIsConnected(true); setIsConnecting(false); - - console.log("account connected"); } return ( @@ -103,12 +97,15 @@ function BurnerWallet({ wallet }: { wallet: IWallet }) { -

- {wallet.address - .slice(0, 12) - .concat("....") - .concat(wallet.address.slice(-6))} -

+
+

+ {wallet.address + .slice(0, 7) + .concat("....") + .concat(wallet.address.slice(-6))} +

+ +
{isConnected ? ( diff --git a/frontend/src/app/components/ConnectionModal.tsx b/frontend/src/app/components/ConnectionModal.tsx index 6848d24..19a67fb 100644 --- a/frontend/src/app/components/ConnectionModal.tsx +++ b/frontend/src/app/components/ConnectionModal.tsx @@ -1,4 +1,5 @@ "use client"; +import CopyButton from "./CopyButton"; import GenericModal from "./GenericModal"; import { useEffect, useState } from "react"; @@ -62,10 +63,13 @@ function ConnectionModal({ isOpen, onClose, handleConnect, wallet }: Props) {

Connect Account

-
+
-

Private Key

+
+

Private Key

+ +
-

Account Address

+
+

Account Address

+ +
Connect diff --git a/frontend/src/app/components/CopyButton.tsx b/frontend/src/app/components/CopyButton.tsx new file mode 100644 index 0000000..a79847a --- /dev/null +++ b/frontend/src/app/components/CopyButton.tsx @@ -0,0 +1,46 @@ +import Image from "next/image"; +import { useEffect, useState } from "react"; + +type Props = { + data: string; +}; + +function CopyButton({ data }: Props) { + const [isCopied, setIsCopied] = useState(false); + + useEffect(() => { + const id = setTimeout(() => { + setIsCopied(false); + }, 1500); + + return () => clearTimeout(id); + }, [isCopied]); + + function handleCopyClick() { + if (!data) return; + navigator.clipboard.writeText(data); + setIsCopied(true); + } + + if (!data) { + return null; + } + return ( + + ); +} + +export default CopyButton;