Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #428 from PureStake/jan/governance-warning
Browse files Browse the repository at this point in the history
Show Warning when sending funds directly to a Governance accounts
  • Loading branch information
PureBrent authored Aug 8, 2022
2 parents 46419d1 + c0f8518 commit b7e7285
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/common/src/messaging/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export enum JsonRpcMethod {
GetAliasedAddresses = 'get-aliased-addresses',
GetNamespaceConfigs = 'get-namespace-configs',
ToggleNamespaceConfig = 'toggle-namespace-config',
GetGovernanceAddresses = 'get-governance-addresses',

// Ledger Device Methods
LedgerSaveAccount = 'ledger-save-account',
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ they are rekeyed to another normal account also on AlgoSigner.`;
export const ALIAS_COLLISION_TOOLTIP: string = `Some of the aliases shown share the same name,
make sure to verify which Namespace you're using
by hovering on the alias before making a selection.`;

export const GOVERNANCE_WARNING: string =
'This is a Governance Address. You are not required to send funds in order to participate in Governance. Please see ';
23 changes: 22 additions & 1 deletion packages/extension/src/background/messaging/internalMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import algosdk from 'algosdk';
import { JsonRpcMethod } from '@algosigner/common/messaging/types';
import { logging } from '@algosigner/common/logging';
import { logging, LogLevel } from '@algosigner/common/logging';
import { ExtensionStorage } from '@algosigner/storage/src/extensionStorage';
import { Alias, Ledger, Namespace, NamespaceConfig } from '@algosigner/common/types';
import { RequestError } from '@algosigner/common/errors';
Expand Down Expand Up @@ -1291,4 +1291,25 @@ export class InternalMethods {
});
return true;
}

public static [JsonRpcMethod.GetGovernanceAddresses](request: any, sendResponse: Function) {
const governanceAccounts: Array<string> = [];
fetch('https://governance.algorand.foundation/api/periods/').then(async (fetchResponse) => {
if (fetchResponse.ok) {
const governanceResponse = await fetchResponse.json();
if ('results' in governanceResponse) {
try {
governanceResponse['results'].forEach((p) => governanceAccounts.push(p['sign_up_address']));
} catch (e) {
logging.log("Governance accounts couldn't be fetched. Error: "+e.message, LogLevel.Debug);
}
}
}

if (governanceAccounts.length) {
sendResponse({accounts: governanceAccounts});
}
});
return true;
}
}
3 changes: 3 additions & 0 deletions packages/extension/src/background/messaging/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,9 @@ export class Task {
[JsonRpcMethod.ToggleNamespaceConfig]: (request: any, sendResponse: Function) => {
return InternalMethods[JsonRpcMethod.ToggleNamespaceConfig](request, sendResponse);
},
[JsonRpcMethod.GetGovernanceAddresses]: (request: any, sendResponse: Function) => {
return InternalMethods[JsonRpcMethod.GetGovernanceAddresses](request, sendResponse);
},
},
};
}
Expand Down
28 changes: 26 additions & 2 deletions packages/ui/src/pages/SendAlgos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Key } from 'ts-key-enum';
import { JsonRpcMethod } from '@algosigner/common/messaging/types';
import { AliasConfig } from '@algosigner/common/config';
import { obfuscateAddress } from '@algosigner/common/utils';
import { ALIAS_COLLISION_TOOLTIP } from '@algosigner/common/strings';
import { ALIAS_COLLISION_TOOLTIP, GOVERNANCE_WARNING } from '@algosigner/common/strings';

import { StoreContext } from 'services/StoreContext';
import { sendMessage } from 'services/Messaging';
Expand Down Expand Up @@ -44,6 +44,7 @@ const SendAlgos: FunctionalComponent = (props: any) => {
const [internalAliases, setInternalAliases] = useState<any>([]);
const [highlightedAlias, setHighlightedAlias] = useState<number>(0);
const [selectedDestination, setSelectedDestination] = useState<any>(null);
const [governanceAddresses, setGovernanceAddresses] = useState<Array<string>>([]);
const [addingContact, setAddingContact] = useState<boolean>(false);
const [newContactName, setNewContactName] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);
Expand All @@ -70,6 +71,16 @@ const SendAlgos: FunctionalComponent = (props: any) => {
setInternalAliases(Object.keys(response).flatMap((n) => response[n]));
}
}
// Fetch governance accounts
sendMessage(JsonRpcMethod.GetGovernanceAddresses, {}, (response) => {
if (response) {
if ('error' in response) {
setError(response.error.message);
} else {
setGovernanceAddresses(response['accounts']);
}
}
});
});
}, []);
// Automatically focus textbox on load
Expand Down Expand Up @@ -287,7 +298,13 @@ const SendAlgos: FunctionalComponent = (props: any) => {
let ddClass: string = 'dropdown is-right';
if (ddActive) ddClass += ' is-active';
const youIndicator = html`<b class="has-text-link">YOU</b>`;
const disabled = (!selectedDestination && !algosdk.isValidAddress(to)) || +amount < 0;
const isGovernance =
(to && governanceAddresses.includes(to)) ||
(selectedDestination &&
selectedDestination.address &&
governanceAddresses.includes(selectedDestination.address));
const disabled =
(!selectedDestination && !algosdk.isValidAddress(to)) || +amount < 0 || isGovernance;
const isActive = (index: number) => (index === highlightedAlias ? 'is-active' : '');

// Render HTML
Expand Down Expand Up @@ -472,6 +489,13 @@ const SendAlgos: FunctionalComponent = (props: any) => {
onInput=${(e) => setNote(e.target.value)}
/>
</div>
${isGovernance &&
html`<span class="px-4 has-text-centered has-text-danger is-size-7">
${GOVERNANCE_WARNING}
<a class="is-underlined" href="https://governance.algorand.foundation/" target="_blank">
official site</a
>.
</span>`}
<div class="px-4 py-4">
<button
id="submitTransfer"
Expand Down

0 comments on commit b7e7285

Please sign in to comment.