-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from bandprotocol/feat/integrate-cosmostation…
…-wallet Integrate cosmostation wallet
- Loading branch information
Showing
16 changed files
with
250 additions
and
129 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
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 |
---|---|---|
@@ -1,134 +1,99 @@ | ||
module Cosmos = { | ||
type requestAccountResponse = { | ||
address: string, | ||
publicKey: array<int>, | ||
name: string, | ||
isLedger: bool, | ||
} | ||
type t = {} | ||
|
||
type amount = { | ||
denom: string, | ||
amount: string, | ||
} | ||
|
||
type fee = { | ||
amount: array<amount>, | ||
gas: string, | ||
} | ||
|
||
type signAminoDoc = { | ||
chain_id: string, | ||
sequence: string, | ||
account_number: string, | ||
fee: fee, | ||
memo: string, | ||
msgs: array<Js.Json.t>, | ||
} | ||
|
||
type signAminoResponse = { | ||
signature: string, | ||
pub_key: {"type": string, "value": string}, | ||
signed_doc: signAminoDoc, | ||
} | ||
|
||
type signDirectDoc = { | ||
chain_id: string, | ||
body_bytes: array<int>, | ||
auth_info_bytes: array<int>, | ||
account_number: string, | ||
} | ||
|
||
type signDirectResponse = { | ||
signature: string, | ||
pub_key: {"type": string, "value": string}, | ||
signed_doc: signDirectDoc, | ||
} | ||
|
||
type gasRateType = { | ||
tiny: string, | ||
low: string, | ||
average: string, | ||
} | ||
type amount = { | ||
denom: string, | ||
amount: string, | ||
} | ||
|
||
type signOptions = { | ||
memo?: bool, | ||
fee?: bool, | ||
gasRate?: gasRateType, | ||
} | ||
type fee = { | ||
amount: array<amount>, | ||
gas: string, | ||
} | ||
|
||
type supportedChainNamesResponse = { | ||
official: array<string>, | ||
unofficial: array<string>, | ||
} | ||
type sign_amino_doc_t = { | ||
chain_id: string, | ||
sequence: string, | ||
account_number: string, | ||
fee: fee, | ||
memo: string, | ||
msgs: array<Js.Json.t>, | ||
} | ||
|
||
type addChainParams = { | ||
chainId: string, | ||
chainName: string, | ||
restURL: string, | ||
imageURL?: string, | ||
baseDenom: string, | ||
displayDenom: string, | ||
decimals?: float, | ||
coinType?: string, | ||
addressPrefix: string, | ||
coinGeckoId?: string, | ||
gasRate?: gasRateType, | ||
sendGas?: string, | ||
} | ||
type sign_amino_param_t = { | ||
chainName: string, | ||
doc: option<sign_amino_doc_t>, | ||
isEditFee: option<bool>, | ||
isEditMemo: option<bool>, | ||
} | ||
|
||
type t = { | ||
getAccount: string => Js.Promise.t<requestAccountResponse>, | ||
signDirect: (string, signDirectDoc, option<signOptions>) => Js.Promise.t<signDirectResponse>, | ||
signAmino: (string, signAminoDoc, option<signOptions>) => Js.Promise.t<signAminoResponse>, | ||
} | ||
type request_account_response_t = { | ||
address: string, | ||
publicKey: array<int>, | ||
name: string, | ||
isLedger: bool, | ||
isEthermint: bool, | ||
} | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external getSupportedChains: string => Js.Promise.t<supportedChainNamesResponse> = | ||
"getSupportedChains" | ||
type sign_amino_response_t = { | ||
signature: string, | ||
pub_key: {"type": string, "value": string}, | ||
signed_doc: sign_amino_doc_t, | ||
} | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external getActivatedChains: string => Js.Promise.t<array<string>> = "getActivatedChains" | ||
type request_t = { | ||
method: string, | ||
params: sign_amino_param_t, | ||
} | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external addChain: addChainParams => Js.Promise.t<array<string>> = "addChain" | ||
type sign_response_t = {signature: string} | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external getAccount: string => Js.Promise.t<requestAccountResponse> = "getAccount" | ||
@val @scope("window") | ||
external cosmostation: option<t> = "cosmostation" | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external signDirect: ( | ||
string, | ||
signDirectDoc, | ||
option<signOptions>, | ||
) => Js.Promise.t<signDirectResponse> = "signDirect" | ||
@val @scope(("window", "cosmostation", "cosmos")) | ||
external request: 'a => Js.Promise.t<'b> = "request" | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external signAmino: ( | ||
string, | ||
signAminoDoc, | ||
option<signOptions>, | ||
) => Js.Promise.t<signAminoResponse> = "signAmino" | ||
let requestAccount = async (chainName: string) => { | ||
let acc: request_account_response_t = await request({ | ||
method: "cos_requestAccount", | ||
params: { | ||
chainName, | ||
doc: None, | ||
isEditFee: None, | ||
isEditMemo: None, | ||
}, | ||
}) | ||
|
||
@module("@cosmostation/extension-client/cosmos") | ||
external disconnect: unit => Js.Promise.t<unit> = "disconnect" | ||
acc | ||
} | ||
|
||
let getAminoSignDocFromTx = (tx: BandChainJS.Transaction.transaction_t) => { | ||
account_number: tx.accountNum->Belt.Option.getExn->Belt.Int.toString, | ||
chain_id: tx.chainId->Belt.Option.getExn, | ||
fee: { | ||
amount: tx.fee | ||
->BandChainJS.Fee.getAmountList | ||
->Belt.Array.map(coin => { | ||
amount: coin->BandChainJS.Coin.getAmount, | ||
denom: coin->BandChainJS.Coin.getDenom, | ||
}), | ||
gas: tx.fee->BandChainJS.Fee.getGasLimit->Belt.Int.toString, | ||
let signAmino = async (chainName: string, doc: sign_amino_doc_t) => { | ||
let response: sign_amino_response_t = await request({ | ||
method: "cos_signAmino", | ||
params: { | ||
chainName, | ||
doc: Some(doc), | ||
isEditFee: Some(false), | ||
isEditMemo: Some(false), | ||
}, | ||
memo: tx.memo, | ||
msgs: tx.msgs->Belt.Array.map(msg => msg->BandChainJS.Message.MsgSend.toJSON), | ||
sequence: tx.sequence->Belt.Option.getExn->Belt.Int.toString, | ||
} | ||
}) | ||
|
||
response | ||
} | ||
|
||
@module("@cosmostation/extension-client") | ||
external cosmos: unit => Js.Promise.t<Cosmos.t> = "cosmos" | ||
let getAminoSignDocFromTx = (tx: BandChainJS.Transaction.transaction_t) => { | ||
account_number: tx.accountNum->Belt.Option.getExn->Belt.Int.toString, | ||
chain_id: tx.chainId->Belt.Option.getExn, | ||
fee: { | ||
amount: tx.fee | ||
->BandChainJS.Fee.getAmountList | ||
->Belt.Array.map(coin => { | ||
amount: coin->BandChainJS.Coin.getAmount, | ||
denom: coin->BandChainJS.Coin.getDenom, | ||
}), | ||
gas: tx.fee->BandChainJS.Fee.getGasLimit->Belt.Int.toString, | ||
}, | ||
memo: tx.memo, | ||
msgs: tx.msgs->Belt.Array.map(msg => msg->BandChainJS.Message.MsgSend.toJSON), | ||
sequence: tx.sequence->Belt.Option.getExn->Belt.Int.toString, | ||
} |
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
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
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
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,38 @@ | ||
module Styles = { | ||
open CssJs | ||
|
||
let container = (theme: Theme.t, isDarkMode) => | ||
style(. [ | ||
display(#flex), | ||
flexDirection(#column), | ||
justifyContent(#center), | ||
alignItems(#center), | ||
position(#relative), | ||
]) | ||
|
||
let icon = { | ||
style(. [width(#px(48)), height(#px(48))]) | ||
} | ||
} | ||
|
||
@react.component | ||
let make = () => { | ||
let ({ThemeContext.theme: theme, isDarkMode}, _) = React.useContext(ThemeContext.context) | ||
|
||
<div className={Styles.container(theme, isDarkMode)}> | ||
<img alt={`$wallet icon`} src={Images.cosmostation} className=Styles.icon /> | ||
<VSpacing size={#px(8)} /> | ||
<Heading size={H2} value="Cosmostation is not installed" /> | ||
<VSpacing size={#px(8)} /> | ||
<Text | ||
size={Body2} | ||
align={Center} | ||
value="If you have Cosmostation installed, refresh this page or follow your browser's instructions to connect your wallet." | ||
/> | ||
<VSpacing size={#px(24)} /> | ||
<LinkButton | ||
href="https://cosmostation.io/products/cosmostation_extension" fullWidth=true fsize=16> | ||
{"Install Cosmostation"->React.string} | ||
</LinkButton> | ||
</div> | ||
} |
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,30 @@ | ||
module Styles = { | ||
open CssJs | ||
|
||
let container = (theme: Theme.t, isDarkMode) => | ||
style(. [ | ||
display(#flex), | ||
flexDirection(#column), | ||
justifyContent(#center), | ||
alignItems(#center), | ||
position(#relative), | ||
]) | ||
|
||
let icon = { | ||
style(. [width(#px(48)), height(#px(48))]) | ||
} | ||
} | ||
|
||
@react.component | ||
let make = () => { | ||
let ({ThemeContext.theme: theme, isDarkMode}, _) = React.useContext(ThemeContext.context) | ||
let (_, _, accountError, _) = React.useContext(WalletPopupContext.context) | ||
|
||
<div className={Styles.container(theme, isDarkMode)}> | ||
<img alt="cosmostation icon" src={Images.fail} className=Styles.icon /> | ||
<VSpacing size={#px(8)} /> | ||
<Heading size={H2} value="Something Wrong" /> | ||
<VSpacing size={#px(8)} /> | ||
<Text size={Body2} align={Center} value=accountError /> | ||
</div> | ||
} |
Oops, something went wrong.