Skip to content

Commit

Permalink
Merge pull request #26 from phantasma-io/dev
Browse files Browse the repository at this point in the history
Merging Dev into master
  • Loading branch information
TeknoPT authored Jan 9, 2024
2 parents cf6181d + fadd569 commit 7f4f677
Show file tree
Hide file tree
Showing 21 changed files with 534 additions and 119 deletions.
Binary file added bun.lockb
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phantasma-hub",
"version": "1.0.6",
"version": "1.0.10",
"private": true,
"scripts": {
"dev": "npm run version:update && vite dev --cors true",
Expand All @@ -11,7 +11,8 @@
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write .",
"prod": "npm run version:update && vite dev --host --port 4000"
"prod": "npm run version:update && vite dev --host --port 4000",
"bun": "bun build"
},
"devDependencies": {
"@iconify/svelte": "3.0.1",
Expand Down
59 changes: 58 additions & 1 deletion src/lib/Commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import type { PhantasmaLink } from 'phantasma-ts';
import { Base16, PBinaryReader, VMObject } from 'phantasma-ts/src';
import {
NotificationError,
NotificationSuccess
NotificationSuccess,
NotificationWarning
} from '$lib/Components/Notification/NotificationsBuilder';
import { ethers } from 'ethers';

Expand Down Expand Up @@ -343,3 +344,59 @@ export async function CheckURLStatus(url: string): Promise<boolean> {
return false;
}
}

/**
* Get the Wallet Nexus
*/
export async function GetWalletNexus(connectedNexus: string) {
await Link.getNexus(
(result) => {
console.log({ result });
if (result.nexus != connectedNexus) {
NotificationWarning(
`Wallet connected to ${result.nexus}!`,
`Wallet is connected to <b>${result.nexus}</b> and the Phantasma Hub is using the <b>${connectedNexus} API</b>.`,
6000
);
} else {
NotificationSuccess(
`Wallet connected to ${result.nexus}!`,
`Phantasma Hub and the wallet are using the <b>${result.nexus} API</b>.`
);
}
},
(error) => {
console.log(error);
}
);
}

export async function GetWalletPeer(connectedPeer: string) {
await Link.getPeer(
(result) => {
console.log('peer:', { result });
if (result.peer != connectedPeer) {
NotificationWarning(
`Wallet connected to ${result.peer}!`,
`Wallet is connected to Peer <b>${result.peer}</b> and the Phantasma Hub is using the <b>${connectedPeer} API</b>.`,
6000
);
} else {
NotificationSuccess(
`Wallet connected to ${result.peer}!`,
`Phantasma Hub and the wallet are using the <b>${result.peer} API</b>.`
);
}
},
(error) => {
NotificationError('Wallet Error!', 'Please connect your wallet first.');
console.log(error);
}
);
}

export function GetNexusPhantasmaLink(connectedNexus: string) {
let sb = new ScriptBuilder();
//sb.CallRPC('interop', 'GetNexusName', []);
return sb;
}
39 changes: 21 additions & 18 deletions src/lib/Components/Airdrop/AirdropCommands.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Address,
PhantasmaAPI,
ScriptBuilder,
Token,
Base16,
} from 'phantasma-ts/src';
import { Address, PhantasmaAPI, ScriptBuilder, Token, Base16 } from 'phantasma-ts/src';
import {
AirdropFee,
GasLimit,
Expand Down Expand Up @@ -96,23 +90,27 @@ export function AirdropFT(
return;
}

const numberOfDistributions = userList.length / 100;
let comulativeFee = (userList.length / 100) * AirdropFee;
const numberOfDistributions = userList.length / 50;
let comulativeFee = (userList.length / 50) * AirdropFee;
if (numberOfDistributions < 1) comulativeFee = AirdropFee;
const from = Address.FromText(String(Link.account.address));
const payload = Base16.encode('Tools.AirdropFT');
const sb = new ScriptBuilder();
sb.AllowGas(from, Address.Null, gasPrice, gasLimit);

if (tipActive) {
sb.CallInterop('Runtime.TransferTokens', [from, TipAddress, 'KCAL', String(comulativeFee)]);
//sb.CallInterop('Runtime.TransferTokens', [from, TipAddress, 'KCAL', comulativeFee]);
sb.CallInterop('Runtime.TransferTokens', [
from.Text,
TipAddress,
'KCAL',
String(comulativeFee)
]);
}

for (const user of userList) {
const toAddress = Address.FromText(user.user);
const amount = String(user.amount);
sb.CallInterop('Runtime.TransferTokens', [from, toAddress, symbol, amount]);
sb.CallInterop('Runtime.TransferTokens', [from.Text, toAddress.Text, symbol, String(amount)]);
}
const myScript = sb.SpendGas(from).EndScript();

Expand All @@ -130,7 +128,7 @@ export function AirdropFT(
);
},
function () {
NotificationError('Airdrop Error!', 'Error doing the Airdrop!');
NotificationError('Airdrop Error!', 'User canceled the Airdrop!');
}
);
}
Expand All @@ -156,19 +154,24 @@ export function AirdropNFT(symbol: string, userList: Array<{ user; id }>, totalA
const from = Address.FromText(String(Link.account.address));
const payload = Base16.encode('Tools.AirdropNFT');

const numberOfDistributions = userList.length / 100;
let comulativeFee = (userList.length / 100) * AirdropFee;
const numberOfDistributions = userList.length / 50;
let comulativeFee = (userList.length / 50) * AirdropFee;
if (numberOfDistributions < 1) comulativeFee = AirdropFee;
const sb = new ScriptBuilder();
sb.AllowGas(from, Address.Null, gasPrice, gasLimit);
if (tipActive) {
//sb.CallInterop('Runtime.TransferTokens', [from, TipAddress, 'KCAL', comulativeFee]);
sb.CallInterop('Runtime.TransferTokens', [
from.Text,
TipAddress,
'KCAL',
String(comulativeFee)
]);
}

for (const user of userList) {
const toAddress = Address.FromText(user.user);
const id = String(user.id);
sb.CallInterop('Runtime.TransferToken', [from, toAddress, symbol, id]);
sb.CallInterop('Runtime.TransferToken', [from.Text, toAddress.Text, symbol, String(id)]);
}

const myScript = sb.SpendGas(from).EndScript();
Expand All @@ -183,7 +186,7 @@ export function AirdropNFT(symbol: string, userList: Array<{ user; id }>, totalA
);
},
function () {
NotificationError('Airdrop Error!', 'Error doing the Airdrop!');
NotificationError('Airdrop Error!', 'User canceled the Airdrop!');
}
);
}
52 changes: 51 additions & 1 deletion src/lib/Components/Airdrop/AirdropFT.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@
continue;
}
if (userDistribution == 0) {
if (userAddressess.length >= numberOfUsers) {
numberOfInvalidAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replace(
addr,
`<span class="error" style="color:red !important">${addr}</span>`
);
continue;
}
}
if (userAddressess.includes(addrTrimmed)) {
numberOfRepeatedAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replaceAll(
Expand Down Expand Up @@ -196,7 +207,43 @@
}
function onChangeNumberOfUsers() {
console.log(numberOfUsers);
let listBefore;
listBefore = userAddressessRAW.split(/[\n ,]+/);
userAddressessRAW = listBefore.join('\n');
userAddressessRAWEdited = listBefore.join('<br>');
numberOfInvalidAddresses = 0;
numberOfRepeatedAddresses = 0;
userAddressess = [];
for (let addr of listBefore) {
let addrTrimmed = addr.trim();
if (!Address.IsValidAddress(addrTrimmed)) {
numberOfInvalidAddresses++;
//userAddressessRAW = userAddressessRAW.replace(addr, `<span class="error">${addr}</span>`);
continue;
}
if (userDistribution == 0) {
if (userAddressess.length >= numberOfUsers) {
numberOfInvalidAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replace(
addr,
`<span class="error" style="color:red !important">${addr}</span>`
);
continue;
}
}
if (userAddressess.includes(addrTrimmed)) {
numberOfRepeatedAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replaceAll(
addr,
`<span class="error" style="color:red !important">${addr}</span>`
);
}
userAddressess.push(addr);
}
}
</script>

Expand Down Expand Up @@ -330,6 +377,9 @@
id="numberOfUsers"
bind:value={numberOfUsers}
on:change={onChangeNumberOfUsers}
on:keypress={onChangeNumberOfUsers}
on:keydown={onChangeNumberOfUsers}
on:keyup={onChangeNumberOfUsers}
class="block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-solid border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer"
placeholder=" "
required
Expand Down
55 changes: 55 additions & 0 deletions src/lib/Components/Airdrop/AirdropNFT.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@
continue;
}
if (userDistribution == 0) {
if (userAddressess.length >= numberOfUsers) {
numberOfInvalidAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replace(
addr,
`<span class="error" style="color:red !important">${addr}</span>`
);
continue;
}
}
if (userAddressess.includes(addrTrimmed)) {
numberOfRepeatedAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replaceAll(
Expand Down Expand Up @@ -188,6 +199,46 @@
console.log(selectedToken);
listOfNFTs = await GetNFTList(selectedToken);
}
function onChangeNumberOfUsers() {
let listBefore;
listBefore = userAddressessRAW.split(/[\n ,]+/);
userAddressessRAW = listBefore.join('\n');
userAddressessRAWEdited = listBefore.join('<br>');
numberOfInvalidAddresses = 0;
numberOfRepeatedAddresses = 0;
userAddressess = [];
for (let addr of listBefore) {
let addrTrimmed = addr.trim();
if (!Address.IsValidAddress(addrTrimmed)) {
numberOfInvalidAddresses++;
//userAddressessRAWEdited = userAddressessRAWEdited.replace(addr, `<span class="error">${addr}</span>`);
continue;
}
if (userDistribution == 0) {
if (userAddressess.length >= numberOfUsers) {
numberOfInvalidAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replace(
addr,
`<span class="error" style="color:red !important">${addr}</span>`
);
continue;
}
}
if (userAddressess.includes(addrTrimmed)) {
numberOfRepeatedAddresses++;
userAddressessRAWEdited = userAddressessRAWEdited.replaceAll(
addr,
`<span class="error" style="color:red !important">${addr}</span>`
);
}
userAddressess.push(addr);
}
}
</script>

<Card
Expand Down Expand Up @@ -321,6 +372,10 @@
name="numberOfUsers"
id="numberOfUsers"
bind:value={numberOfUsers}
on:change={onChangeNumberOfUsers}
on:keypress={onChangeNumberOfUsers}
on:keydown={onChangeNumberOfUsers}
on:keyup={onChangeNumberOfUsers}
class="block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-solid border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer"
placeholder=" "
required
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Components/Card/APISelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
DefaultAPIURL,
ExplorerURL,
ExplorerURLMainnet,
ExplorerURLTestnet
ExplorerURLTestnet,
SelectedNexus
} from '$lib/store';
import { NotificationSuccess } from '../Notification/NotificationsBuilder';
import { PhantasmaAPI } from 'phantasma-ts';
Expand All @@ -33,6 +34,7 @@
let nexusName = e.target.selectedOptions[0].dataset.net;
PhantasmaAPIClient.set(new PhantasmaAPI(selectedAPI, null, nexusName));
API_URL.set(selectedAPI);
SelectedNexus.set(nexusName);
ExplorerURL.set(nexusName == 'mainnet' ? ExplorerURLMainnet : ExplorerURLTestnet);
connectToAPI();
NotificationSuccess('API Changed', `API has been changed to <b>${nexusName}</b> network.`);
Expand Down
Loading

0 comments on commit 7f4f677

Please sign in to comment.