Skip to content

Commit

Permalink
A-1207636878260058: referral code support (#168)
Browse files Browse the repository at this point in the history
* A-1207636878260058: referral code support

* bump version

* cleanup console
  • Loading branch information
anyxem authored Jun 23, 2024
1 parent 6689311 commit ae7f848
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browser-extension",
"version": "1.2.6",
"version": "1.2.7",
"private": true,
"dependencies": {
"@mintlayer/entropy-generator": "^1.0.2",
Expand Down
5 changes: 4 additions & 1 deletion public/background-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ browser.runtime.onConnect.addListener((port) => {
setTimeout(async () => {
await browser.runtime.sendMessage({
action: 'createDelegate',
data: { pool_id: request.myProperty.message.pool_id },
data: {
pool_id: request.myProperty.message.pool_id,
referral_code: request.myProperty.message.referral_code || '',
},
})
}, 1000)
})
Expand Down
5 changes: 4 additions & 1 deletion public/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ chrome.runtime.onMessageExternal.addListener(function (
setTimeout(function () {
chrome.runtime.sendMessage({
action: 'createDelegate',
data: { pool_id: request.pool_id },
data: {
pool_id: request.pool_id,
referral_code: request.referral_code || '',
},
})
}, 1000)
},
Expand Down
2 changes: 1 addition & 1 deletion public/manifestDefault.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Mojito - A Mintlayer Wallet",
"version": "1.2.6",
"version": "1.2.7",
"short_name": "Mojito",
"description": "Mojito is a non-custodial decentralized crypto wallet that lets you send and receive BTC and ML from any other address.",
"homepage_url": "https://www.mintlayer.org/",
Expand Down
2 changes: 1 addition & 1 deletion public/manifestFirefox.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Mojito - A Mintlayer Wallet",
"version": "1.2.6",
"version": "1.2.7",
"description": "Mojito is a non-custodial decentralized crypto wallet that lets you send and receive BTC and ML from any other address.",
"homepage_url": "https://www.mintlayer.org/",
"icons": {
Expand Down
14 changes: 14 additions & 0 deletions src/components/containers/SendTransaction/SendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ const SendTransaction = ({
[fee, amountInCrypto],
)

useEffect(
() => {
if (preEnterAddress) {
calculateTotalFee({
to: preEnterAddress,
amount: NumbersHelper.floatStringToNumber(amountInCrypto),
fee,
})
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[isFormValid, amountInCrypto, fee, preEnterAddress],
)

useEffect(() => {
const validity = originalAmount && AppInfo.amountRegex.test(originalAmount)
const maxValue = BTC.convertBtcToSatoshi(
Expand Down
1 change: 1 addition & 0 deletions src/components/containers/Wallet/Delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const Delegation = ({ delegation }) => {
></div>
<div
style={{
left: '30px',
position: 'absolute',
top: '50%',
marginTop: '-38px',
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ const App = () => {
state: {
action: 'createDelegate',
pool_id: request.data.pool_id,
referral_code: request.data.referral_code || '',
},
})
return
}
// change route to staking page
navigate('/wallet/Mintlayer/staking/create-delegation', {
state: { action: 'createDelegate', pool_id: request.data.pool_id },
state: {
action: 'createDelegate',
pool_id: request.data.pool_id,
referral_code: request.data.referral_code || '',
},
})
}

Expand Down
4 changes: 4 additions & 0 deletions src/pages/CreateDelegation/CreateDelegation.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
min-height: 400px;
position: absolute;
z-index: 40;
background-color: rgba(255, 255, 255, 0.8);
}
44 changes: 32 additions & 12 deletions src/pages/CreateDelegation/CreateDelegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,31 @@ const CreateDelegationPage = () => {
})

if (result) {
// map txid to referral code
try {
const REFERRAL_TRACK_ENDPOINT = {
mainnet: 'https://api-server.mintlayer.org/track',
testnet: 'https://api-server-lovelace.mintlayer.org/track',
}
const referralCode = state?.referral_code || ''
if (referralCode) {
const txid = result
// send request to api server to track txid and referral_code
await fetch(REFERRAL_TRACK_ENDPOINT[networkType], {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
txid,
referral_code: referralCode,
}),
})
}
} catch (error) {
console.error('Error:', error)
}

await fetchDelegations()
}

Expand All @@ -164,22 +189,17 @@ const CreateDelegationPage = () => {

const loading = preEnterAddress && (fetchingBalances || fetchingUtxos)

if (loading) {
return (
<div>
<div className="page-loading">
<VerticalGroup>
<Loading />
</VerticalGroup>
</div>
</div>
)
}

return (
<>
<div className="page">
<VerticalGroup>
{loading ? (
<div className="page-loading">
<Loading />
</div>
) : (
<></>
)}
<SendTransaction
totalFeeFiat={totalFeeFiat}
totalFeeCrypto={totalFeeCrypto}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/CreateRestore/CreateRestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CreateRestorePage = () => {
className="footnote-version"
data-testid="footnote-name"
>
v1.2.6
v1.2.7
</small>
</div>
</div>
Expand Down

0 comments on commit ae7f848

Please sign in to comment.