From ee0ee2ce7b6f33aead5fca745f7197247cc55b1f Mon Sep 17 00:00:00 2001 From: Francisco Gamundi Date: Tue, 3 Nov 2020 17:05:01 +0100 Subject: [PATCH 01/12] Added check for currently owned assets when adding a new one --- .../src/components/Account/AddAssetConfirm.ts | 9 ++++--- packages/ui/src/pages/AddAsset.ts | 26 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/ui/src/components/Account/AddAssetConfirm.ts b/packages/ui/src/components/Account/AddAssetConfirm.ts index 470c65d8..4ccb1c83 100644 --- a/packages/ui/src/components/Account/AddAssetConfirm.ts +++ b/packages/ui/src/components/Account/AddAssetConfirm.ts @@ -10,7 +10,7 @@ import { StoreContext } from 'services/StoreContext' import Authenticate from 'components/Authenticate' const AddAssetConfirm: FunctionalComponent = (props: any) => { - const { asset, ledger, address } = props; + const { asset, ledger, address, accountsAssetsIDs } = props; const store:any = useContext(StoreContext); const [askAuth, setAskAuth] = useState(false); const [loading, setLoading] = useState(false); @@ -18,6 +18,8 @@ const AddAssetConfirm: FunctionalComponent = (props: any) => { const [error, setError] = useState(''); const [txId, setTxId] = useState(''); + const disabled = accountsAssetsIDs.includes(asset['asset_id']); + const addAsset = (pwd: string) => { const params = { ledger: ledger, @@ -94,8 +96,9 @@ const AddAssetConfirm: FunctionalComponent = (props: any) => { `} diff --git a/packages/ui/src/pages/AddAsset.ts b/packages/ui/src/pages/AddAsset.ts index c90d77b9..df9ffa79 100644 --- a/packages/ui/src/pages/AddAsset.ts +++ b/packages/ui/src/pages/AddAsset.ts @@ -1,16 +1,19 @@ import { FunctionalComponent } from "preact"; import { html } from 'htm/preact'; -import { useState, useEffect } from 'preact/hooks'; +import { useState, useEffect, useContext } from 'preact/hooks'; import { route } from 'preact-router'; import { JsonRpcMethod } from '@algosigner/common/messaging/types'; -import { sendMessage } from 'services/Messaging' +import AddAssetConfirm from 'components/Account/AddAssetConfirm' +import HeaderView from 'components/HeaderView' + import { useDebounce } from 'services/customHooks' +import { sendMessage } from 'services/Messaging' +import { StoreContext } from 'services/StoreContext' -import HeaderView from 'components/HeaderView' -import AddAssetConfirm from 'components/Account/AddAssetConfirm' const AddAsset: FunctionalComponent = (props: any) => { + const store:any = useContext(StoreContext); const { matches, path, url, ledger, address } = props; const [tab, setTab] = useState(0); const [filter, setFilter] = useState(''); @@ -21,6 +24,7 @@ const AddAsset: FunctionalComponent = (props: any) => { // Verified results coming from Inc's API const [verifiedResults, setVerifiedResults] = useState({}); const [verifiedIDs, setVerifiedIDs] = useState([]); + const [accountsAssetsIDs, setAccountsAssetsIDs] = useState([]); const debouncedFilter = useDebounce(filter, 500); @@ -74,6 +78,18 @@ const AddAsset: FunctionalComponent = (props: any) => { useEffect(() => { setLoading(true); + // Load account's assets + for (var i = store[ledger].length - 1; i >= 0; i--) { + if (store[ledger][i].address === address) { + if ('details' in store[ledger][i]) { + const ids = store[ledger][i].details.assets.map(x => x['asset-id']); + setAccountsAssetsIDs(ids); + } + break; + } + } + + // Load Verified assets const params = { ledger: ledger }; @@ -170,7 +186,7 @@ const AddAsset: FunctionalComponent = (props: any) => { From 324e51cc111173e71676b33dce169959c436f7d8 Mon Sep 17 00:00:00 2001 From: Jan Marcano Date: Tue, 3 Nov 2020 13:31:19 -0300 Subject: [PATCH 02/12] Prevent the addition of duplicate accounts --- .../src/background/messaging/internalMethods.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/extension/src/background/messaging/internalMethods.ts b/packages/extension/src/background/messaging/internalMethods.ts index c54cc6c4..90163f3c 100644 --- a/packages/extension/src/background/messaging/internalMethods.ts +++ b/packages/extension/src/background/messaging/internalMethods.ts @@ -234,9 +234,15 @@ export class InternalMethods { this._encryptionWrap = new encryptionWrap(request.body.params.passphrase); try { - var recoveredAccount = algosdk.mnemonicToSecretKey(mnemonic); + var recoveredAccountAddress = algosdk.mnemonicToSecretKey(mnemonic).addr; + var existingAccounts = session.wallet[ledger]; + for (let i = 0; i < existingAccounts.length; i++) { + if (existingAccounts[i].address === recoveredAccountAddress) { + throw new Error(`Account already exists in ${ledger} wallet.`); + } + } var newAccount = { - address: recoveredAccount.addr, + address: recoveredAccountAddress, mnemonic: mnemonic, name: name }; From 82aa6b5a41f05e9187773670488c4be46a2d3d9a Mon Sep 17 00:00:00 2001 From: Brent Date: Tue, 3 Nov 2020 15:16:19 -0500 Subject: [PATCH 03/12] Revert version in zip release back to 1.0.1 --- .github/workflows/zip-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/zip-release.yml b/.github/workflows/zip-release.yml index f0f0783d..aaa6946c 100644 --- a/.github/workflows/zip-release.yml +++ b/.github/workflows/zip-release.yml @@ -27,7 +27,7 @@ jobs: id: zip_up run: zip -r AlgoSigner.zip ./dist/* - name: Upload - uses: actions/upload-release-asset@v1.1.0 + uses: actions/upload-release-asset@v1.0.1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: From f093a1258a74d4ca7fe685ca540668a575c58b57 Mon Sep 17 00:00:00 2001 From: purestakatie <54632920+purestakatie@users.noreply.github.com> Date: Tue, 3 Nov 2020 15:56:07 -0500 Subject: [PATCH 04/12] Copy update --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 70688b0b..a7ea62cf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # ![AlgoSigner](media/algosigner-wallet-banner-3.png) -An open-source Algorand wallet browser extension that permits dApp communication for signing Algorand transactions - available for Chrome initially. +An open-source Algorand wallet browser extension that permits dApp communication for signing Algorand transactions — available for Chrome initially. ## Chrome Extension Store The extension is available on the [Chrome Extension Store](https://chrome.google.com/webstore/detail/algosigner/kmmolakhbgdlpkjkcjkebenjheonagdm) @@ -13,7 +13,7 @@ Developers working with dApps may also install directly from the release package The latest release introduces several key new features for users and dApp developers. ### Asset Support in the UI -Assets have always been displayed in the UI, now you may find new assets, opt-in to them, and transfer them right in the UI. +Assets you own have always been displayed in the AlgoSigner UI, but we have added additional capabilities. Now you may search for new assets, opt-in to receive them, and transfer them right in the AlgoSigner UI. ### Asset Support for dApps dApps were previously able to send in basic asset transactions to be signed by AlgoSigner. Support has now been added for all asset transaction types with accompanying UI notices. @@ -33,11 +33,11 @@ dApp developers may now send in application transactions to be signed. This supp ### UI Transactions With the addition of support for `close-to` transactions, new warning messages will display in the UI when dApps send in pay transactions that are potentially dangerous. -The signing window will also now reflect better the ledger the dApp is asking the user to sign a transaction for. A new label is present in dark blue for Testnet and orange for Mainnet +The signing window will also now better reflect the ledger for which the dApp is asking the user to sign a transaction. A new label is present in dark blue for TestNet and orange for MainNet. ### Sample dApp and dApp Tests -* Signing app - New sample dApp for [demonstrating transaction signing](https://purestake.github.io/algosigner-dapp-example/tx-test/signTesting.html) +* Signing app — New sample dApp for [demonstrating transaction signing](https://purestake.github.io/algosigner-dapp-example/tx-test/signTesting.html) * Updates to the [existing sample dApp](https://purestake.github.io/algosigner-dapp-example/) demonstrating pending lookup and asset search ## Decentralized Applications @@ -57,7 +57,7 @@ DApp users can trust AlgoSigner to: - Try [Interactive dApp](https://purestake.github.io/algosigner-dapp-example/) ## Project Structure -There are multiple packages in the project that combine to build the overall extension. Each component package is designed so that it's functionality doesn't require the rebuild of other packages and will be combined to build the deployable extension. +There are multiple packages in the project that combine to build the overall extension. Each component package is designed so that its functionality doesn't require the rebuild of other packages and will be combined to build the deployable extension. *https://github.com/PureStake* * algosigner-> // Base project folder @@ -69,7 +69,7 @@ There are multiple packages in the project that combine to build the overall ext * extension-> // Extension definition and core files * storage -> // Handles saving and loading of account information * test-project -> // Test wrapper for the package files - * ui-> // Front end application for interaction within the extension interface \ + * ui-> // Front end application for interaction within the extension interface * manifest.json // Extension definition file * package.json // Algosigner package, required packages, and scripts to build the project * readme.md // Project overview @@ -83,26 +83,26 @@ The ./dist/ folder is the only required folder to install the extension yourself - Clone the repository locally - Run `npm install` in the root folder -- Run `npm run build` in the root folder - this creates the `dist` folder -- Open Chrome Browser - go to `chrome://extensions/` +- Run `npm run build` in the root folder — this creates the `dist` folder +- Open Chrome browser — go to `chrome://extensions/` - Enable developer mode - Select `Load Unpacked` and choose the just created `dist` folder - AlgoSigner is now installed and available ## Install from zip -The latest built zip is available for download on the releases page - +The latest built zip is available for download on the releases page — -Note - this is not recommended for non-developers and never for production purposes, extreme caution should be taken with installing any wallet. +NoteL this is not recommended for non-developers and should never be used for production purposes. Extreme caution should be taken when installing any wallet. ### Prerequisites -- Installation of the Chrome Browser +- Installation of the Chrome browser - File unzip program - Local file system write permissions - Access to set developer mode in Chrome and install unpacked extensions ### Process - Unzip `AlgoSigner.zip` file to local file system -- Open Chrome Browser and go to `chrome://extensions/` +- Open Chrome browser and go to `chrome://extensions/` - Enable developer mode - Select `Load Unpacked` and choose the unzipped `dist` folder - AlgoSigner is now installed and available From 8e7bcbe25968ed3ff47999c521c39439b836b902 Mon Sep 17 00:00:00 2001 From: Jan Marcano Date: Tue, 3 Nov 2020 18:07:01 -0300 Subject: [PATCH 05/12] Close Network Selector Dropdown on outside click --- packages/ui/src/components/LedgerSelect.ts | 1 + packages/ui/src/styles.scss | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/LedgerSelect.ts b/packages/ui/src/components/LedgerSelect.ts index 831b4339..b47f6bdf 100644 --- a/packages/ui/src/components/LedgerSelect.ts +++ b/packages/ui/src/components/LedgerSelect.ts @@ -50,6 +50,7 @@ const LedgerSelect: FunctionalComponent = (props: any) => {