diff --git a/examples/erc20/Compound/cBAT.xml b/examples/erc20/DeFi/Compound/cBAT.xml similarity index 99% rename from examples/erc20/Compound/cBAT.xml rename to examples/erc20/DeFi/Compound/cBAT.xml index 8ae3d332..450584a8 100644 --- a/examples/erc20/Compound/cBAT.xml +++ b/examples/erc20/DeFi/Compound/cBAT.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/Compound/cDAI.xml b/examples/erc20/DeFi/Compound/cDAI.xml similarity index 99% rename from examples/erc20/Compound/cDAI.xml rename to examples/erc20/DeFi/Compound/cDAI.xml index 023b02c7..436254b9 100644 --- a/examples/erc20/Compound/cDAI.xml +++ b/examples/erc20/DeFi/Compound/cDAI.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/Compound/cETH.xml b/examples/erc20/DeFi/Compound/cETH.xml similarity index 98% rename from examples/erc20/Compound/cETH.xml rename to examples/erc20/DeFi/Compound/cETH.xml index 18f7e239..2cd38448 100644 --- a/examples/erc20/Compound/cETH.xml +++ b/examples/erc20/DeFi/Compound/cETH.xml @@ -1,6 +1,6 @@ + ]> diff --git a/examples/erc20/Compound/cREP.xml b/examples/erc20/DeFi/Compound/cREP.xml similarity index 99% rename from examples/erc20/Compound/cREP.xml rename to examples/erc20/DeFi/Compound/cREP.xml index e64b2423..8b969579 100644 --- a/examples/erc20/Compound/cREP.xml +++ b/examples/erc20/DeFi/Compound/cREP.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/Compound/cUSDC.xml b/examples/erc20/DeFi/Compound/cUSDC.xml similarity index 99% rename from examples/erc20/Compound/cUSDC.xml rename to examples/erc20/DeFi/Compound/cUSDC.xml index a4ca35c5..41c061a7 100644 --- a/examples/erc20/Compound/cUSDC.xml +++ b/examples/erc20/DeFi/Compound/cUSDC.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/Compound/cWBTC.xml b/examples/erc20/DeFi/Compound/cWBTC.xml similarity index 99% rename from examples/erc20/Compound/cWBTC.xml rename to examples/erc20/DeFi/Compound/cWBTC.xml index 4752b9a4..887d8183 100644 --- a/examples/erc20/Compound/cWBTC.xml +++ b/examples/erc20/DeFi/Compound/cWBTC.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/Compound/cZRX.xml b/examples/erc20/DeFi/Compound/cZRX.xml similarity index 99% rename from examples/erc20/Compound/cZRX.xml rename to examples/erc20/DeFi/Compound/cZRX.xml index 9d2acdbb..52a661e5 100644 --- a/examples/erc20/Compound/cZRX.xml +++ b/examples/erc20/DeFi/Compound/cZRX.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/Compound/enable.en.shtml b/examples/erc20/DeFi/Compound/enable.en.shtml similarity index 99% rename from examples/erc20/Compound/enable.en.shtml rename to examples/erc20/DeFi/Compound/enable.en.shtml index 67232b34..d6c010f9 100644 --- a/examples/erc20/Compound/enable.en.shtml +++ b/examples/erc20/DeFi/Compound/enable.en.shtml @@ -9,6 +9,7 @@ class Token { let message = ""; if(this.props.allowance > 0) { message = "Compound " + this.props.name + " is already enabled"; + window.onConfirm = function() { window.close(); } } else { message = "Please enable compound " + this.props.name + " before supplying or withdrawing"; } diff --git a/examples/erc20/Compound/supply.en.shtml b/examples/erc20/DeFi/Compound/supply.en.shtml similarity index 50% rename from examples/erc20/Compound/supply.en.shtml rename to examples/erc20/DeFi/Compound/supply.en.shtml index 1e688bb5..f8130d75 100644 --- a/examples/erc20/Compound/supply.en.shtml +++ b/examples/erc20/DeFi/Compound/supply.en.shtml @@ -3,6 +3,22 @@ class Token { constructor(tokenInstance) { this.props = tokenInstance; + this.props.underlyingToken = this.props.name.replace("c", ""); + } + + mustEnableFirstPage(APR, cTokenBalance, tokenBalance) { + window.onConfirm = function() { window.close() }; + return` +
+
+ +

${this.props.name} Balance: ${cTokenBalance}

+

${this.props.underlyingToken} Balance: ${tokenBalance}

+

Interest Rate: ${APR}%

+

You must enable compound before you can supply ${this.props.underlyingToken}

+
+
+`; } render() { @@ -13,16 +29,23 @@ class Token { let interestRatePerBlock = this.props.supplyInterestRate; const averageBlocksPerYear = 2102400; let APR = (((interestRatePerBlock * averageBlocksPerYear) / decimals18) * 100).toFixed(2); + try { + if(this.props.allowance <= 0) { + return this.mustEnableFirstPage(APR, cTokenBalance, tokenBalance); + } + } catch { + //this would hit if it is cETH which does not have this requirement and so does not have the allowance attribute + } return`

${this.props.name} Balance: ${cTokenBalance}

-

${this.props.name.replace("c", "")} Balance: ${tokenBalance}

+

${this.props.underlyingToken} Balance: ${tokenBalance}

Interest Rate: ${APR}%

-

Supply ${this.props.name.replace("c", "")} to Compound

+

Supply ${this.props.underlyingToken} to Compound

diff --git a/examples/erc20/Compound/withdraw.en.shtml b/examples/erc20/DeFi/Compound/withdraw.en.shtml similarity index 50% rename from examples/erc20/Compound/withdraw.en.shtml rename to examples/erc20/DeFi/Compound/withdraw.en.shtml index ec134632..f5d8b1c9 100644 --- a/examples/erc20/Compound/withdraw.en.shtml +++ b/examples/erc20/DeFi/Compound/withdraw.en.shtml @@ -13,6 +13,22 @@ class Token { constructor(tokenInstance) { this.props = tokenInstance; + this.props.underlyingToken = this.props.name.replace("c", ""); + } + + mustEnableFirstPage(APR, cTokenBalance, tokenBalance) { + window.onConfirm = function() { window.close() }; + return` +
+
+ +

${this.props.name} Balance: ${cTokenBalance}

+

${this.props.underlyingToken} Balance: ${tokenBalance}

+

Interest Rate: ${APR}%

+

You must enable compound before you can withdraw ${this.props.underlyingToken}

+
+
+`; } render() { @@ -23,16 +39,23 @@ class Token { let interestRatePerBlock = this.props.supplyInterestRate; const averageBlocksPerYear = 2102400; let APR = (((interestRatePerBlock * averageBlocksPerYear) / decimals18) * 100).toFixed(2); + try { + if(this.props.allowance <= 0) { + return this.mustEnableFirstPage(APR, cTokenBalance, tokenBalance); + } + } catch { + //this would hit if it is cETH which does not have this requirement and so does not have the allowance attribute + } return`

${this.props.name} Balance: ${cTokenBalance}

-

${this.props.name.replace("c", "")} Balance: ${tokenBalance}

+

${this.props.underlyingToken} Balance: ${tokenBalance}

Interest Rate: ${APR}%

-

Withdraw ${this.props.name} for ${this.props.name.replace("c", "")} from Compound

+

Withdraw ${this.props.name} for ${this.props.underlyingToken} from Compound

diff --git a/examples/erc20/Compound/Makefile b/examples/erc20/DeFi/Makefile similarity index 100% rename from examples/erc20/Compound/Makefile rename to examples/erc20/DeFi/Makefile diff --git a/examples/erc20/iDAI/enable.en.shtml b/examples/erc20/DeFi/iDAI/enable.en.shtml similarity index 99% rename from examples/erc20/iDAI/enable.en.shtml rename to examples/erc20/DeFi/iDAI/enable.en.shtml index ed8356f5..0b9985f0 100644 --- a/examples/erc20/iDAI/enable.en.shtml +++ b/examples/erc20/DeFi/iDAI/enable.en.shtml @@ -8,7 +8,8 @@ class Token { render() { let message = ""; if(this.props.allowance > 0) { - message = "iDAI is already enabled, no need to click confirm"; + message = "iDAI is already enabled"; + window.onConfirm = function() { window.close(); } } else { message = "Please enable iDAI by clicking confirm"; } diff --git a/examples/erc20/iDAI/iDAI.xml b/examples/erc20/DeFi/iDAI/iDAI.xml similarity index 99% rename from examples/erc20/iDAI/iDAI.xml rename to examples/erc20/DeFi/iDAI/iDAI.xml index 2024411c..a953d7ea 100644 --- a/examples/erc20/iDAI/iDAI.xml +++ b/examples/erc20/DeFi/iDAI/iDAI.xml @@ -1,6 +1,6 @@ + diff --git a/examples/erc20/DeFi/iDAI/supply.en.shtml b/examples/erc20/DeFi/iDAI/supply.en.shtml new file mode 100644 index 00000000..733e93aa --- /dev/null +++ b/examples/erc20/DeFi/iDAI/supply.en.shtml @@ -0,0 +1,56 @@ + +
diff --git a/examples/erc20/iDAI/withdraw.en.shtml b/examples/erc20/DeFi/iDAI/withdraw.en.shtml similarity index 50% rename from examples/erc20/iDAI/withdraw.en.shtml rename to examples/erc20/DeFi/iDAI/withdraw.en.shtml index 18737976..3f362793 100644 --- a/examples/erc20/iDAI/withdraw.en.shtml +++ b/examples/erc20/DeFi/iDAI/withdraw.en.shtml @@ -3,6 +3,22 @@ class Token { constructor(tokenInstance) { this.props = tokenInstance; + this.props.underlyingToken = this.props.name.replace("bZx i", ""); + } + + mustEnableFirstPage(APR, iTokenBalance, tokenBalance) { + window.onConfirm = function() { window.close() }; + return` +
+
+ +

${this.props.name} Balance: ${iTokenBalance}

+

${this.props.underlyingToken} Balance: ${tokenBalance}

+

Interest Rate: ${APR}%

+

You must enable iDAI before you can withdraw

+
+
+`; } render() { @@ -10,12 +26,15 @@ class Token { let iTokenBalance = (this.props.iTokenBalance / decimals18).toFixed(2); let tokenBalance = (this.props.tokenBalance / decimals18).toFixed(2); let APR = (this.props.interestRateSupply / decimals18).toFixed(2); - return` + if(this.props.allowance <= 0) { + return this.mustEnableFirstPage(APR, iTokenBalance, tokenBalance); + } else { + return`

${this.props.name} Balance: ${iTokenBalance}

-

${this.props.name.replace("bZx i", "")} Balance: ${tokenBalance}

+

${this.props.underlyingToken} Balance: ${tokenBalance}

Interest Rate: ${APR}%

@@ -23,6 +42,7 @@ class Token {
`; + } } } diff --git a/examples/erc20/Compound/shared.css b/examples/erc20/DeFi/shared.css similarity index 100% rename from examples/erc20/Compound/shared.css rename to examples/erc20/DeFi/shared.css diff --git a/examples/erc20/iDAI/Makefile b/examples/erc20/iDAI/Makefile deleted file mode 100644 index 5cc1c2e3..00000000 --- a/examples/erc20/iDAI/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -XMLSECTOOL=xmlsectool -KEYSTORE= -KEY=1 -KEYPASSWORD= -SIGNATURE_ALGORITHM=rsa-sha256 - -help: - # Needs a target, example: $$ make EntryToken.canonicalized.xml - # - # Let's say you have a TokenScript "EntryToken.xml" - #- to validate and canonicalize, add 'canonicalized' in the filename - @echo $$ make EntryToken.canonicalized.xml - # - to sign, use tsml as file extension: - @echo $$ make EntryToken.tsml - -%.canonicalized.xml : %.xml - # xmlsectool canonicalises automatically when needed, but leaving an xml:base attribute which creates trouble later. - # xmlstarlet does it neatly - # XML Canonicalization - xmlstarlet c14n $^ > $@ - # xmlsectool validates too, albeit adding xml:base with breaks schema. Example: - # JVMOPTS=-Djavax.xml.accessExternalDTD=all /opt/xmlsectool-2.0.0/xmlsectool.sh --validateSchema --xsd --schemaDirectory ../../schema --inFile $^ - # XML Validation - # if INVALID, run validation again with xmllint to get meaningful error - # then delete the canonicalized file - -xmlstarlet val --xsd http://tokenscript.org/2019/05/tokenscript/tokenscript.xsd $@ || (mv $@ $@.INVALID; xmllint --noout --schema http://tokenscript.org/2019/05/tokenscript/tokenscript.xsd $@.INVALID) - -%.tsml: %.canonicalized.xml -ifeq (,$(KEYSTORE)) - @echo ---------------- Keystore missing. Try this ---------------- - @echo $$ make KEYSTORE=shong.wang.p12 KEYPASSWORD=shong.wang $@ - @echo replace it with your .p12 file and your password - rm $^ -else - $(XMLSECTOOL) --sign --keyInfoKeyName 'AlphaWallet' --digest SHA-256 --signatureAlgorithm http://www.w3.org/2001/04/xmldsig-more#$(SIGNATURE_ALGORITHM) --inFile $^ --outFile $@ --keystore $(KEYSTORE) --keystoreType PKCS12 --key $(KEY) --keyPassword $(KEYPASSWORD) --signaturePosition LAST - # removing the canonicalized created for validation - rm $^ -endif diff --git a/examples/erc20/iDAI/shared.css b/examples/erc20/iDAI/shared.css deleted file mode 100644 index 64f1a1e5..00000000 --- a/examples/erc20/iDAI/shared.css +++ /dev/null @@ -1,98 +0,0 @@ -h3 { color: #111; font-family: 'Open Sans', sans-serif; font-size: 20px; font-weight: 300; line-height: 32px; } - -#inputBox { - text-align: center; -} - -html, -body { - height: 100%; -} -html { - font-size: 14px; -} -body { - margin: 0px; - padding: 0px; - overflow-x: hidden; - min-width: 320px; - background: #FFFFFF; - font-family: 'Lato', 'Helvetica Neue', Arial, Helvetica, sans-serif; - font-size: 14px; - line-height: 1.4285em; - color: rgba(0, 0, 0, 0.87); - font-smoothing: antialiased; -} -.ui.container { - display: block; - max-width: 100% !important; -} -@media only screen and (max-width: 767px) { - .ui.container { - width: auto !important; - margin-left: 1em !important; - margin-right: 1em !important; - } -} -@media only screen and (min-width: 768px) and (max-width: 991px) { - .ui.container { - width: 723px; - margin-left: auto !important; - margin-right: auto !important; - } -} -@media only screen and (min-width: 992px) and (max-width: 1199px) { - .ui.container { - width: 933px; - margin-left: auto !important; - margin-right: auto !important; - } -} -@media only screen and (min-width: 1200px) { - .ui.container { - width: 1127px; - margin-left: auto !important; - margin-right: auto !important; - } -} -.ui.segment { - position: relative; - background: #FFFFFF; - -webkit-box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15); - box-shadow: 0px 1px 2px 0 rgba(34, 36, 38, 0.15); - margin: 0.5rem 0em; - padding: 0.5em 0.5em; - border-radius: 0.28571429rem; - border: 1px solid rgba(34, 36, 38, 0.15); - text-align: center; -} -.ui.segment:first-child { - margin-top: 0em; -} -.ui.segment:last-child { - margin-bottom: 0em; -} -input { - position: relative; - font-weight: normal; - font-style: normal; - font-size: 12px; - display: -ms-inline-flexbox; - display: inline-flex; - color: rgba(0, 0, 0, 0.87); - padding: 9.5px 14px; - width: 300px; - border-color: #D8D8D8; -} -input[type=text]:focus { - border-color: #D8D8D8; - background: #FAFAFA; - color: rgba(0, 0, 0, 0.87); - -webkit-box-shadow: none; - box-shadow: none; -} -label { - font-size: 12px; - font-weight: 500; - margin-top: 6px; -} \ No newline at end of file diff --git a/examples/erc20/iDAI/supply.en.shtml b/examples/erc20/iDAI/supply.en.shtml deleted file mode 100644 index 7112dd4c..00000000 --- a/examples/erc20/iDAI/supply.en.shtml +++ /dev/null @@ -1,36 +0,0 @@ - -