update WebUI for testnet

This commit is contained in:
Hendrik Hofstadt 2020-12-09 15:49:37 +01:00
parent 2c8b411a6b
commit ba8f4355d5
6 changed files with 42 additions and 30 deletions

View File

@ -12,12 +12,13 @@ import WalletContext from '../providers/WalletContext';
import Wallet from "@project-serum/sol-wallet-adapter";
import {BridgeProvider} from "../providers/BridgeContext";
import Assistant from "../pages/Assistant";
import {SOLANA_HOST} from "../config";
const {Header, Content, Footer} = Layout;
function App() {
let c = new solanaWeb3.Connection("http://localhost:8899");
const wallet = useMemo(() => new Wallet("https://www.sollet.io", "http://localhost:8899"), []);
let c = new solanaWeb3.Connection(SOLANA_HOST);
const wallet = useMemo(() => new Wallet("https://www.sollet.io", SOLANA_HOST), []);
const [, setConnected] = useState(false);
useEffect(() => {
wallet.on('connect', () => {

View File

@ -239,7 +239,7 @@ export default function TransferInitiator(params: TransferInitiatorParams) {
<Form.Item label="Amount" name="layout"
validateStatus={amountValid ? "success" : "error"}>
<Input type={"number"} placeholder={"Amount"}
addonAfter={`Balance: ${coinInfo.balance.div(Math.pow(10, coinInfo.decimals))}`}
addonAfter={`Balance: ${coinInfo.balance.div(new BigNumber(10).pow(coinInfo.decimals))}`}
onChange={(v) => {
if (v.target.value === "") {
setAmount(new BigNumber(0));
@ -282,7 +282,6 @@ export default function TransferInitiator(params: TransferInitiatorParams) {
content: (<>This will create a new token account for the
token: <code>{wrappedMint}</code></>),
onOk() {
console.log(coinInfo.decimals)
createWrapped(c, bridge, k, {
chain: coinInfo.chainID,
address: coinInfo.assetAddress,
@ -290,7 +289,6 @@ export default function TransferInitiator(params: TransferInitiatorParams) {
}, new PublicKey(wrappedMint))
},
onCancel() {
console.log('Cancel');
},
})
}}>+</Button>

View File

@ -43,8 +43,14 @@ function TransferProposals() {
let c = useContext(ClientContext);
let [lockups, setLockups] = useState<LockupWithStatus[]>([])
let [lastUpdate, setLastUpdate] = useState(0);
useEffect(() => {
if (s - lastUpdate <= 16) {
return
}
setLastUpdate(s);
let updateLockups = async () => {
let lockups: LockupWithStatus[] = [];
for (let account of tokens.balances) {

View File

@ -1,13 +1,13 @@
import {PublicKey} from "@solana/web3.js";
const BRIDGE_ADDRESS = "0x5b1869D9A4C187F2EAa108f3062412ecf0526b24";
const WRAPPED_MASTER = "e78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab"
const BRIDGE_ADDRESS = "0xdae0Cba01eFc4bfEc1F7Fece73Fe8b8d2Eda65B0";
const WRAPPED_MASTER = "9f7bedd9ef2d57eccab2cb56a5bd395edbb77df8"
const SOLANA_BRIDGE_PROGRAM = new PublicKey("Bridge1p5gheXUvJ6jGWGeCsgPKgnE3YgdGKRVCMY9o");
const SOLANA_BRIDGE_PROGRAM = new PublicKey("BrdgiFmZN3BKkcY3danbPYyxPKwb8RhQzpM2VY5L97ED");
const TOKEN_PROGRAM = new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
const SOLANA_HOST = "http://localhost:8899";
const SOLANA_HOST = "https://testnet.solana.com";
export {
BRIDGE_ADDRESS,

View File

@ -36,32 +36,38 @@ export const SolanaTokenProvider: FunctionComponent = ({children}) => {
let [loading, setLoading] = useState(true)
let [balances, setBalances] = useState<Array<BalanceInfo>>([]);
let [lastUpdate, setLastUpdate] = useState(0);
useEffect(() => {
if (slot - lastUpdate <= 16) {
return
}
setLastUpdate(slot);
// @ts-ignore
setLoading(true)
let getAccounts = async () => {
let res: RpcResponseAndContext<Array<{ pubkey: PublicKey; account: AccountInfo<ParsedAccountData> }>> = await c.getParsedTokenAccountsByOwner(k.publicKey, {programId: TOKEN_PROGRAM}, "single")
let meta: AssetMeta[] = [];
for (let acc of res.value) {
let am = await b?.fetchAssetMeta(new PublicKey(acc.account.data.parsed.info.mint))
if (!am) {
throw new Error("could not derive asset meta")
}
am.decimals = acc.account.data.parsed.info.tokenAmount.decimals;
meta.push(am)
let res: RpcResponseAndContext<Array<{ pubkey: PublicKey; account: AccountInfo<ParsedAccountData> }>> = await c.getParsedTokenAccountsByOwner(k.publicKey, {programId: TOKEN_PROGRAM}, "single")
let meta: AssetMeta[] = [];
for (let acc of res.value) {
let am = await b?.fetchAssetMeta(new PublicKey(acc.account.data.parsed.info.mint))
if (!am) {
throw new Error("could not derive asset meta")
}
let balances: Array<BalanceInfo> = await res.value.map((v, i) => {
return {
mint: v.account.data.parsed.info.mint,
account: v.pubkey,
balance: new BigNumber(v.account.data.parsed.info.tokenAmount.amount),
decimals: v.account.data.parsed.info.tokenAmount.decimals,
assetMeta: meta[i],
}
})
setBalances(balances)
setLoading(false)
am.decimals = acc.account.data.parsed.info.tokenAmount.decimals;
meta.push(am)
}
let balances: Array<BalanceInfo> = await res.value.map((v, i) => {
return {
mint: v.account.data.parsed.info.mint,
account: v.pubkey,
balance: new BigNumber(v.account.data.parsed.info.tokenAmount.amount),
decimals: v.account.data.parsed.info.tokenAmount.decimals,
assetMeta: meta[i],
}
})
setBalances(balances)
setLoading(false)
}
getAccounts();

View File

@ -289,7 +289,8 @@ class SolanaBridge {
let accounts: Lockup[] = [];
for (let acc of raw_accounts) {
accounts.push(this.parseLockup(acc.pubkey, bs58.decode(acc.account.data)))
let pubkey = new PublicKey(acc.pubkey)
accounts.push(this.parseLockup(pubkey, bs58.decode(acc.account.data)))
}
return accounts