Skip to content

Commit cad4562

Browse files
committed
CLI update
1 parent bb3cdef commit cad4562

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

CLI/commands/transfer_manager.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -829,38 +829,50 @@ async function getApprovalsArray() {
829829
if (address == gbl.constants.ADDRESS_ZERO) {
830830
return await getApprovals();
831831
} else {
832-
let approvalsIndex = await getApprovalsToAnAddress(address);
833-
if (!approvalsIndex.length) {
832+
let approvals = await getApprovalsToAnAddress(address);
833+
if (!approvals.length) {
834834
console.log(chalk.red(`\nThe address is not listed\n`))
835835
}
836-
return await processApprovalsArray(approvalsIndex)
836+
return approvals;
837837
}
838838
}
839839

840-
async function processApprovalsArray(array) {
841-
let result = []
842-
for (const item of array) {
843-
let ap = await currentTransferManager.methods.approvals(item).call();
844-
result.push(ap)
845-
};
846-
return result
847-
}
848-
849840
function printMatmRow(from, to, allowance, time, description) {
850841
console.log(`\nDescription: ${web3.utils.toAscii(description)}\nFrom ${from} to ${to}\nAllowance: ${web3.utils.fromWei(allowance)}\nExpiry time: ${moment.unix(time).format('MMMM Do YYYY HH:mm')}\n`);
851842
}
852843

853844
async function getApprovals() {
854-
let totalApprovals = await currentTransferManager.methods.getTotalApprovalsLength().call();
845+
function ApprovalDetail(_from, _to, _allowance, _expiryTime, _description) {
846+
this.from = _from;
847+
this.to = _to;
848+
this.allowance = _allowance;
849+
this.expiryTime = _expiryTime;
850+
this.description = _description;
851+
}
852+
855853
let results = [];
856-
for (let i = 0; i < totalApprovals; i++) {
857-
results.push(await currentTransferManager.methods.approvals(i).call());
854+
let approvalDetails = await currentTransferManager.methods.getAllApprovals().call();
855+
for (let i = 0; i < approvalDetails[0].length; i++) {
856+
results.push(new ApprovalDetail(approvalDetails[0][i], approvalDetails[1][i], approvalDetails[2][i], approvalDetails[3][i], approvalDetails[4][i]));
858857
}
859858
return results;
860859
}
861860

862861
async function getApprovalsToAnAddress(address) {
863-
return await currentTransferManager.methods.getActiveApprovalsToUser(address).call();
862+
function ApprovalDetail(_from, _to, _allowance, _expiryTime, _description) {
863+
this.from = _from;
864+
this.to = _to;
865+
this.allowance = _allowance;
866+
this.expiryTime = _expiryTime;
867+
this.description = _description;
868+
}
869+
870+
let results = [];
871+
let approvals = await currentTransferManager.methods.getActiveApprovalsToUser(address).call();
872+
for (let i = 0; i < approvals[0].length; i++) {
873+
results.push(new ApprovalDetail(approvals[0][i], approvals[1][i], approvals[2][i], approvals[3][i], approvals[4][i]));
874+
}
875+
return results;
864876
}
865877

866878
async function getManualApproval(_from, _to) {

0 commit comments

Comments
 (0)