Skip to content

Commit

Permalink
Airdrop improvements
Browse files Browse the repository at this point in the history
Fix permanent loading if airdrop is poorly constructed
  • Loading branch information
grctest committed Jul 28, 2023
1 parent 7f1e98c commit abea704
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 68 deletions.
20 changes: 10 additions & 10 deletions public/locales/ja/nodes.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"title": "ブロックチェーンノードの構成",
"radio": {
"label": "ターゲットのブロックチェーンを選択します",
"desc": "グラフェンベースのブロックチェーンのみ"
},
"th1": "現在 {{value}} ブロックチェーンノードの順序",
"title2": "自分自身の使用に興味がある {{value}} ブロックチェーンノード?",
"urlLabel": "URLを入力してください {{value}} ブロックチェーン",
"btn": "送信"
}
"title": "ブロックチェーンノードの構成",
"radio": {
"label": "ターゲットのブロックチェーンを選択します",
"desc": "グラフェンベースのブロックチェーンのみ"
},
"th1": "現在 {{value}} ブロックチェーンノードの順序",
"title2": "自分自身の使用に興味がある {{value}} ブロックチェーンノード?",
"urlLabel": "URLを入力してください {{value}} ブロックチェーン",
"btn": "送信"
}
20 changes: 10 additions & 10 deletions public/locales/ko/nodes.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"title": "블록체인 노드 구성",
"radio": {
"label": "대상 블록체인 선택",
"desc": "그래핀 기반 블록체인 전용"
},
"th1": "현재의 {{value}} 블록체인 노드 순서",
"title2": "자신의 사용에 관심 {{value}} 블록체인 노드?",
"urlLabel": "URL을 입력하세요. {{value}} 블록체인",
"btn": "제출하다"
}
"title": "블록체인 노드 구성",
"radio": {
"label": "대상 블록체인 선택",
"desc": "그래핀 기반 블록체인 전용"
},
"th1": "현재의 {{value}} 블록체인 노드 순서",
"title2": "자신의 사용에 관심 {{value}} 블록체인 노드?",
"urlLabel": "URL을 입력하세요. {{value}} 블록체인",
"btn": "제출하다"
}
6 changes: 3 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ function App() {
];

const localeItems = languages.map((lang) => (
<Menu.Item key={`lang_${lang.value}`} onClick={() => setLanguage(lang.value)}>
{ lang.label }
</Menu.Item>
<Menu.Item key={`lang_${lang.value}`} onClick={() => setLanguage(lang.value)}>
{ lang.label }
</Menu.Item>
));

return (
Expand Down
6 changes: 5 additions & 1 deletion src/lib/airdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ async function getTokenRows(
const equalAllocation = parseFloat(
((1 / equalTally) * remainingTokens).toFixed(tokenDetails.precision)
);

if (!equalAllocation || Number.isNaN(equalAllocation)) {
continue;
}

remainingTokens -= equalAllocation;
equalTally -= 1;
validOutput[i].assignedTokens = equalAllocation;
Expand All @@ -254,7 +259,6 @@ function filterMinRewards(variables, zustandSet) {
const { invalidOutput, unassignedUsers } = variables;
const { setFinalInvalidOutput } = zustandSet;

// console.log({ invalidOutput, unassignedUsers })
const invalidOutputMap = new Map(Array.from(invalidOutput, (x) => [x.id, x]));
const newInvalidOutput = unassignedUsers.reduce((acc, current) => {
const currentInvalid = invalidOutputMap.get(current.id);
Expand Down
7 changes: 2 additions & 5 deletions src/lib/states.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const assetStore = create(
bitshares: [],
bitshares_testnet: [],
tusc: [],
changeAssets: (env, leaders) => {
changeAssets: (env, newAssets) => {
const newObj = {};
newObj[env] = leaders;
newObj[env] = newAssets;
set(newObj);
},
addOne: (env, newAsset) => {
Expand Down Expand Up @@ -264,7 +264,6 @@ const appStore = create(
bitshares_fees: null, // {fee, maxBytes}
bitshares_testnet_fees: null,
tusc_fees: null,
account: "",
replaceNodes: (env, nodes) => {
if (env === 'bitshares') {
set(async (state) => ({
Expand All @@ -280,7 +279,6 @@ const appStore = create(
}));
}
},
setAccount: (newAccount) => set({ account: newAccount }),
setFees: (env, newFees) => {
if (env === 'bitshares') {
set({
Expand Down Expand Up @@ -344,7 +342,6 @@ const appStore = create(
bitshares_fees: null, // {fee, maxBytes}
bitshares_testnet_fees: null,
tusc_fees: null,
account: "",
}),
removeURL: (env, url) => {
let nodesToChange = get().nodes[env];
Expand Down
72 changes: 52 additions & 20 deletions src/pages/CustomAirdrop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ import _ from "lodash";
import { sort } from 'fast-sort';
import {
HiOutlineShieldExclamation,
HiOutlineShieldCheck,
} from "react-icons/hi";

import {
BiError,
} from "react-icons/bi";

import {
appStore,
leaderboardStore,
Expand Down Expand Up @@ -219,7 +222,12 @@ export default function CustomAirdrop(properties) {
reasons.push("self");
}

if (validTicketHolders && validTicketHolders.length && ticketHolder && ticketHolder !== 'both') {
if (
validTicketHolders
&& validTicketHolders.length
&& ticketHolder
&& ticketHolder !== 'both'
) {
const ticketCheck = validTicketHolders.includes(user.id);
if (ticketHolder === 'onlyHolders' && !ticketCheck) {
// Filter out non-ticket holders
Expand Down Expand Up @@ -343,7 +351,7 @@ export default function CustomAirdrop(properties) {
]);

const winners = useMemo(() => {
if (!tokenRows || !tokenDetails) {
if ((!tokenRows || !tokenRows.length) || !tokenDetails) {
return null;
}
console.time("winners");
Expand Down Expand Up @@ -476,23 +484,47 @@ export default function CustomAirdrop(properties) {

<SimpleGrid cols={2} spacing="sm" mt={10} breakpoints={[{ maxWidth: 'md', cols: 2 }]}>
{
leftAirdropCard || (
<Card shadow="md" radius="md" padding="xl">

<Title ta="center" order={4}>
{t("customAirdrop:grid.left.loading")}
</Title>

<Center>
<Text mt="sm">
{t("customAirdrop:header.processing")}
</Text>
</Center>
<Center>
<Loader variant="dots" mt="md" />
</Center>
</Card>
)
!tokenRows
? (
<Card shadow="md" radius="md" padding="xl">
<Title ta="center" order={4}>
{t("customAirdrop:grid.left.loading")}
</Title>

<Center>
<Text mt="sm">
{t("customAirdrop:header.processing")}
</Text>
</Center>
<Center>
<Loader variant="dots" mt="md" />
</Center>
</Card>
)
: null
}
{
tokenRows && !winners
? (
<Card shadow="md" radius="md" padding="xl">
<Center>
<BiError size={50} />
</Center>
<Title ta="center" order={4}>
{t("customAirdrop:grid.right.invalid.title")}
</Title>

<Center>
<Text mt="sm">
{t("customAirdrop:grid.right.invalid.resolution")}
</Text>
</Center>
</Card>
)
: null
}
{
winners && winners.length && leftAirdropCard
}
<Card>
<SimpleGrid cols={1} spacing="sm">
Expand Down
69 changes: 50 additions & 19 deletions src/pages/PerformAirdrop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
HiOutlineShieldCheck,
} from "react-icons/hi";

import {
BiError,
} from "react-icons/bi";

import {
airdropStore,
appStore,
Expand Down Expand Up @@ -218,7 +222,11 @@ export default function PerformAirdrop(properties) {
useEffect(() => {
fetchAirdropDetails(
{
account, finalTokenName, cachedAssets
account,
finalTokenName,
cachedAssets,
currentNodes,
env: params.env
},
{
addOne, changeURL, setTokenDetails, setInProgress
Expand Down Expand Up @@ -605,25 +613,48 @@ export default function PerformAirdrop(properties) {
? (
<SimpleGrid cols={2} spacing="sm" mt={10} breakpoints={[{ maxWidth: 'md', cols: 2 }]}>
{
leftAirdropCard || (
<Card shadow="md" radius="md" padding="xl">

<Title ta="center" order={4}>
{t("customAirdrop:grid.left.loading")}
</Title>

<Center>
<Text mt="sm">
{t("customAirdrop:header.processing")}
</Text>
</Center>
<Center>
<Loader variant="dots" mt="md" />
</Center>
</Card>
)
!tokenRows
? (
<Card shadow="md" radius="md" padding="xl">
<Title ta="center" order={4}>
{t("customAirdrop:grid.left.loading")}
</Title>

<Center>
<Text mt="sm">
{t("customAirdrop:header.processing")}
</Text>
</Center>
<Center>
<Loader variant="dots" mt="md" />
</Center>
</Card>
)
: null
}
{
tokenRows && (!winners || !winners.length)
? (
<Card shadow="md" radius="md" padding="xl">
<Center>
<BiError size={50} />
</Center>
<Title ta="center" order={4}>
{t("customAirdrop:grid.right.invalid.title")}
</Title>

<Center>
<Text mt="sm">
{t("customAirdrop:grid.right.invalid.resolution")}
</Text>
</Center>
</Card>
)
: null
}
{
(winners && winners.length && leftAirdropCard) || null
}

<Card>
<SimpleGrid cols={1} spacing="sm">
<Card shadow="md" radius="md" padding="xl">
Expand Down

0 comments on commit abea704

Please sign in to comment.