Skip to content
Open

Dev #127

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a31f3cd
[ADD] coin98
Calcifer1001 Nov 21, 2022
e5114b9
[ADD] coin98
Calcifer1001 Nov 21, 2022
17fa6f3
Fix Merge branch 'dev' into calcifer1001/coin98
Jan 9, 2023
14f5c23
fix lint issue
Jan 10, 2023
cba6262
Merge pull request #109 from Narwallets/calcifer1001/coin98
Jan 10, 2023
b2f8acf
upgrade herer wallet 7.4.0
Jan 13, 2023
9d114da
token.metadata.name to token.metadata.symbol
leomanza Jan 31, 2023
25d6d69
Merge pull request #120 from Narwallets/manza/get_meta_update_token_s…
leomanza Jan 31, 2023
abc54df
fix build error -> dep issues
leomanza Jan 31, 2023
414240c
Merge pull request #121 from Narwallets/manza/fix_build
leomanza Jan 31, 2023
772bd43
update token name to symbol
leomanza Jan 31, 2023
99447d2
Merge pull request #122 from Narwallets/manza/update_token_name_to_sy…
leomanza Jan 31, 2023
0d1bdd7
[ADD] narwallets
Calcifer1001 Feb 1, 2023
166ad1e
min received styles update
leomanza Feb 1, 2023
af6f72d
Merge pull request #124 from Narwallets/manza/get_meta_min_received_s…
leomanza Feb 1, 2023
6a568c8
Merge pull request #123 from Narwallets/narwallets
leomanza Feb 1, 2023
0b2c497
improve ux - show meta on return and usd rate
leomanza Feb 2, 2023
b40a260
fix input amount validation
leomanza Feb 2, 2023
30e8169
Merge pull request #125 from Narwallets/manza/get_meta_improve_ux
leomanza Feb 2, 2023
d79ad0b
[ADD] xdefi
Calcifer1001 Feb 14, 2023
831c036
Merge branch 'dev' of https://github.com/Narwallets/meta-vote into xdefi
Calcifer1001 Feb 14, 2023
584503f
Merge pull request #126 from Narwallets/xdefi
Calcifer1001 Feb 15, 2023
64730be
Merge branch 'main' into dev
Calcifer1001 Feb 16, 2023
38a7545
code comments
The-Preem-Palver May 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions contract/meta-vote-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ impl MetaVoteContract {
/* View functions */
/**********************/

// get all information, voter + locking-positions + voting-positions
pub fn get_voters(&self, from_index: u32, limit: u32) -> Vec<VoterJSON> {
let keys = self.voters.keys_as_vector();
let voters_len = keys.len() as u64;
Expand Down Expand Up @@ -600,6 +601,7 @@ impl MetaVoteContract {
(self.min_locking_period, self.max_locking_period)
}

// all locking positions for a voter
pub fn get_all_locking_positions(
&self,
voter_id: VoterId
Expand Down Expand Up @@ -628,6 +630,7 @@ impl MetaVoteContract {
}
}

// votes by app and votable_object
pub fn get_total_votes(
&self,
contract_address: ContractAddress,
Expand All @@ -642,6 +645,7 @@ impl MetaVoteContract {
U128::from(votes)
}

// votes by app
pub fn get_votes_by_contract(
&self,
contract_address: ContractAddress
Expand Down
6 changes: 6 additions & 0 deletions front/contexts/WalletSelectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { getConfig } from "../config";
import { setupWalletConnect } from "@near-wallet-selector/wallet-connect";
import { setupNearWallet } from "@near-wallet-selector/near-wallet";
import { setupHereWallet } from "@near-wallet-selector/here-wallet";
import { setupCoin98Wallet } from "@near-wallet-selector/coin98-wallet";
import { setupMeteorWallet } from "@near-wallet-selector/meteor-wallet";
import { setupXDEFI } from "@near-wallet-selector/xdefi";
import { setupNarwallets } from "@near-wallet-selector/narwallets";
declare global {
interface Window {
selector: WalletSelector;
Expand Down Expand Up @@ -50,6 +53,7 @@ export const WalletSelectorContextProvider: React.FC = ({ children }) => {
network: NETWORK_ID as NetworkId,
debug: true,
modules: [
setupNarwallets(),
setupMeteorWallet() as WalletModuleFactory<Wallet>,
setupNearWallet({
walletUrl: nearConfig.walletUrl,
Expand All @@ -58,6 +62,8 @@ export const WalletSelectorContextProvider: React.FC = ({ children }) => {
setupMyNearWallet(),
setupMathWallet(),
setupNightly(),
setupCoin98Wallet(),
setupXDEFI(),
// setupLedger(),
setupWalletConnect({
projectId:
Expand Down
43 changes: 21 additions & 22 deletions front/lib/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,8 @@ const callPublicMetavoteMethod = async (method: string, args: any) => {
return decodeJsonRpcData(response.result);
};

const callChangeMetavoteMethod = async (
method: string,
args: any,
deposit?: string
): Promise<FinalExecutionOutcome | null> => {
const wallet = window.wallet;
const callChangeMetavoteMethod = async (method: string, args: any, deposit?: string): Promise<FinalExecutionOutcome | null> => {
const wallet = window.wallet || await window.selector.wallet();
const account_id = window.account_id;
blockerStore.setState({ isActive: true });
const result = await wallet!
Expand All @@ -225,13 +221,13 @@ const callChangeMetavoteMethod = async (
.catch((err) => {
console.error(`Failed to call metavote contract -- method: ${method}`);
throw getPanicErrorFromText(err.message);
})
.finally(() => {
blockerStore.setState({ isActive: false });
}).
finally(()=> {
blockerStore.setState({isActive: false});
});
if (result instanceof Object) {
return result;
}
if (result instanceof Object) {
return result;
}
return null;
};

Expand Down Expand Up @@ -298,7 +294,7 @@ export const getBalanceOfTokenForSupporter = async (
};

const callChangeMetaTokenMethod = async (method: string, args: any) => {
const wallet = window.wallet;
let wallet = window.wallet || await window.selector.wallet();
const account_id = window.account_id;
blockerStore.setState({ isActive: true });
const result = await wallet!.signAndSendTransaction({
Expand All @@ -312,15 +308,18 @@ const callChangeMetaTokenMethod = async (method: string, args: any) => {
args: args,
gas: GAS,
deposit: "1",
},
},
],
});
checkPanicError(result);
blockerStore.setState({ isActive: false });
if (result instanceof Object) {
return result;
}
}
}]
}).catch((err) => {
console.error(`Failed to call metavote contract -- method: ${method}`);
throw getPanicErrorFromText(err.message);
}).finally(()=> {
blockerStore.setState({isActive: false});
})
checkPanicError(result);
if (result instanceof Object) {
return result;
}
return null;
};

Expand Down
8 changes: 5 additions & 3 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@
"@emotion/react": "^11.8.2",
"@emotion/styled": "^11.8.1",
"@fontsource/inter": "^4.5.5",
"@meta-pool-apps/meta-shared-components": "^0.1.0",
"@near-wallet-selector/coin98-wallet": "^7.1.0",
"@near-wallet-selector/core": "^7.0.3",
"@near-wallet-selector/here-wallet": "^7.4.0",
"@near-wallet-selector/ledger": "^7.0.3",
"@near-wallet-selector/math-wallet": "^7.0.3",
"@near-wallet-selector/meteor-wallet": "^7.0.3",
"@near-wallet-selector/meteor-wallet": "^7.0.3",
"@near-wallet-selector/modal-ui": "^7.0.3",
"@near-wallet-selector/my-near-wallet": "^7.0.3",
"@near-wallet-selector/narwallets": "^7.6.1",
"@near-wallet-selector/near-wallet": "^7.0.3",
"@near-wallet-selector/nightly": "^7.0.3",
"@near-wallet-selector/wallet-connect": "^7.0.3",
"@near-wallet-selector/xdefi": "^7.6.1",
"@types/gtag.js": "^0.0.10",
"better-sqlite3": "^7.6.2",
"better-sqlite3": "^8.0.1",
"bn": "^1.0.5",
"caniuse-lite": "^1.0.30001396",
"dotenv": "^16.0.0",
Expand Down
8 changes: 4 additions & 4 deletions front/pages/get-meta/DetailInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ const DetailInfo = ({ name, children, ...props }: Props) => {
<HStack justifyContent="space-between" spacing={10} w="full" {...props}>
<Stack w="max-content" align="flex-end">
<Text
fontSize={"xs"}
fontSize={props.fontSize || "xs"}
lineHeight={3}
color={"gray.400"}
color={props.color || "gray.400"}
letterSpacing="wide"
>
{name}
</Text>
</Stack>
<Stack justify="flex-end">
<Text
fontSize={"xs"}
fontSize={props.fontSize || "xs"}
lineHeight={3}
color={colors.white}
color={props.color || colors.white}
letterSpacing="wide"
>
{children}
Expand Down
32 changes: 25 additions & 7 deletions front/pages/get-meta/TokenAmount/TokenAmountInUsd.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Text, TextProps } from "@chakra-ui/react";
import React, { useEffect } from "react";
import { number } from "yup";
import { useGetMetapoolContractState } from "../../../hooks/metapool";
import { useGetNearDollarPrice } from "../../../hooks/near";
import { formatToLocaleNear, yton } from "../../../lib/util";
import { isStNearDenomination } from "../TokenIcon/util";
import { isMetaDenomination, isStNearDenomination } from "../TokenIcon/util";
interface Props extends TextProps {
currency?: string;
amount?: number;
stNearRate?: number;
}
const TokenAmountInUsd = ({ currency, amount, ...props }: Props) => {
const TokenAmountInUsd = ({ currency, amount, stNearRate, ...props }: Props) => {
const { data: nearPrice, isLoading: isLoadingNearPrice } =
useGetNearDollarPrice();
const { data: metapoolState, isLoading: isLoadingMetapool } =
useGetMetapoolContractState();

if (!currency || !amount || amount == 0)
return (
<Text
Expand All @@ -24,7 +25,7 @@ const TokenAmountInUsd = ({ currency, amount, ...props }: Props) => {
{...props}
>
{" "}
~ USD -
USD -
</Text>
);
if (currency == "NEAR")
Expand All @@ -36,7 +37,7 @@ const TokenAmountInUsd = ({ currency, amount, ...props }: Props) => {
letterSpacing="wide"
{...props}
>
~ USD {formatToLocaleNear(amount * nearPrice, 2)}
USD {" "} {formatToLocaleNear(amount * nearPrice, 2)}
</Text>
);
if (isStNearDenomination(currency))
Expand All @@ -48,13 +49,30 @@ const TokenAmountInUsd = ({ currency, amount, ...props }: Props) => {
letterSpacing="wide"
{...props}
>
~ USD
USD {" "}
{formatToLocaleNear(
amount * yton(metapoolState?.st_near_price!) * nearPrice,
2
)}
</Text>
);
if (isMetaDenomination(currency) && stNearRate ){
return (
<Text
fontSize={"xs"}
lineHeight={3}
color={"gray.400"}
letterSpacing="wide"
{...props}
>
≈ USD {" "}
{formatToLocaleNear(
amount * stNearRate * yton(metapoolState?.st_near_price!) * nearPrice,
4
)}
</Text>
);
}
return (
<Text
fontSize={"xs"}
Expand All @@ -63,7 +81,7 @@ const TokenAmountInUsd = ({ currency, amount, ...props }: Props) => {
letterSpacing="wide"
{...props}
>
~ USD N/A
USD N/A
</Text>
);
};
Expand Down
23 changes: 18 additions & 5 deletions front/pages/get-meta/TokenAmount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,29 @@ export interface Props extends StackProps {
currency?: string;
amount: number;
setAmount: (value: number) => void;
setAmountError: (value: string | undefined) => void;
setAmountError?: (value: string | undefined) => void;
readOnly?: boolean;
stNearRate?: number;
}
const TokenAmount = ({
currency,
amount,
setAmount,
setAmountError,
readOnly,
stNearRate,
}: Props) => {
const { accountId } = useWalletSelector();
const { data: balance } = useGetBalance(accountId!, currency);

useEffect(() => {
setAmountError(undefined);
if (amount > yton(balance)) {
setAmountError("Insufficiente balance");
if (setAmountError) {
setAmountError(undefined);
if (!currency) {
setAmountError("Select a token");
} else if (amount > yton(balance)) {
setAmountError("Insufficient balance");
}
}
}, [balance, amount, currency]);

Expand All @@ -39,8 +47,13 @@ const TokenAmount = ({
onPaste={(e) => setAmount(Number(e.currentTarget.value))}
value={amount}
onChange={(e) => setAmount(Number(e.target.value))}
isReadOnly={readOnly}
/>
<TokenAmountInUsd
currency={currency}
amount={amount}
stNearRate={stNearRate}
/>
<TokenAmountInUsd currency={currency} amount={amount} />
</VStack>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import {
isNearDenomination,
} from "./util";

interface TokenIconProps extends TextProps {
interface Props extends TextProps {
denomination: string;
}
export default function TokenName({ denomination, ...props }: TokenIconProps) {
export default function TokenSymbol({ denomination, ...props }: Props) {
const { data: metadata, isLoading } = useGetTokenMetadata(denomination);
if (isNearDenomination(denomination)) {
return <Text {...props}>{denomination}</Text>;
}
return !isLoading && metadata ? (

<Text {...props}>{metadata?.name}</Text>
<Text {...props}>{metadata?.symbol}</Text>

) : null;
}
6 changes: 3 additions & 3 deletions front/pages/get-meta/TokenIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ export default function TokenIcon({ denomination, ...props }: TokenIconProps) {
<Text
fontFamily={"meta"}
fontSize={"35px"}
color={"gray.900"}
color={props.color || "gray.900"}
>
{getCurrencyTokenCalt("NEAR")}
</Text>
<Text color={"gray.900"}>{denomination}</Text>
<Text color={props.color || "gray.900"}>{denomination}</Text>
</HStack>
);
}
Expand All @@ -34,7 +34,7 @@ export default function TokenIcon({ denomination, ...props }: TokenIconProps) {
alt="token"
src={metadata?.icon}
/>
<Text color={"gray.900"}>{metadata?.name}</Text>
<Text color={props.color || "gray.900"}>{metadata?.symbol}</Text>
</HStack>
) : null;
}
6 changes: 5 additions & 1 deletion front/pages/get-meta/TokenIcon/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { METAPOOL_CONTRACT_ID, METAPOOL_DEV_CONTRACT_ID, IS_PRODUCTION } from "../../../lib/near";
import { METAPOOL_CONTRACT_ID, METAPOOL_DEV_CONTRACT_ID, IS_PRODUCTION, META_CONTRACT_ID } from "../../../lib/near";
import { NativeCurrencies, NativeCurrency, TokenCalt, TokenNameCalt } from "./tokenIcon.types";
export const getCurrencyTokenCalt = (currency: NativeCurrency): TokenCalt => {
return TokenNameCalt[currency];
Expand All @@ -14,4 +14,8 @@ export const isNearDenomination = (denomination: any): boolean=> {

export const isStNearDenomination = (denomination: any) : boolean => {
return IS_PRODUCTION ? denomination == METAPOOL_CONTRACT_ID : denomination == METAPOOL_DEV_CONTRACT_ID;
}

export const isMetaDenomination = (denomination: any) : boolean => {
return denomination == META_CONTRACT_ID;
}
Loading