From 593a6efbe78d4c641590fa2cbf6fae68d8fca1ab Mon Sep 17 00:00:00 2001 From: Lorexia Date: Sun, 1 Oct 2023 17:00:06 +0200 Subject: [PATCH] update mixfetch, cosmoskit examples --- .../docs/pages/guides/cosmos-kit.mdx | 49 ++++++++++++++++--- .../docs/pages/guides/mix-fetch.mdx | 6 +-- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/sdk/typescript/docs/pages/guides/cosmos-kit.mdx b/sdk/typescript/docs/pages/guides/cosmos-kit.mdx index dbbe010422..a90a3e8182 100644 --- a/sdk/typescript/docs/pages/guides/cosmos-kit.mdx +++ b/sdk/typescript/docs/pages/guides/cosmos-kit.mdx @@ -55,8 +55,32 @@ import { ChainProvider, useChain } from '@cosmos-kit/react'; import { assets, chains } from 'chain-registry'; import { wallets as ledger } from '@cosmos-kit/ledger'; import { wallets as keplr } from '@cosmos-kit/keplr'; +import { AminoMsg, makeSignDoc } from '@cosmjs/amino'; +import { MsgSend } from 'cosmjs-types/cosmos/bank/v1beta1/tx'; + +export const getDoc = (address: string) => { + const chainId = 'nyx'; + const msg: AminoMsg = { + type: '/cosmos.bank.v1beta1.MsgSend', + value: MsgSend.fromPartial({ + fromAddress: address, + toAddress: 'n1nn8tghp94n8utsgyg3kfttlxm0exgjrsqkuwu9', + amount: [{ amount: '1000', denom: 'unym' }], + }), + }; + const fee = { + amount: [{ amount: '2000', denom: 'ucosm' }], + gas: '180000', // 180k + }; + const memo = 'Use your power wisely'; + const accountNumber = 15; + const sequence = 16; + const doc = makeSignDoc([msg], fee, chainId, memo, accountNumber, sequence); + return doc +}; + function MyComponent() { - const {wallet, address, connect, getOfflineSignerDirect } = + const {wallet, address, connect, getOfflineSignerAmino } = useChain('nyx'); React.useEffect(() => { @@ -64,8 +88,9 @@ function MyComponent() { }, []); const sign = async () => { - const doc = {foo: 'bar'}; - return getOfflineSignerDirect().signDirect(address, doc); + if (!address) return + const doc = getDoc(address); + return getOfflineSignerAmino().signAmino(address, doc); }; return ( @@ -77,17 +102,28 @@ function MyComponent() { { wallet &&
Address: {address}
} - {address && } ); } export default function App() { + const assetsFixedUp = React.useMemo(() => { + const nyx = assets.find((a) => a.chain_name === 'nyx'); + if (nyx) { + const nyxCoin = nyx.assets.find((a) => a.name === 'nyx'); + if (nyxCoin) { + nyxCoin.coingecko_id = 'nyx'; + } + nyx.assets = nyx.assets.reverse(); + } + return assets; + }, [assets]); + return ( c.chain_id === 'nyx')]} - assetLists={[assets.find((a) => a.chain_name === 'nyx')]} + chains={[chains.find((c) => c.chain_id === 'nyx')!]} + assetLists={assetsFixedUp} wallets={[...ledger, ...keplr]} signerOptions={{ preferredSignType: () => 'amino', @@ -99,4 +135,5 @@ export default function App() { ) } + ``` diff --git a/sdk/typescript/docs/pages/guides/mix-fetch.mdx b/sdk/typescript/docs/pages/guides/mix-fetch.mdx index c514c3a6f6..3bfec67f34 100644 --- a/sdk/typescript/docs/pages/guides/mix-fetch.mdx +++ b/sdk/typescript/docs/pages/guides/mix-fetch.mdx @@ -136,11 +136,10 @@ export function HttpGET() { export function HttpPOST() { async function post () { - const apiResponse = await mixFetch('https://api.example.com', { + const apiResponse = await mixFetch('https://postman-echo.com/post', { method: 'POST', - mode: 'unsafe-ignore-cors', body: JSON.stringify({ foo: 'bar' }), - headers: { [`Content-Type`]: 'application/json', Authorization: `Bearer ${process.env.AUTH_TOKEN}` } + headers: { 'Content-Type': 'application/json' } }, mixFetchOptions) console.log(apiResponse) } @@ -159,6 +158,5 @@ export default function App() { ) } - ```