-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add keplr wallet to help page #154
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bb69cd1
Add keplr to help page
giansalex c4013cf
Add wallet.js
giansalex c9fa518
Add txs endpoint
giansalex f19563d
Add keplr chain info
giansalex b0c697c
Add keplr guide link
giansalex a51ae3c
Fix issues
giansalex 178ed71
Update keplr gasprices
giansalex f8e118e
Use protojs tx
giansalex 5d09424
Revert "Add txs endpoint"
giansalex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,162 @@ | ||
var remote = "http://gno.land:36657", | ||
chainId = "testchain", | ||
walletFn = {keplr: {}}; | ||
|
||
walletFn.createVmCallMsg = function (sender, pkgPath, funcName, args) { | ||
return { | ||
type: "/vm.m_call", | ||
value: { | ||
caller: sender, | ||
send: "", | ||
pkg_path: pkgPath, | ||
func: funcName, | ||
args: args, | ||
} | ||
}; | ||
}; | ||
|
||
walletFn.createSignDoc = function(account, msg, chainId, gas) { | ||
return { | ||
msgs: [msg], | ||
fee: { amount: [{ | ||
amount: "1", | ||
denom: "gnot" | ||
}], gas: gas }, | ||
chain_id: chainId, | ||
memo: "", | ||
account_number: account.account_number, | ||
sequence: account.sequence, | ||
}; | ||
}; | ||
|
||
walletFn.keplr.signAndBroadcast = function(sender, msg) { | ||
return window.keplr.experimentalSuggestChain(walletFn.getTestnetKeplrConfig()) | ||
.then(function () { | ||
return window.keplr.enable(chainId); | ||
}) | ||
.then(function () { | ||
return walletFn.getAccount(sender); | ||
}) | ||
.then(function(account) { | ||
const signDoc = walletFn.createSignDoc(account, msg, chainId, "2000000"); | ||
return window.keplr.signAmino(chainId, sender, signDoc, { | ||
// use app fee (1gnot fixed fee) | ||
preferNoSetFee: true, | ||
}); | ||
}) | ||
.then(function (signature) { | ||
const tx = gnopb.makeProtoTx(signature.signed, signature.signature); | ||
return walletFn.broadcastTx(tx); | ||
}); | ||
}; | ||
|
||
walletFn.getTestnetKeplrConfig = function() { | ||
const addressPrefix = "g"; | ||
const gnoToken = { | ||
coinDenom: "GNOT", | ||
coinMinimalDenom: "gnot", | ||
coinDecimals: 6, | ||
// coinGeckoId: "" | ||
}; | ||
|
||
return { | ||
chainId: chainId, | ||
chainName: "GNO Testnet", | ||
rpc: 'http://gno.land:36657', | ||
rest: 'https://lcd.gno.tools', // source: https://github.com/disperze/gno-api | ||
bech32Config: { | ||
bech32PrefixAccAddr: `${addressPrefix}`, | ||
bech32PrefixAccPub: `${addressPrefix}pub`, | ||
bech32PrefixValAddr: `${addressPrefix}valoper`, | ||
bech32PrefixValPub: `${addressPrefix}valoperpub`, | ||
bech32PrefixConsAddr: `${addressPrefix}valcons`, | ||
bech32PrefixConsPub: `${addressPrefix}valconspub`, | ||
}, | ||
currencies: [gnoToken], | ||
feeCurrencies: [gnoToken], | ||
stakeCurrency: gnoToken, | ||
gasPriceStep: { | ||
low: 0.000000001, // min 1gnot for any tx | ||
average: 0.000000001, | ||
high: 0.000000001, | ||
}, | ||
bip44: { coinType: 118 }, | ||
// custom feature for GNO chains. | ||
features: ["gno"] | ||
}; | ||
}; | ||
|
||
walletFn.getAccount = function(address) { | ||
return walletFn.rpcCall("abci_query", {path: `auth/accounts/${address}`}) | ||
.then(function (data) { | ||
const response = data.result.response.ResponseBase; | ||
if (response.Error) { | ||
throw new Error(response.Log); | ||
} | ||
|
||
const account = JSON.parse(atob(response.Data)); | ||
if (!account) { | ||
throw new Error("Account not found"); | ||
} | ||
|
||
return account.BaseAccount; | ||
}); | ||
}; | ||
|
||
walletFn.broadcastTx = function(tx) { | ||
return walletFn.rpcCall("broadcast_tx_commit", {tx: walletFn.tob64(tx)}).then(function (data) { | ||
if (data.error) { | ||
throw new Error(data.error.message); | ||
} | ||
|
||
const checkTx = data.result.check_tx.ResponseBase; | ||
if (checkTx.Error) { | ||
throw new Error(checkTx.Log); | ||
} | ||
|
||
const deliverTx = data.result.deliver_tx.ResponseBase; | ||
if (deliverTx.Error) { | ||
throw new Error(deliverTx.Log); | ||
} | ||
|
||
return { | ||
height: data.result.height, | ||
txhash: walletFn.base64ToHex(data.result.hash), | ||
gasWanted: deliverTx.GasWanted, | ||
gasUsed: deliverTx.GasUsed, | ||
}; | ||
}); | ||
}; | ||
|
||
walletFn.tob64 = function(data) { | ||
return btoa(String.fromCharCode.apply(null, data)); | ||
}; | ||
|
||
walletFn.base64ToHex = function(data) { | ||
return atob(data) | ||
.split('') | ||
.map(function (c) { | ||
return ('0' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}) | ||
.join('') | ||
.toUpperCase(); | ||
} | ||
|
||
walletFn.rpcCall = function(method, params) { | ||
const payload = { | ||
"jsonrpc": "2.0", | ||
"method": method, | ||
"params": params, | ||
"id": 1 | ||
}; | ||
|
||
return fetch(remote, { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(payload) | ||
}).then(function (response) { | ||
return response.json(); | ||
}); | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL :)
where is this number coming from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from ATOM, I'm not sure if Jae wants to change that.