forked from leather-io/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add debug mode for transaction signing
- Loading branch information
Showing
86 changed files
with
3,416 additions
and
609 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 |
---|---|---|
|
@@ -11,4 +11,5 @@ dist/ | |
.rts2_cache_umd/ | ||
yarn-error.log | ||
.github/workflows/event.json | ||
.npmrc | ||
.npmrc | ||
coverage/ |
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,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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,57 @@ | ||
import { ContractCallArgument, ContractCallArgumentType } from '@blockstack/connect'; | ||
import { | ||
uintCV, | ||
intCV, | ||
falseCV, | ||
trueCV, | ||
contractPrincipalCV, | ||
standardPrincipalCV, | ||
bufferCV, | ||
} from '@blockstack/stacks-transactions'; | ||
import RPCClient from '@blockstack/rpc-client'; | ||
import BigNumber from 'bignumber.js'; | ||
|
||
export const encodeContractCallArgument = ({ type, value }: ContractCallArgument) => { | ||
switch (type) { | ||
case ContractCallArgumentType.UINT: | ||
return uintCV(value); | ||
case ContractCallArgumentType.INT: | ||
return intCV(value); | ||
case ContractCallArgumentType.BOOL: | ||
if (value === 'false' || value === '0') return falseCV(); | ||
else if (value === 'true' || value === '1') return trueCV(); | ||
else throw new Error(`Unexpected Clarity bool value: ${JSON.stringify(value)}`); | ||
case ContractCallArgumentType.PRINCIPAL: | ||
if (value.includes('.')) { | ||
const [addr, name] = value.split('.'); | ||
return contractPrincipalCV(addr, name); | ||
} else { | ||
return standardPrincipalCV(value); | ||
} | ||
case ContractCallArgumentType.BUFFER: | ||
return bufferCV(Buffer.from(value)); | ||
default: | ||
throw new Error(`Unexpected Clarity type: ${type}`); | ||
} | ||
}; | ||
|
||
export const getRPCClient = () => { | ||
const { origin } = location; | ||
const url = origin.includes('localhost') | ||
? 'http://localhost:3999' | ||
: 'https://sidecar.staging.blockstack.xyz'; | ||
return new RPCClient(url); | ||
}; | ||
|
||
export const stacksValue = ({ | ||
value, | ||
fixedDecimals = false, | ||
}: { | ||
value: number; | ||
fixedDecimals?: boolean; | ||
}) => { | ||
const microStacks = new BigNumber(value); | ||
const stacks = microStacks.shiftedBy(-6); | ||
const stxString = fixedDecimals ? stacks.toFormat(6) : stacks.decimalPlaces(6).toFormat(); | ||
return `${stxString} STX`; | ||
}; |
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
Oops, something went wrong.