mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Add Org treasury to org profile
Signed-off-by: Sebastian Martinez <sebastinez@me.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import type { SvelteComponent } from 'svelte';
|
||||
import type { Config } from '@app/config';
|
||||
import type { BigNumber } from "ethers";
|
||||
import { formatName, explorerLink } from '@app/utils';
|
||||
import { session } from '@app/session';
|
||||
import Loading from '@app/Loading.svelte';
|
||||
@@ -44,6 +45,20 @@
|
||||
const transferOwnership = () => {
|
||||
transferOwnerForm = TransferOwnership;
|
||||
};
|
||||
$: getOrgTreasury = async (org: Org): Promise<Array<{ name: string; symbol: string; logo: string; decimals: number; balance: BigNumber }>| undefined> => {
|
||||
const addressType = await utils.identifyAddress(org.owner, config);
|
||||
// We query the org treasury only for Gnosis Safes, to maintain some privacy for EOA org owners.
|
||||
if (addressType === utils.AddressType.Safe) {
|
||||
try {
|
||||
const tokens = await utils.getTokens(org.owner, config);
|
||||
const balance = await config.provider.getBalance(org.owner);
|
||||
// To maintain the format we hardcode the ETH specs.
|
||||
return [{ balance, decimals: 18, logo: "", name: "Ethereum", symbol: "ETH" }, ...tokens];
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
$: isOwner = (org: Org): boolean => $session
|
||||
? utils.isAddressEqual(org.owner, $session.address)
|
||||
: false;
|
||||
@@ -207,6 +222,17 @@
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{#await getOrgTreasury(org) then tokens}
|
||||
{#if tokens}
|
||||
<div class="label">Treasury</div>
|
||||
<div>
|
||||
{#each tokens as token}
|
||||
{` ${utils.formatBalance(token.balance)} ${token.symbol} `}
|
||||
{/each}
|
||||
</div>
|
||||
<div></div>
|
||||
{/if}
|
||||
{/await}
|
||||
<!-- Seed Address -->
|
||||
{#if profile.seedId && profile.seedHost}
|
||||
<div class="label">Seed</div>
|
||||
|
||||
+15
-5
@@ -1,5 +1,5 @@
|
||||
import { ethers } from "ethers";
|
||||
import type { BigNumber } from "ethers";
|
||||
import { BigNumber } from "ethers";
|
||||
import multibase from 'multibase';
|
||||
import multihashes from 'multihashes';
|
||||
import EthersSafe, { EthersAdapter } from "@gnosis.pm/safe-core-sdk";
|
||||
@@ -380,12 +380,22 @@ export async function getOwnerSafes(owner: string, config: Config): Promise<stri
|
||||
|
||||
// Get token balances for an address.
|
||||
export async function getTokens(address: string, config: Config):
|
||||
Promise<Array<{ tokenName: string; tokenLogo: string }>>
|
||||
Promise<Array<{ name: string; symbol: string; decimals: number; logo: string; balance: BigNumber }>>
|
||||
{
|
||||
await config.provider.send("alchemy_getTokenBalances", [address, config.tokens]);
|
||||
const userBalances = await config.provider.send("alchemy_getTokenBalances", [address, "DEFAULT_TOKENS"]);
|
||||
const balances = userBalances.tokenBalances.filter((token: any) => {
|
||||
// alchemy_getTokenBalances sometimes returns 0x and this does not work well with ethers.BigNumber
|
||||
if (token.tokenBalance !== "0x") {
|
||||
if (!BigNumber.from(token.tokenBalance).isZero()) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}).map(async (token: any) => {
|
||||
const tokenMetaData = await config.provider.send("alchemy_getTokenMetadata", [token.contractAddress]);
|
||||
return { ...tokenMetaData, balance: BigNumber.from(token.tokenBalance) };
|
||||
});
|
||||
|
||||
// TODO
|
||||
return [];
|
||||
return Promise.all(balances);
|
||||
}
|
||||
|
||||
// Check whether the given path has a markdown file extension.
|
||||
|
||||
Reference in New Issue
Block a user