Skip to content

Commit

Permalink
Merge pull request #638 from PolymathNetwork/release
Browse files Browse the repository at this point in the history
Release 2.1
  • Loading branch information
remon-nashid authored Aug 19, 2019
2 parents 6ef7240 + 1a17880 commit b56962e
Show file tree
Hide file tree
Showing 13 changed files with 868 additions and 196 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"editor.formatOnSave": true,
"prettier.eslintIntegration": true,
"search.exclude": {
"**/node_modules": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/polymath-issuer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"node": ">=8.9"
},
"scripts": {
"start:prod": "serve -s build",
"start": "node scripts/start.js",
"start:prod": "serve -s build",
"build": "node scripts/build.js",
"test": "node ./scripts/test.js --env=jsdom",
"typecheck": "flow --show-all-branches"
Expand Down
231 changes: 231 additions & 0 deletions packages/polymath-issuer/src/actions/compliance.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { formName as addInvestorFormName } from '../pages/compliance/components/
import { formName as editInvestorsFormName } from '../pages/compliance/components/EditInvestorsForm';
import { parseWhitelistCsv } from '../utils/parsers';
import { STAGE_OVERVIEW } from '../reducers/sto';
import { PERM_TYPES } from '../constants';
import Web3 from 'web3';

import type { Investor, Address } from '@polymathnetwork/js/types';
import type { GetState } from '../redux/reducer';
Expand All @@ -39,6 +41,31 @@ export const listLength = (listLength: number) => ({
listLength,
});

export const LOAD_MANAGERS = 'compliance/LOAD_MANAGERS';
export const loadManagers = managers => ({
type: LOAD_MANAGERS,
managers,
});

export const ADD_MANAGER = 'compliance/ADD_MANAGER';
export const addManager = manager => ({
type: ADD_MANAGER,
manager,
});

export const REMOVE_MANAGER = 'compliance/REMOVE_MANAGER';
export const removeManager = address => ({
type: REMOVE_MANAGER,
address,
});

export const TOGGLE_WHITELIST_MANAGEMENT =
'compliance/TOGGLE_WHITELIST_MANAGEMENT';
export const toggleWhitelistManagement = (isToggled: boolean) => ({
type: TOGGLE_WHITELIST_MANAGEMENT,
isToggled,
});

export const RESET_UPLOADED = 'compliance/RESET_UPLOADED';
export const resetUploaded = () => ({ type: RESET_UPLOADED });

Expand All @@ -59,6 +86,210 @@ export type InvestorCSVRow = [
string,
];

// make more functional and switch transfermanager to module
async function getDelegateDetails(permissionManager, transferManager) {
const delegates = await permissionManager.getAllDelegates(
transferManager.address,
PERM_TYPES.ADMIN
);
let delegateDetails = [];
for (const delegate of delegates) {
let details = await permissionManager.getDelegateDetails(delegate);
delegateDetails.push({ id: delegate, address: delegate, details });
}
return delegateDetails;
}

export const fetchManagers = () => async (
dispatch: Function,
getState: GetState
) => {
dispatch(ui.fetching());
// $FlowFixMe
try {
const st: SecurityToken = getState().token.token.contract;
const permissionManager = await st.getPermissionManager();
if (!permissionManager) {
return;
}
const moduleMetadata = await st.getModule(permissionManager.address);
if (permissionManager && !moduleMetadata.isArchived) {
const transferManager = await st.getTransferManager();
if (transferManager) {
const delegateDetails = await getDelegateDetails(
permissionManager,
transferManager
);
dispatch(loadManagers(delegateDetails));
}
dispatch(toggleWhitelistManagement(true));
} else {
dispatch(toggleWhitelistManagement(false));
}
dispatch(ui.fetched());
} catch (e) {
console.log(e);
}
};

export const addAddressToTransferManager = (
delegate: Address,
details: string
) => async (dispatch: Function, getState: GetState) => {
const st: SecurityToken = getState().token.token.contract;
const permissionManager = await st.getPermissionManager();
const titles = ['Adding New Whitelist Manager', 'Setting Permissions'];
const isDelegate = await permissionManager.checkDelegate(delegate);
if (isDelegate) {
titles.shift();
}
dispatch(
ui.tx(
titles,
async () => {
if (permissionManager) {
const transferManager = await st.getTransferManager();
if (transferManager) {
if (!isDelegate) {
await permissionManager.addDelegate(delegate, details);
}
await permissionManager.changePermission(
delegate,
transferManager.address,
PERM_TYPES.ADMIN,
true
);
}
}
},
'New Whistlist Manager Added',
() => {
dispatch(addManager({ address: delegate, details: details }));
},
undefined,
undefined,
undefined,
true
)
);
};

// TODO: Add confirm dialog box
export const removeAddressFromTransferManager = (delegate: Address) => async (
dispatch: Function,
getState: GetState
) => {
dispatch(
ui.confirm(
<div>
<p>
Once removed, the whitelist manager will no longer have permission to
update the whitelist. Consult your legal team before removing a wallet
from the list.
</p>
</div>,
async () => {
dispatch(
ui.tx(
['Removing Whitelist Manager'],
async () => {
const st: SecurityToken = getState().token.token.contract;
const permissionManager = await st.getPermissionManager();
if (permissionManager) {
const transferManager = await st.getTransferManager();
if (transferManager) {
await permissionManager.changePermission(
delegate,
transferManager.address,
PERM_TYPES.ADMIN,
false
);
}
}
},
'Whitelist Manager Removed',
() => {
dispatch(removeManager(delegate));
},
undefined,
undefined,
undefined,
true
)
);
},
`Remove the Whitelist Manager from the Whitelist Managers List?`,
undefined,
'pui-large-confirm-modal'
)
);
};

export const archiveGeneralPermissionModule = () => async (
dispatch: Function,
getState: GetState
) => {
const st: SecurityToken = getState().token.token.contract;
dispatch(
ui.tx(
['Disabling General Permissions Manager'],
async () => {
const permissionManager = await st.getPermissionManager();
await st.archiveModule(permissionManager.address);
},
'General Permissions Manager Disabled',
() => {
dispatch(toggleWhitelistManagement(false));
dispatch(loadManagers([]));
},
undefined,
undefined,
undefined,
true
)
);
};

export const addGeneralPermissionModule = () => async (
dispatch: Function,
getState: GetState
) => {
const st: SecurityToken = getState().token.token.contract;
const permissionManager = await st.getPermissionManager();
const transferManager = await st.getTransferManager();
let moduleMetadata = {};
let delegateDetails = [];

if (permissionManager)
moduleMetadata = await st.getModule(permissionManager.address);

dispatch(
ui.tx(
['Enabling General Permissions Manager for General Transfer Manager'],
async () => {
if (moduleMetadata.isArchived) {
await st.unarchiveModule(permissionManager.address);
delegateDetails = await getDelegateDetails(
permissionManager,
transferManager
);
} else {
await st.setPermissionManager();
}
},
'General Permissions Manager for General Transfer Manager Enabled',
() => {
dispatch(loadManagers(delegateDetails));
dispatch(toggleWhitelistManagement(true));
},
undefined,
undefined,
undefined,
true
)
);
};

export const fetchWhitelist = () => async (
dispatch: Function,
getState: GetState
Expand Down
4 changes: 4 additions & 0 deletions packages/polymath-issuer/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const EVENT_TYPES = {
TOKEN_PURCHASE: 'TokenPurchase',
};

export const PERM_TYPES = {
ADMIN: 'ADMIN',
};

export const MODULE_TYPES = {
PERMISSION: 1,
TRANSFER: 2,
Expand Down
Loading

0 comments on commit b56962e

Please sign in to comment.