-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
20 changed files
with
10,910 additions
and
54 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
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,20 @@ | ||
#!/bin/sh | ||
|
||
# use provided source path or a default | ||
DUALITY_CORE_DIRECTORY="${1:-"../duality"}" | ||
|
||
# copy type files | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/module/types" \ | ||
"src/lib/web3/generated/duality/duality.duality/module" | ||
|
||
# copy REST API file | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/module/rest.ts" \ | ||
"src/lib/web3/generated/duality/duality.duality/module/rest.ts" | ||
|
||
# copy version info | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/duality/duality.duality/package.json" \ | ||
"src/lib/web3/generated/duality/duality.duality/package.json" | ||
|
||
# copy readme info | ||
cp -r "$DUALITY_CORE_DIRECTORY/vue/src/store/generated/readme.md" \ | ||
"src/lib/web3/generated/readme.md" |
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,72 @@ | ||
// This file is modified from an original generated/duality/duality.duality/module/index.ts file | ||
// | ||
// This file will not auto generate changes: | ||
// if new Msgs are created they should be added to the txClient below | ||
|
||
import { StdFee } from '@cosmjs/launchpad'; | ||
import { defaultRegistryTypes, SigningStargateClient } from '@cosmjs/stargate'; | ||
import { Registry, OfflineSigner, EncodeObject } from '@cosmjs/proto-signing'; | ||
import { Api } from './generated/duality/duality.duality/module/rest'; | ||
import { | ||
MsgWithdrawShares, | ||
MsgDepositShares, | ||
} from './generated/duality/duality.duality/module/types/duality/tx'; | ||
|
||
const { REACT_APP__RPC_API = '', REACT_APP__REST_API = '' } = process.env; | ||
|
||
export const MissingWalletError = new Error('wallet is required'); | ||
|
||
export const registry = new Registry(defaultRegistryTypes); | ||
|
||
// -----> register our Msgs here | ||
registry.register('/duality.duality.MsgDepositShares', MsgDepositShares); | ||
registry.register('/duality.duality.MsgWithdrawShares', MsgWithdrawShares); | ||
|
||
interface TxClientOptions { | ||
addr?: string; | ||
} | ||
|
||
interface SignAndBroadcastOptions { | ||
fee?: StdFee | 'auto' | number; | ||
memo?: string; | ||
} | ||
|
||
const txClient = async ( | ||
wallet: OfflineSigner, | ||
{ addr = REACT_APP__RPC_API }: TxClientOptions = {} | ||
) => { | ||
if (!wallet) throw MissingWalletError; | ||
const client = addr | ||
? await SigningStargateClient.connectWithSigner(addr, wallet, { registry }) | ||
: await SigningStargateClient.offline(wallet, { registry }); | ||
const { address } = (await wallet.getAccounts())[0]; | ||
|
||
return { | ||
signAndBroadcast: ( | ||
msgs: EncodeObject[], | ||
{ fee = 'auto', memo }: SignAndBroadcastOptions = {} | ||
) => client.signAndBroadcast(address, msgs, fee, memo), | ||
|
||
// -----> register our Msg client methods here | ||
msgWithdrawShares: (data: MsgWithdrawShares): EncodeObject => ({ | ||
typeUrl: '/duality.duality.MsgWithdrawShares', | ||
value: MsgWithdrawShares.fromPartial(data), | ||
}), | ||
msgDepositShares: (data: MsgDepositShares): EncodeObject => ({ | ||
typeUrl: '/duality.duality.MsgDepositShares', | ||
value: MsgDepositShares.fromPartial(data), | ||
}), | ||
}; | ||
}; | ||
|
||
interface QueryClientOptions { | ||
addr?: string; | ||
} | ||
|
||
const queryClient = async ({ | ||
addr = REACT_APP__REST_API, | ||
}: QueryClientOptions = {}) => { | ||
return new Api({ baseUrl: addr }); | ||
}; | ||
|
||
export { txClient, queryClient }; |
Oops, something went wrong.