mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-02-11 17:55:49 +00:00
added qortalRequess
This commit is contained in:
parent
5d7dac10bb
commit
24714fb0a6
@ -2416,7 +2416,7 @@ async function cancelBan({ groupId, qortalAddress }) {
|
||||
throw new Error("Transaction was not able to be processed");
|
||||
return res;
|
||||
}
|
||||
async function registerName({ name }) {
|
||||
export async function registerName({ name, description = "" }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
const parsedData = JSON.parse(resKeyPair);
|
||||
@ -2431,7 +2431,7 @@ async function registerName({ name }) {
|
||||
const tx = await createTransaction(3, keyPair, {
|
||||
fee: feeres.fee,
|
||||
name,
|
||||
value: "",
|
||||
value: description || "",
|
||||
lastReference: lastReference,
|
||||
});
|
||||
|
||||
@ -2442,6 +2442,35 @@ async function registerName({ name }) {
|
||||
throw new Error(res?.message || "Transaction was not able to be processed");
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function updateName({ newName, oldName, description }) {
|
||||
const lastReference = await getLastRef();
|
||||
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 feeres = await getFee("UPDATE_NAME");
|
||||
|
||||
const tx = await createTransaction(4, keyPair, {
|
||||
fee: feeres.fee,
|
||||
name: oldName,
|
||||
newName,
|
||||
newData: description || "",
|
||||
lastReference: lastReference,
|
||||
});
|
||||
|
||||
const signedBytes = Base58.encode(tx.signedBytes);
|
||||
|
||||
const res = await processTransactionVersion2(signedBytes);
|
||||
if (!res?.signature)
|
||||
throw new Error(res?.message || "Transaction was not able to be processed");
|
||||
return res;
|
||||
}
|
||||
|
||||
async function makeAdmin({ groupId, qortalAddress }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { gateways, getApiKeyFromStorage } from "./background";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
|
||||
|
||||
const listOfAllQortalRequests = [
|
||||
'GET_USER_ACCOUNT', 'DECRYPT_DATA', 'SEND_COIN', 'GET_LIST_ITEMS',
|
||||
@ -622,6 +622,31 @@ chrome?.runtime?.onMessage.addListener((request, sender, sendResponse) => {
|
||||
sendResponse(listOfAllQortalRequests)
|
||||
break;
|
||||
}
|
||||
|
||||
case "REGISTER_NAME" : {
|
||||
const data = request.payload;
|
||||
|
||||
registerNameRequest(data, isFromExtension)
|
||||
.then((res) => {
|
||||
sendResponse(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({ error: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "UPDATE_NAME" : {
|
||||
const data = request.payload;
|
||||
|
||||
updateNameRequest(data, isFromExtension)
|
||||
.then((res) => {
|
||||
sendResponse(res);
|
||||
})
|
||||
.catch((error) => {
|
||||
sendResponse({ error: error.message });
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -16,7 +16,9 @@ import {
|
||||
createBuyOrderTxQortalRequest,
|
||||
groupSecretkeys,
|
||||
getBaseApi,
|
||||
getArbitraryEndpoint
|
||||
getArbitraryEndpoint,
|
||||
updateName,
|
||||
registerName
|
||||
} from "../background";
|
||||
import { decryptGroupEncryption, getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||
import { QORT_DECIMALS } from "../constants/constants";
|
||||
@ -3830,4 +3832,61 @@ export const deleteHostedData = async (data, isFromExtension) => {
|
||||
throw new Error("User declined delete hosted resources");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export const registerNameRequest = async (data, isFromExtension) => {
|
||||
const requiredFields = ["name"];
|
||||
const missingFields: string[] = [];
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to register this name?`,
|
||||
highlightedText: data.name,
|
||||
text2: data?.description
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
const name = data.name
|
||||
const description = data?.description
|
||||
const response = await registerName({ name, description });
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
||||
|
||||
export const updateNameRequest = async (data, isFromExtension) => {
|
||||
const requiredFields = ["newName", "oldName"];
|
||||
const missingFields: string[] = [];
|
||||
requiredFields.forEach((field) => {
|
||||
if (!data[field]) {
|
||||
missingFields.push(field);
|
||||
}
|
||||
});
|
||||
const oldName = data.oldName
|
||||
const newName = data.newName
|
||||
const description = data?.description
|
||||
const resPermission = await getUserPermission(
|
||||
{
|
||||
text1: `Do you give this application permission to register this name?`,
|
||||
highlightedText: data.newName,
|
||||
text2: data?.description
|
||||
},
|
||||
isFromExtension
|
||||
);
|
||||
const { accepted } = resPermission;
|
||||
if (accepted) {
|
||||
const response = await updateName({ oldName, newName, description });
|
||||
return response
|
||||
|
||||
} else {
|
||||
throw new Error("User declined request");
|
||||
}
|
||||
};
|
51
src/transactions/UpdateNameTransaction.ts
Normal file
51
src/transactions/UpdateNameTransaction.ts
Normal file
@ -0,0 +1,51 @@
|
||||
// @ts-nocheck
|
||||
|
||||
import { QORT_DECIMALS } from "../constants/constants"
|
||||
import TransactionBase from "./TransactionBase"
|
||||
|
||||
|
||||
export default class UpdateNameTransaction extends TransactionBase {
|
||||
constructor() {
|
||||
super()
|
||||
this.type = 4
|
||||
}
|
||||
|
||||
|
||||
|
||||
set fee(fee) {
|
||||
this._fee = fee * QORT_DECIMALS
|
||||
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
||||
}
|
||||
|
||||
set name(name) {
|
||||
this.nameText = name
|
||||
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name)
|
||||
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length)
|
||||
}
|
||||
|
||||
set newName(newName) {
|
||||
this.newNameText = newName
|
||||
this._newNameBytes = this.constructor.utils.stringtoUTF8Array(newName)
|
||||
this._newNameLength = this.constructor.utils.int32ToBytes(this._newNameBytes.length)
|
||||
}
|
||||
|
||||
set newData(newData) {
|
||||
this.newDataText = newData.length === 0 ? "Registered Name on the Qortal Chain" : newData
|
||||
this._newDataBytes = this.constructor.utils.stringtoUTF8Array(this.newDataText)
|
||||
this._newDataLength = this.constructor.utils.int32ToBytes(this._newDataBytes.length)
|
||||
}
|
||||
|
||||
get params() {
|
||||
const params = super.params
|
||||
params.push(
|
||||
this._nameLength,
|
||||
this._nameBytes,
|
||||
this._newNameLength,
|
||||
this._newNameBytes,
|
||||
this._newDataLength,
|
||||
this._newDataBytes,
|
||||
this._feeBytes
|
||||
)
|
||||
return params
|
||||
}
|
||||
}
|
@ -19,9 +19,11 @@ import CreatePollTransaction from './CreatePollTransaction.js'
|
||||
import DeployAtTransaction from './DeployAtTransaction.js'
|
||||
import RewardShareTransaction from './RewardShareTransaction.js'
|
||||
import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js'
|
||||
import UpdateNameTransaction from './UpdateNameTransaction.js'
|
||||
|
||||
export const transactionTypes = {
|
||||
3: RegisterNameTransaction,
|
||||
4: UpdateNameTransaction,
|
||||
2: PaymentTransaction,
|
||||
8: CreatePollTransaction,
|
||||
9: VoteOnPollTransaction,
|
||||
|
Loading…
x
Reference in New Issue
Block a user