Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further Bitshares operations support #207

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,23 @@ const createModal = async (arg, modalEvent) => {
let target = arg.target;
modalRequests[id]['target'] = target;

let isBlockedAccount = arg.isBlockedAccount;
if (isBlockedAccount) {
modalRequests[id]['warning'] = true;
targetURL += isBlockedAccount ? `&warning=blockedAccount` : `&warning=serverError`;
}

targetURL += `&chain=${encodeURIComponent(chain)}`;
targetURL += `&accountName=${encodeURIComponent(accountName)}`;
targetURL += `&target=${encodeURIComponent(target)}`;
targetURL += `&toSend=${encodeURIComponent(toSend)}`;
}

if ([Actions.INJECTED_CALL, Actions.TRANSFER].includes(type)) {
grctest marked this conversation as resolved.
Show resolved Hide resolved
if (arg.isBlockedAccount) {
modalRequests[id]['warning'] = true;
targetURL += `&warning=blockedAccount`;
} else if (arg.serverError) {
modalRequests[id]['warning'] = true;
targetURL += `&warning=serverError`;
}
}


modalWindows[id] = new BrowserWindow({
parent: mainWindow,
title: 'Beet prompt',
Expand Down
22 changes: 22 additions & 0 deletions src/components/popups/genericrequestpopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
return {}
}
},
warning: {
type: String,
required: false,
default() {
return ''
}
}
});

let acceptText = computed(() => {
Expand All @@ -45,6 +52,13 @@
return props.payload.generic.details.split(/\r?\n/);
});

let warning = computed(() => {
if (!props.warning || !props.warning.length) {
return;
}
return props.warning;
});

onMounted(() => {
logger.debug("Req Popup initialised");
});
Expand Down Expand Up @@ -86,6 +100,14 @@
</ui-item-text-content>
</ui-item>
</ui-list>

<ui-alert v-if="warning" state="warning">
{{
warning === "serverError"
? t("operations.transfer.server_error")
: t("operations.transfer.detected_scammer")
}}
</ui-alert>

<ui-button
raised
Expand Down
196 changes: 146 additions & 50 deletions src/lib/apiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,27 @@ export async function injectedCall(request, blockchain) {
return _promptFail("injectedCall", 'injectedCall', request, reject);
}

// extract account_ids from request.payload.params
let stringifiedPayload = JSON.stringify(request.payload.params);
let regex = /1.2.\d+/g
let regexMatches = stringifiedPayload.matchAll(regex);
let foundIDs = [];
for (const match of regexMatches) {foundIDs.push(match[0]);}

let isBlocked;
let blockedAccounts;
if (foundIDs.length) {
// Won't catch account names, only account IDs
try {
blockedAccounts = await blockchain.getBlockedAccounts();
} catch (error) {
console.log(error);
}

const isBadActor = (actor) => blockedAccounts.find(x => x === actor) ? true : false;
isBlocked = foundIDs.some(isBadActor);
}

let visualizedParams;
try {
visualizedParams = await blockchain.visualize(request.payload.params);
Expand All @@ -283,6 +304,25 @@ export async function injectedCall(request, blockchain) {
return _promptFail("injectedCall", request.id, request, reject);
}

if (!isBlocked && visualizedParams) {
// account names will have 1.2.x in parenthesis now - check again
if (!blockedAccounts) {
try {
blockedAccounts = await blockchain.getBlockedAccounts();
grctest marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
console.log(error);
}
}

let strVirtParams = JSON.stringify(visualizedParams);
let regexMatches = strVirtParams.matchAll(regex);

for (const match of regexMatches) {foundIDs.push(match[0]);}

const isBadActor = (actor) => blockedAccounts.find(x => x === actor) ? true : false;
isBlocked = foundIDs.some(isBadActor);
}

let visualizedAccount;
try {
visualizedAccount = await blockchain.visualize(request.payload.account_id);
Expand All @@ -291,17 +331,55 @@ export async function injectedCall(request, blockchain) {
return _promptFail("injectedCall", request.id, request, reject);
}

ipcRenderer.send(
'createPopup',
{
let popupContents = {
request: request,
visualizedAccount: visualizedAccount,
visualizedParams: visualizedParams
}
);
};

if (foundIDs.length) {
popupContents['isBlockedAccount'] = isBlocked;
}

if (!blockedAccounts || !blockedAccounts.length) {
popupContents['serverError'] = true,
}

ipcRenderer.send('createPopup', popupContent);

ipcRenderer.once(`popupApproved_${request.id}`, async (event, result) => {
return _signOrBroadcast(blockchain, request, resolve, reject);
let memoObject;
let reference = request;
if (request.payload.memo) {
let from;
let to;
if (request.payload.from) {
from = request.payload.from;
to = request.payload.to;
} else if (request.payload.withdraw_from_account) {
from = request.payload.withdraw_from_account;
to = request.payload.withdraw_to_account;
} else if (request.payload.issuer) {
from = request.payload.issuer;
to = request.payload.issue_to_account;
}

try {
memoObject = blockchain._createMemoObject(
from,
to,
request.payload.memo,
optionalNonce,
encryptMemo
);
} catch (error) {
console.log(error);
}

reference.payload.memo = memoObject;
}

return _signOrBroadcast(blockchain, reference, resolve, reject);
})

ipcRenderer.once(`popupRejected_${request.id}`, (event, result) => {
Expand Down Expand Up @@ -571,55 +649,30 @@ export async function transfer(request, blockchain) {
return _promptFail("transfer", request.id, 'No toSend', reject);
}

let targetID;
let targetAccount = request.payload.params.to;
if (!targetAccount.includes("1.2.")) {
let targetAccountContents;
try {
targetAccountContents = await this.getAccount(targetAccount);
} catch (error) {
console.log(error);
return reject();
}

targetID = targetAccountContents.id;
} else {
targetID = targetAccount;
}

let blockedAccounts;
try {
blockedAccounts = await blockchain.getBlockedAccounts(targetAccount);
blockedAccounts = await blockchain.getBlockedAccounts();
sschiessl-bcp marked this conversation as resolved.
Show resolved Hide resolved
} catch (error) {
console.log(error);
}

/*
if (!request.payload.params.amount && request.payload.params.satoshis) {
popupContents.request.payload.params.amount = request.payload.params.satoshis;
}

if (blockchain.supportsFeeCalculation() && request.chain === "BTC") {

let activeKey = store.getters['AccountStore/getActiveKey'](request);

let signingKey;
try {
signingKey = await getKey(activeKey);
} catch (error) {
return _promptFail("transfer.getKey", request.id, error, reject);
}

if (signingKey) {
let transferResult;
try {
transferResult = await blockchain.transfer(
signingKey, // Can we do this without the key?
accountDetails.accountName,
request.params.to,
{
amount: request.params.amount.satoshis || request.params.amount.amount,
asset_id: request.params.amount.asset_id
},
request.params.memo,
false // PREVENTS SENDING!
);
} catch (error) {
return _promptFail("transfer.falseTransfer", request.id, error, reject);
}

if (transferResult) {
popupContents['feeInSatoshis'] = transferResult.feeInSatoshis;
popupContents['toSendFee'] = blockchain.format(transferResult.feeInSatoshis);
}
}
}
*/
let isBlocked = blockedAccounts.find(x => x === targetID) ? true : false;

ipcRenderer.send(
'createPopup',
Expand All @@ -628,8 +681,9 @@ export async function transfer(request, blockchain) {
accountName: accountDetails.accountName,
request: request,
toSend: toSend,
target: blockedAccounts.id,
isBlockedAccount: blockedAccounts.blocked
target: targetID,
serverError: !blockedAccounts || !blockedAccounts.length ? true : false,
isBlockedAccount: isBlocked
}
);

Expand Down Expand Up @@ -687,6 +741,48 @@ export async function transfer(request, blockchain) {
ipcRenderer.once(`popupRejected_${request.id}`, (event, result) => {
return _promptFail("Transfer.reject", request.id, result, reject);
})

/*
if (!request.payload.params.amount && request.payload.params.satoshis) {
popupContents.request.payload.params.amount = request.payload.params.satoshis;
}

if (blockchain.supportsFeeCalculation() && request.chain === "BTC") {

let activeKey = store.getters['AccountStore/getActiveKey'](request);

let signingKey;
try {
signingKey = await getKey(activeKey);
} catch (error) {
return _promptFail("transfer.getKey", request.id, error, reject);
}

if (signingKey) {
let transferResult;
try {
transferResult = await blockchain.transfer(
signingKey, // Can we do this without the key?
accountDetails.accountName,
request.params.to,
{
amount: request.params.amount.satoshis || request.params.amount.amount,
asset_id: request.params.amount.asset_id
},
request.params.memo,
false // PREVENTS SENDING!
);
} catch (error) {
return _promptFail("transfer.falseTransfer", request.id, error, reject);
}

if (transferResult) {
popupContents['feeInSatoshis'] = transferResult.feeInSatoshis;
popupContents['toSendFee'] = blockchain.format(transferResult.feeInSatoshis);
}
}
}
*/
});
}

Expand Down
Loading