mirror of
https://github.com/Qortal/chrome-extension.git
synced 2025-03-31 09:45:53 +00:00
get ltc balance
This commit is contained in:
parent
f6c0afbc40
commit
0399c9d147
@ -121,6 +121,35 @@ document.addEventListener('qortalExtensionRequests', async (event) => {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else if(type === 'REQUEST_LTC_BALANCE'){
|
||||||
|
|
||||||
|
|
||||||
|
const hostname = window.location.hostname
|
||||||
|
const res = await connection(hostname)
|
||||||
|
if(!res){
|
||||||
|
document.dispatchEvent(new CustomEvent('qortalExtensionResponses', {
|
||||||
|
detail: { type: "USER_INFO", data: {
|
||||||
|
error: "Not authorized"
|
||||||
|
}, requestId }
|
||||||
|
}));
|
||||||
|
return
|
||||||
|
}
|
||||||
|
chrome.runtime.sendMessage({ action: "ltcBalance", payload: {
|
||||||
|
hostname
|
||||||
|
}, timeout }, (response) => {
|
||||||
|
if (response.error) {
|
||||||
|
document.dispatchEvent(new CustomEvent('qortalExtensionResponses', {
|
||||||
|
detail: { type: "LTC_BALANCE", data: {
|
||||||
|
error: response.error
|
||||||
|
}, requestId }
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
// Include the requestId in the detail when dispatching the response
|
||||||
|
document.dispatchEvent(new CustomEvent('qortalExtensionResponses', {
|
||||||
|
detail: { type: "LTC_BALANCE", data: response, requestId }
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
} else if (type === 'REQUEST_AUTHENTICATION') {
|
} else if (type === 'REQUEST_AUTHENTICATION') {
|
||||||
const hostname = window.location.hostname
|
const hostname = window.location.hostname
|
||||||
const res = await connection(hostname)
|
const res = await connection(hostname)
|
||||||
|
26
src/App.tsx
26
src/App.tsx
@ -56,6 +56,7 @@ type extStates =
|
|||||||
| "transfer-success-request"
|
| "transfer-success-request"
|
||||||
| "wallet-dropped"
|
| "wallet-dropped"
|
||||||
| "web-app-request-buy-order"
|
| "web-app-request-buy-order"
|
||||||
|
| "buy-order-submitted"
|
||||||
;
|
;
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
@ -366,7 +367,7 @@ function App() {
|
|||||||
},
|
},
|
||||||
(response) => {
|
(response) => {
|
||||||
if (response === true) {
|
if (response === true) {
|
||||||
setExtstate("transfer-success-request");
|
setExtstate("buy-order-submitted");
|
||||||
setCountdown(null);
|
setCountdown(null);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -1433,6 +1434,29 @@ function App() {
|
|||||||
</CustomButton>
|
</CustomButton>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{extState === "buy-order-submitted" && (
|
||||||
|
<>
|
||||||
|
<Spacer height="48px" />
|
||||||
|
<img src={Success} />
|
||||||
|
<Spacer height="45px" />
|
||||||
|
<TextP
|
||||||
|
sx={{
|
||||||
|
textAlign: "center",
|
||||||
|
lineHeight: "15px",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Your buy order was submitted
|
||||||
|
</TextP>
|
||||||
|
<Spacer height="100px" />
|
||||||
|
<CustomButton
|
||||||
|
onClick={() => {
|
||||||
|
window.close();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Close
|
||||||
|
</CustomButton>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
{countdown && (
|
{countdown && (
|
||||||
<Box
|
<Box
|
||||||
style={{
|
style={{
|
||||||
|
@ -129,6 +129,27 @@ async function getBalanceInfo() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
async function getLTCBalance() {
|
||||||
|
const wallet = await getSaveWallet();
|
||||||
|
let _url = `${buyTradeNodeBaseUrl}/crosschain/ltc/walletbalance`;
|
||||||
|
const keyPair = await getKeyPair()
|
||||||
|
const parsedKeyPair = JSON.parse(keyPair)
|
||||||
|
let _body = parsedKeyPair.ltcPublicKey
|
||||||
|
const response = await fetch(_url, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: _body
|
||||||
|
});
|
||||||
|
if(response?.ok){
|
||||||
|
const data = await response.text();
|
||||||
|
const dataLTCBalance = (Number(data) / 1e8).toFixed(8);
|
||||||
|
return +dataLTCBalance
|
||||||
|
|
||||||
|
} else throw new Error('Onable to get LTC balance')
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const processTransactionVersion2Chat = async (body: any, validApi: string) => {
|
const processTransactionVersion2Chat = async (body: any, validApi: string) => {
|
||||||
// const validApi = await findUsableApi();
|
// const validApi = await findUsableApi();
|
||||||
@ -261,10 +282,13 @@ async function decryptWallet({ password, wallet, walletVersion }) {
|
|||||||
const wallet2 = new PhraseWallet(response, walletVersion);
|
const wallet2 = new PhraseWallet(response, walletVersion);
|
||||||
const keyPair = wallet2._addresses[0].keyPair;
|
const keyPair = wallet2._addresses[0].keyPair;
|
||||||
const ltcPrivateKey = wallet2._addresses[0].ltcWallet.derivedMasterPrivateKey
|
const ltcPrivateKey = wallet2._addresses[0].ltcWallet.derivedMasterPrivateKey
|
||||||
|
const ltcPublicKey = wallet2._addresses[0].ltcWallet.derivedMasterPublicKey
|
||||||
|
|
||||||
const toSave = {
|
const toSave = {
|
||||||
privateKey: Base58.encode(keyPair.privateKey),
|
privateKey: Base58.encode(keyPair.privateKey),
|
||||||
publicKey: Base58.encode(keyPair.publicKey),
|
publicKey: Base58.encode(keyPair.publicKey),
|
||||||
ltcPrivateKey: ltcPrivateKey
|
ltcPrivateKey: ltcPrivateKey,
|
||||||
|
ltcPublicKey : ltcPublicKey
|
||||||
}
|
}
|
||||||
const dataString = JSON.stringify(toSave)
|
const dataString = JSON.stringify(toSave)
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
@ -442,7 +466,9 @@ async function createBuyOrderTx({ crosschainAtInfo }) {
|
|||||||
signature: res?.signature,
|
signature: res?.signature,
|
||||||
|
|
||||||
})
|
})
|
||||||
return { atAddress: crosschainAtInfo.qortalAtAddress, chatSignature: res?.signature, node: buyTradeNodeBaseUrl }
|
return { atAddress: crosschainAtInfo.qortalAtAddress, chatSignature: res?.signature, node: buyTradeNodeBaseUrl, qortAddress: address }
|
||||||
|
} else {
|
||||||
|
throw new Error("Unable to send buy order message")
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -522,12 +548,17 @@ function fetchMessages(apiCall) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchMessagesForBuyOrders(apiCall, signature, senderPublicKey) {
|
async function fetchMessagesForBuyOrders(apiCall, signature, senderPublicKey) {
|
||||||
let retryDelay = 2000; // Start with a 2-second delay
|
let retryDelay = 2000; // Start with a 2-second delay
|
||||||
const maxDuration = 360000 * 2; // Maximum duration set to 12 minutes
|
const maxDuration = 360000 * 2; // Maximum duration set to 12 minutes
|
||||||
const startTime = Date.now(); // Record the start time
|
const startTime = Date.now(); // Record the start time
|
||||||
let triedChatMessage = []
|
let triedChatMessage = []
|
||||||
// Promise to handle polling logic
|
// Promise to handle polling logic
|
||||||
|
await new Promise((res)=> {
|
||||||
|
setTimeout(() => {
|
||||||
|
res()
|
||||||
|
}, 40000);
|
||||||
|
})
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const attemptFetch = async () => {
|
const attemptFetch = async () => {
|
||||||
if (Date.now() - startTime > maxDuration) {
|
if (Date.now() - startTime > maxDuration) {
|
||||||
@ -734,6 +765,18 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case "ltcBalance": {
|
||||||
|
getLTCBalance()
|
||||||
|
.then((balance) => {
|
||||||
|
sendResponse(balance);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "sendCoin":
|
case "sendCoin":
|
||||||
{
|
{
|
||||||
const { receiver, password, amount } = request.payload;
|
const { receiver, password, amount } = request.payload;
|
||||||
@ -1184,7 +1227,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error(error.message);
|
console.error(error.message);
|
||||||
sendResponse({ error: error.message });
|
sendResponse({ error: error.message });
|
||||||
originalSendResponse({ error: error.message });
|
// originalSendResponse({ error: error.message });
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user