add qr for sign_fee

This commit is contained in:
PhilReact 2025-05-01 12:05:07 +03:00
parent 09c5625a07
commit 170e99b4d0
3 changed files with 94 additions and 0 deletions

View File

@ -253,6 +253,7 @@ export const listOfAllQortalRequests = [
'SELL_NAME',
'CANCEL_SELL_NAME',
'BUY_NAME',
'SIGN_FOREIGN_FEES',
];
export const UIQortalRequests = [
@ -313,6 +314,7 @@ export const UIQortalRequests = [
'SELL_NAME',
'CANCEL_SELL_NAME',
'BUY_NAME',
'SIGN_FOREIGN_FEES',
];
async function retrieveFileFromIndexedDB(fileId) {

View File

@ -61,6 +61,7 @@ import {
buyNameRequest,
sellNameRequest,
cancelSellNameRequest,
signForeignFees,
} from './qortalRequests/get';
import { getData, storeData } from './utils/chromeStorage';
import { executeEvent } from './utils/events';
@ -1833,6 +1834,32 @@ function setupMessageListenerQortalRequest() {
}
break;
}
case 'SIGN_FOREIGN_FEES': {
try {
const res = await signForeignFees(request.payload, isFromExtension);
event.source.postMessage(
{
requestId: request.requestId,
action: request.action,
payload: res,
type: 'backgroundMessageResponse',
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: request.action,
error: error.message,
type: 'backgroundMessageResponse',
},
event.origin
);
}
break;
}
default:
break;
}

View File

@ -4923,3 +4923,68 @@ export const buyNameRequest = async (data, isFromExtension) => {
throw new Error('User declined request');
}
};
export const signForeignFees = async (data, isFromExtension) => {
const resPermission = await getUserPermission(
{
text1: `Do you give this application permission to sign the required fees for all your trade offers?`,
},
isFromExtension
);
const { accepted } = resPermission;
if (accepted) {
const wallet = await getSaveWallet();
const address = wallet.address0;
const resKeyPair = await getKeyPair();
const parsedData = resKeyPair;
const uint8PrivateKey = Base58.decode(parsedData.privateKey);
const uint8PublicKey = Base58.decode(parsedData.publicKey);
const keyPair = {
privateKey: uint8PrivateKey,
publicKey: uint8PublicKey,
};
const unsignedFeesUrl = await createEndpoint(
`/crosschain/unsignedfees/${address}`
);
const unsignedFeesResponse = await fetch(unsignedFeesUrl);
const unsignedFees = await unsignedFeesResponse.json();
const signedFees = [];
unsignedFees.forEach((unsignedFee) => {
const unsignedDataDecoded = Base58.decode(unsignedFee.data);
const signature = nacl.sign.detached(
unsignedDataDecoded,
keyPair.privateKey
);
const signedFee = {
timestamp: unsignedFee.timestamp,
data: `${Base58.encode(signature)}`,
atAddress: unsignedFee.atAddress,
fee: unsignedFee.fee,
};
signedFees.push(signedFee);
});
const signedFeesUrl = await createEndpoint(`/crosschain/signedfees`);
await fetch(signedFeesUrl, {
method: 'POST',
headers: {
Accept: '*/*',
'Content-Type': 'application/json',
},
body: `${JSON.stringify(signedFees)}`,
});
return true;
} else {
throw new Error('User declined request');
}
};