mirror of
https://github.com/Qortal/qortal-mobile.git
synced 2025-03-14 11:52:33 +00:00
added qortalRequest
This commit is contained in:
parent
6b437aa1b4
commit
4031e13d65
@ -1983,7 +1983,7 @@ export async function cancelBan({ groupId, qortalAddress }) {
|
||||
throw new Error("Transaction was not able to be processed");
|
||||
return res;
|
||||
}
|
||||
export async function registerName({ name }) {
|
||||
export async function registerName({ name, description = "" }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
const parsedData = resKeyPair;
|
||||
@ -1998,7 +1998,7 @@ export async function registerName({ name }) {
|
||||
const tx = await createTransaction(3, keyPair, {
|
||||
fee: feeres.fee,
|
||||
name,
|
||||
value: "",
|
||||
value: description || "",
|
||||
lastReference: lastReference,
|
||||
});
|
||||
|
||||
@ -2009,6 +2009,35 @@ export 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;
|
||||
}
|
||||
|
||||
export async function makeAdmin({ groupId, qortalAddress }) {
|
||||
const lastReference = await getLastRef();
|
||||
const resKeyPair = await getKeyPair();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { gateways, getApiKeyFromStorage } from "./background";
|
||||
import { listOfAllQortalRequests } from "./components/Apps/useQortalMessageListener";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createPoll, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, openNewTab, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
|
||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createPoll, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, openNewTab, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
|
||||
import { getData, storeData } from "./utils/chromeStorage";
|
||||
|
||||
|
||||
@ -870,6 +870,44 @@ export const isRunningGateway = async ()=> {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "REGISTER_NAME" : {
|
||||
try {
|
||||
const res = await registerNameRequest(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;
|
||||
}
|
||||
case "UPDATE_NAME" : {
|
||||
try {
|
||||
const res = await updateNameRequest(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;
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ import {
|
||||
isUsingLocal,
|
||||
createBuyOrderTx,
|
||||
performPowTask,
|
||||
groupSecretkeys
|
||||
groupSecretkeys,
|
||||
updateName,
|
||||
registerName
|
||||
} from "../background";
|
||||
import { getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
|
||||
@ -3775,4 +3777,62 @@ 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