Skip to content

Commit

Permalink
Fix mining config generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Swepool committed Nov 22, 2023
1 parent 3ba97ba commit 261d64e
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/routes/mining/components/Config/generate.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
export const generateConfig = (address) => {
// fetches the array of pools
fetch("https://raw.githubusercontent.com/Swepool/kryptokrona-pools/main/pools.json")
.then(res => res.json())
.then(data => {
//if there's something we generate a file, this could be improved.. for example check the address.
if (address) {
downloadObjectAsJson(generateFile(randomPool(data.pools), address), "config")
} else {
//if empty send alert
alert("Fill in wallet address to generate config.json")
}
})
export const generateConfig = (address: string): void => {

const pools: string[] = [
'swepool.org:3333',
'techy.ddns.net:3333',
'fastpool.xyz:10092'
]

if (address) {
const pool = randomPool(pools)
const config = generateFile(pool, address)
downloadObjectAsJson(config, 'config')
} else {
alert("Fill in wallet address to generate config.json")
}
}

function randomPool(array) {
function randomPool(array: string[]): string {
const random = Math.floor(Math.random() * array.length)
return array[random]
}

function downloadObjectAsJson(exportObj, exportName) {
function downloadObjectAsJson(exportObj: any, exportName: string): void {
const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
const downloadAnchorNode = document.createElement('a');
downloadAnchorNode.setAttribute("href", dataStr);
Expand All @@ -28,7 +30,7 @@ function downloadObjectAsJson(exportObj, exportName) {
downloadAnchorNode.remove();
}

function generateFile(pool, user) {
function generateFile(pool: string, user: string): any {
return JSON.parse(
`{
"api": {"id": null, "worker-id": null},
Expand Down

1 comment on commit 261d64e

@vercel
Copy link

@vercel vercel bot commented on 261d64e Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.