-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07b7c31
commit e46b609
Showing
12 changed files
with
225 additions
and
231 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Accordion, Badge, Button, copyTextToClipboard, Flex, Text, Tooltip } from '@near-pagoda/ui'; | ||
import { Copy } from '@phosphor-icons/react'; | ||
|
||
import type { Drops } from '@/utils/types'; | ||
|
||
const getDropName = (drop: Drops) => { | ||
return drop ? JSON.parse(drop.metadata).dropName : ''; | ||
}; | ||
|
||
const ListTokenDrop = ({ drops }: { drops: Drops[] }) => { | ||
return ( | ||
<Accordion.Root type="multiple"> | ||
{drops.map((drop) => { | ||
return ( | ||
<Accordion.Item key={drop.drop_id} value={drop.drop_id}> | ||
<Accordion.Trigger> | ||
{getDropName(drop)} - Claimed {drop.next_key_id - drop.registered_uses}/{drop.next_key_id} | ||
</Accordion.Trigger> | ||
<Accordion.Content> | ||
{drop.keys && | ||
drop.keys.map((key) => { | ||
const wasClaimed = !drop.information.some((info) => info.pk == key.public); | ||
return ( | ||
<Flex align="center" justify="space-between" key={key.private}> | ||
<Text style={{ maxWidth: '10rem' }} clampLines={1}> | ||
{key.private} | ||
</Text> | ||
<Badge | ||
label={wasClaimed ? 'Claimed' : 'Unclaimed'} | ||
variant={wasClaimed ? 'success' : 'neutral'} | ||
/> | ||
<Tooltip content="Copy Account ID"> | ||
<Button | ||
label="copy" | ||
onClick={() => { | ||
const url = 'https://app.mynearwallet.com' + '/linkdrop/v2.keypom.near/' + key.private; | ||
copyTextToClipboard(url, url); | ||
}} | ||
size="small" | ||
fill="outline" | ||
icon={<Copy />} | ||
/> | ||
</Tooltip> | ||
</Flex> | ||
); | ||
})} | ||
</Accordion.Content> | ||
</Accordion.Item> | ||
); | ||
})} | ||
</Accordion.Root> | ||
); | ||
}; | ||
|
||
export default ListTokenDrop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Drops } from '@/utils/types'; | ||
|
||
import CreateTokenDrop from './CreateTokenDrop'; | ||
import ListTokenDrop from './ListTokenDrop'; | ||
|
||
const Linkdrops = ({ drops }: { drops: Drops[] }) => { | ||
return ( | ||
<> | ||
<CreateTokenDrop /> | ||
<ListTokenDrop drops={drops} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default Linkdrops; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useContext, useEffect, useState } from 'react'; | ||
|
||
import { NearContext } from '@/components/WalletSelector'; | ||
import { getKeypomKeys } from '@/utils/linkdrops'; | ||
import type { Drops } from '@/utils/types'; | ||
|
||
const useLinkdrops = () => { | ||
const { signedAccountId } = useContext(NearContext); | ||
const [drops, setDrops] = useState<Drops[]>([]); | ||
|
||
const { wallet } = useContext(NearContext); | ||
|
||
useEffect(() => { | ||
const fetchDropData = async () => { | ||
if (!wallet || !signedAccountId) return; | ||
const fetchedDrops: Drops[] = await wallet.viewMethod({ | ||
contractId: 'v2.keypom.near', | ||
method: 'get_drops_for_owner', | ||
args: { account_id: signedAccountId }, | ||
}); | ||
|
||
const filteredDrops = fetchedDrops.filter( | ||
(drop) => | ||
drop.metadata && | ||
JSON.parse(drop.metadata).dropName && | ||
getKeypomKeys(JSON.parse(drop.metadata).dropName).length, | ||
); | ||
|
||
const fetchedInformationDrops = await Promise.all( | ||
filteredDrops.map(async (drop) => { | ||
const information = await wallet.viewMethod({ | ||
contractId: 'v2.keypom.near', | ||
method: 'get_keys_for_drop', | ||
args: { drop_id: drop.drop_id }, | ||
}); | ||
return { ...drop, information }; | ||
}), | ||
); | ||
|
||
const localDataDrops = fetchedInformationDrops.map((drop) => ({ | ||
...drop, | ||
keys: getKeypomKeys(JSON.parse(drop.metadata).dropName), | ||
})); | ||
|
||
setDrops(localDataDrops); | ||
}; | ||
|
||
fetchDropData(); | ||
}, [wallet, signedAccountId]); | ||
|
||
return drops; | ||
}; | ||
|
||
export default useLinkdrops; |
Oops, something went wrong.